1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4*4882a593Smuzhiyun * Universal interface for Audio Codec '97
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * For more details look to AC '97 component specification revision 2.2
7*4882a593Smuzhiyun * by Intel Corporation (http://developer.intel.com) and to datasheets
8*4882a593Smuzhiyun * for specific codecs.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include "ac97_local.h"
12*4882a593Smuzhiyun #include "ac97_patch.h"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun * Forward declarations
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
19*4882a593Smuzhiyun const char *name);
20*4882a593Smuzhiyun static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
21*4882a593Smuzhiyun const unsigned int *tlv,
22*4882a593Smuzhiyun const char * const *followers);
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun * Chip specific initialization
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun
patch_build_controls(struct snd_ac97 * ac97,const struct snd_kcontrol_new * controls,int count)28*4882a593Smuzhiyun static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun int idx, err;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun for (idx = 0; idx < count; idx++)
33*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
34*4882a593Smuzhiyun return err;
35*4882a593Smuzhiyun return 0;
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* replace with a new TLV */
reset_tlv(struct snd_ac97 * ac97,const char * name,const unsigned int * tlv)39*4882a593Smuzhiyun static void reset_tlv(struct snd_ac97 *ac97, const char *name,
40*4882a593Smuzhiyun const unsigned int *tlv)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun struct snd_ctl_elem_id sid;
43*4882a593Smuzhiyun struct snd_kcontrol *kctl;
44*4882a593Smuzhiyun memset(&sid, 0, sizeof(sid));
45*4882a593Smuzhiyun strcpy(sid.name, name);
46*4882a593Smuzhiyun sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
47*4882a593Smuzhiyun kctl = snd_ctl_find_id(ac97->bus->card, &sid);
48*4882a593Smuzhiyun if (kctl && kctl->tlv.p)
49*4882a593Smuzhiyun kctl->tlv.p = tlv;
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun /* set to the page, update bits and restore the page */
ac97_update_bits_page(struct snd_ac97 * ac97,unsigned short reg,unsigned short mask,unsigned short value,unsigned short page)53*4882a593Smuzhiyun static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun unsigned short page_save;
56*4882a593Smuzhiyun int ret;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun mutex_lock(&ac97->page_mutex);
59*4882a593Smuzhiyun page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
60*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
61*4882a593Smuzhiyun ret = snd_ac97_update_bits(ac97, reg, mask, value);
62*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
63*4882a593Smuzhiyun mutex_unlock(&ac97->page_mutex); /* unlock paging */
64*4882a593Smuzhiyun return ret;
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /*
68*4882a593Smuzhiyun * shared line-in/mic controls
69*4882a593Smuzhiyun */
ac97_surround_jack_mode_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)70*4882a593Smuzhiyun static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun static const char * const texts[] = { "Shared", "Independent" };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 2, texts);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
ac97_surround_jack_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)77*4882a593Smuzhiyun static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = ac97->indep_surround;
82*4882a593Smuzhiyun return 0;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
ac97_surround_jack_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)85*4882a593Smuzhiyun static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
88*4882a593Smuzhiyun unsigned char indep = !!ucontrol->value.enumerated.item[0];
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun if (indep != ac97->indep_surround) {
91*4882a593Smuzhiyun ac97->indep_surround = indep;
92*4882a593Smuzhiyun if (ac97->build_ops->update_jacks)
93*4882a593Smuzhiyun ac97->build_ops->update_jacks(ac97);
94*4882a593Smuzhiyun return 1;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun return 0;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
ac97_channel_mode_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)99*4882a593Smuzhiyun static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun
ac97_channel_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)106*4882a593Smuzhiyun static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = ac97->channel_mode;
111*4882a593Smuzhiyun return 0;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
ac97_channel_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)114*4882a593Smuzhiyun static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
117*4882a593Smuzhiyun unsigned char mode = ucontrol->value.enumerated.item[0];
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun if (mode >= kcontrol->private_value)
120*4882a593Smuzhiyun return -EINVAL;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun if (mode != ac97->channel_mode) {
123*4882a593Smuzhiyun ac97->channel_mode = mode;
124*4882a593Smuzhiyun if (ac97->build_ops->update_jacks)
125*4882a593Smuzhiyun ac97->build_ops->update_jacks(ac97);
126*4882a593Smuzhiyun return 1;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun return 0;
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun #define AC97_SURROUND_JACK_MODE_CTL \
132*4882a593Smuzhiyun { \
133*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
134*4882a593Smuzhiyun .name = "Surround Jack Mode", \
135*4882a593Smuzhiyun .info = ac97_surround_jack_mode_info, \
136*4882a593Smuzhiyun .get = ac97_surround_jack_mode_get, \
137*4882a593Smuzhiyun .put = ac97_surround_jack_mode_put, \
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun /* 6ch */
140*4882a593Smuzhiyun #define AC97_CHANNEL_MODE_CTL \
141*4882a593Smuzhiyun { \
142*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
143*4882a593Smuzhiyun .name = "Channel Mode", \
144*4882a593Smuzhiyun .info = ac97_channel_mode_info, \
145*4882a593Smuzhiyun .get = ac97_channel_mode_get, \
146*4882a593Smuzhiyun .put = ac97_channel_mode_put, \
147*4882a593Smuzhiyun .private_value = 3, \
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun /* 4ch */
150*4882a593Smuzhiyun #define AC97_CHANNEL_MODE_4CH_CTL \
151*4882a593Smuzhiyun { \
152*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
153*4882a593Smuzhiyun .name = "Channel Mode", \
154*4882a593Smuzhiyun .info = ac97_channel_mode_info, \
155*4882a593Smuzhiyun .get = ac97_channel_mode_get, \
156*4882a593Smuzhiyun .put = ac97_channel_mode_put, \
157*4882a593Smuzhiyun .private_value = 2, \
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun /* 8ch */
160*4882a593Smuzhiyun #define AC97_CHANNEL_MODE_8CH_CTL \
161*4882a593Smuzhiyun { \
162*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
163*4882a593Smuzhiyun .name = "Channel Mode", \
164*4882a593Smuzhiyun .info = ac97_channel_mode_info, \
165*4882a593Smuzhiyun .get = ac97_channel_mode_get, \
166*4882a593Smuzhiyun .put = ac97_channel_mode_put, \
167*4882a593Smuzhiyun .private_value = 4, \
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
is_surround_on(struct snd_ac97 * ac97)170*4882a593Smuzhiyun static inline int is_surround_on(struct snd_ac97 *ac97)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun return ac97->channel_mode >= 1;
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun
is_clfe_on(struct snd_ac97 * ac97)175*4882a593Smuzhiyun static inline int is_clfe_on(struct snd_ac97 *ac97)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun return ac97->channel_mode >= 2;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /* system has shared jacks with surround out enabled */
is_shared_surrout(struct snd_ac97 * ac97)181*4882a593Smuzhiyun static inline int is_shared_surrout(struct snd_ac97 *ac97)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun return !ac97->indep_surround && is_surround_on(ac97);
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun /* system has shared jacks with center/lfe out enabled */
is_shared_clfeout(struct snd_ac97 * ac97)187*4882a593Smuzhiyun static inline int is_shared_clfeout(struct snd_ac97 *ac97)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun return !ac97->indep_surround && is_clfe_on(ac97);
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* system has shared jacks with line in enabled */
is_shared_linein(struct snd_ac97 * ac97)193*4882a593Smuzhiyun static inline int is_shared_linein(struct snd_ac97 *ac97)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun return !ac97->indep_surround && !is_surround_on(ac97);
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun /* system has shared jacks with mic in enabled */
is_shared_micin(struct snd_ac97 * ac97)199*4882a593Smuzhiyun static inline int is_shared_micin(struct snd_ac97 *ac97)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun return !ac97->indep_surround && !is_clfe_on(ac97);
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun
alc850_is_aux_back_surround(struct snd_ac97 * ac97)204*4882a593Smuzhiyun static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun return is_surround_on(ac97);
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
210*4882a593Smuzhiyun /* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun /* It is possible to indicate to the Yamaha YMF7x3 the type of
213*4882a593Smuzhiyun speakers being used. */
214*4882a593Smuzhiyun
snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)215*4882a593Smuzhiyun static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
216*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun static const char * const texts[3] = {
219*4882a593Smuzhiyun "Standard", "Small", "Smaller"
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts);
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)225*4882a593Smuzhiyun static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
226*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
229*4882a593Smuzhiyun unsigned short val;
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
232*4882a593Smuzhiyun val = (val >> 10) & 3;
233*4882a593Smuzhiyun if (val > 0) /* 0 = invalid */
234*4882a593Smuzhiyun val--;
235*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = val;
236*4882a593Smuzhiyun return 0;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun
snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)239*4882a593Smuzhiyun static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
240*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
243*4882a593Smuzhiyun unsigned short val;
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 2)
246*4882a593Smuzhiyun return -EINVAL;
247*4882a593Smuzhiyun val = (ucontrol->value.enumerated.item[0] + 1) << 10;
248*4882a593Smuzhiyun return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
249*4882a593Smuzhiyun }
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
254*4882a593Smuzhiyun .name = "3D Control - Speaker",
255*4882a593Smuzhiyun .info = snd_ac97_ymf7x3_info_speaker,
256*4882a593Smuzhiyun .get = snd_ac97_ymf7x3_get_speaker,
257*4882a593Smuzhiyun .put = snd_ac97_ymf7x3_put_speaker,
258*4882a593Smuzhiyun };
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /* It is possible to indicate to the Yamaha YMF7x3 the source to
261*4882a593Smuzhiyun direct to the S/PDIF output. */
snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)262*4882a593Smuzhiyun static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
263*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun static const char * const texts[2] = { "AC-Link", "A/D Converter" };
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 2, texts);
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)270*4882a593Smuzhiyun static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
271*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
272*4882a593Smuzhiyun {
273*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
274*4882a593Smuzhiyun unsigned short val;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
277*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
278*4882a593Smuzhiyun return 0;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)281*4882a593Smuzhiyun static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
282*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
283*4882a593Smuzhiyun {
284*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
285*4882a593Smuzhiyun unsigned short val;
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 1)
288*4882a593Smuzhiyun return -EINVAL;
289*4882a593Smuzhiyun val = ucontrol->value.enumerated.item[0] << 1;
290*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun
patch_yamaha_ymf7x3_3d(struct snd_ac97 * ac97)293*4882a593Smuzhiyun static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
294*4882a593Smuzhiyun {
295*4882a593Smuzhiyun struct snd_kcontrol *kctl;
296*4882a593Smuzhiyun int err;
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
299*4882a593Smuzhiyun err = snd_ctl_add(ac97->bus->card, kctl);
300*4882a593Smuzhiyun if (err < 0)
301*4882a593Smuzhiyun return err;
302*4882a593Smuzhiyun strcpy(kctl->id.name, "3D Control - Wide");
303*4882a593Smuzhiyun kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
304*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
305*4882a593Smuzhiyun err = snd_ctl_add(ac97->bus->card,
306*4882a593Smuzhiyun snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
307*4882a593Smuzhiyun ac97));
308*4882a593Smuzhiyun if (err < 0)
309*4882a593Smuzhiyun return err;
310*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
311*4882a593Smuzhiyun return 0;
312*4882a593Smuzhiyun }
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
315*4882a593Smuzhiyun {
316*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
317*4882a593Smuzhiyun AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
320*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
321*4882a593Smuzhiyun .info = snd_ac97_ymf7x3_spdif_source_info,
322*4882a593Smuzhiyun .get = snd_ac97_ymf7x3_spdif_source_get,
323*4882a593Smuzhiyun .put = snd_ac97_ymf7x3_spdif_source_put,
324*4882a593Smuzhiyun },
325*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
326*4882a593Smuzhiyun AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
327*4882a593Smuzhiyun };
328*4882a593Smuzhiyun
patch_yamaha_ymf743_build_spdif(struct snd_ac97 * ac97)329*4882a593Smuzhiyun static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun int err;
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
334*4882a593Smuzhiyun if (err < 0)
335*4882a593Smuzhiyun return err;
336*4882a593Smuzhiyun err = patch_build_controls(ac97,
337*4882a593Smuzhiyun snd_ac97_yamaha_ymf743_controls_spdif, 3);
338*4882a593Smuzhiyun if (err < 0)
339*4882a593Smuzhiyun return err;
340*4882a593Smuzhiyun /* set default PCM S/PDIF params */
341*4882a593Smuzhiyun /* PCM audio,no copyright,no preemphasis,PCM coder,original */
342*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
343*4882a593Smuzhiyun return 0;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
347*4882a593Smuzhiyun .build_spdif = patch_yamaha_ymf743_build_spdif,
348*4882a593Smuzhiyun .build_3d = patch_yamaha_ymf7x3_3d,
349*4882a593Smuzhiyun };
350*4882a593Smuzhiyun
patch_yamaha_ymf743(struct snd_ac97 * ac97)351*4882a593Smuzhiyun static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
352*4882a593Smuzhiyun {
353*4882a593Smuzhiyun ac97->build_ops = &patch_yamaha_ymf743_ops;
354*4882a593Smuzhiyun ac97->caps |= AC97_BC_BASS_TREBLE;
355*4882a593Smuzhiyun ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
356*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
357*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
358*4882a593Smuzhiyun return 0;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
362*4882a593Smuzhiyun The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
363*4882a593Smuzhiyun By default, no output pin is selected, and the S/PDIF signal is not output.
364*4882a593Smuzhiyun There is also a bit to mute S/PDIF output in a vendor-specific register. */
snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)365*4882a593Smuzhiyun static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts);
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)372*4882a593Smuzhiyun static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
373*4882a593Smuzhiyun {
374*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
375*4882a593Smuzhiyun unsigned short val;
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
378*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
379*4882a593Smuzhiyun return 0;
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun
snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)382*4882a593Smuzhiyun static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
383*4882a593Smuzhiyun {
384*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
385*4882a593Smuzhiyun unsigned short val;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 2)
388*4882a593Smuzhiyun return -EINVAL;
389*4882a593Smuzhiyun val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
390*4882a593Smuzhiyun (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
391*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
392*4882a593Smuzhiyun /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
393*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
397*4882a593Smuzhiyun {
398*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
399*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
400*4882a593Smuzhiyun .info = snd_ac97_ymf7x3_spdif_source_info,
401*4882a593Smuzhiyun .get = snd_ac97_ymf7x3_spdif_source_get,
402*4882a593Smuzhiyun .put = snd_ac97_ymf7x3_spdif_source_put,
403*4882a593Smuzhiyun },
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
406*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
407*4882a593Smuzhiyun .info = snd_ac97_ymf753_spdif_output_pin_info,
408*4882a593Smuzhiyun .get = snd_ac97_ymf753_spdif_output_pin_get,
409*4882a593Smuzhiyun .put = snd_ac97_ymf753_spdif_output_pin_put,
410*4882a593Smuzhiyun },
411*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
412*4882a593Smuzhiyun AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
413*4882a593Smuzhiyun };
414*4882a593Smuzhiyun
patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)415*4882a593Smuzhiyun static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
416*4882a593Smuzhiyun {
417*4882a593Smuzhiyun int err;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
420*4882a593Smuzhiyun return err;
421*4882a593Smuzhiyun return 0;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
425*4882a593Smuzhiyun .build_3d = patch_yamaha_ymf7x3_3d,
426*4882a593Smuzhiyun .build_post_spdif = patch_yamaha_ymf753_post_spdif
427*4882a593Smuzhiyun };
428*4882a593Smuzhiyun
patch_yamaha_ymf753(struct snd_ac97 * ac97)429*4882a593Smuzhiyun static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
430*4882a593Smuzhiyun {
431*4882a593Smuzhiyun /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
432*4882a593Smuzhiyun This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
433*4882a593Smuzhiyun The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
434*4882a593Smuzhiyun The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
435*4882a593Smuzhiyun By default, no output pin is selected, and the S/PDIF signal is not output.
436*4882a593Smuzhiyun There is also a bit to mute S/PDIF output in a vendor-specific register.
437*4882a593Smuzhiyun */
438*4882a593Smuzhiyun ac97->build_ops = &patch_yamaha_ymf753_ops;
439*4882a593Smuzhiyun ac97->caps |= AC97_BC_BASS_TREBLE;
440*4882a593Smuzhiyun ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
441*4882a593Smuzhiyun return 0;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun /*
445*4882a593Smuzhiyun * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
446*4882a593Smuzhiyun * removed broken wolfson00 patch.
447*4882a593Smuzhiyun * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
448*4882a593Smuzhiyun */
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
451*4882a593Smuzhiyun AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
452*4882a593Smuzhiyun AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
453*4882a593Smuzhiyun };
454*4882a593Smuzhiyun
patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)455*4882a593Smuzhiyun static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun /* This is known to work for the ViewSonic ViewPad 1000
458*4882a593Smuzhiyun * Randolph Bentson <bentson@holmsjoen.com>
459*4882a593Smuzhiyun * WM9703/9707/9708/9717
460*4882a593Smuzhiyun */
461*4882a593Smuzhiyun int err, i;
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
464*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
465*4882a593Smuzhiyun return err;
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
468*4882a593Smuzhiyun return 0;
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
472*4882a593Smuzhiyun .build_specific = patch_wolfson_wm9703_specific,
473*4882a593Smuzhiyun };
474*4882a593Smuzhiyun
patch_wolfson03(struct snd_ac97 * ac97)475*4882a593Smuzhiyun static int patch_wolfson03(struct snd_ac97 * ac97)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun ac97->build_ops = &patch_wolfson_wm9703_ops;
478*4882a593Smuzhiyun return 0;
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
482*4882a593Smuzhiyun AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
483*4882a593Smuzhiyun AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
484*4882a593Smuzhiyun AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
485*4882a593Smuzhiyun AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
486*4882a593Smuzhiyun AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
487*4882a593Smuzhiyun AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
488*4882a593Smuzhiyun };
489*4882a593Smuzhiyun
patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)490*4882a593Smuzhiyun static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
491*4882a593Smuzhiyun {
492*4882a593Smuzhiyun int err, i;
493*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
494*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
495*4882a593Smuzhiyun return err;
496*4882a593Smuzhiyun }
497*4882a593Smuzhiyun /* patch for DVD noise */
498*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
499*4882a593Smuzhiyun return 0;
500*4882a593Smuzhiyun }
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
503*4882a593Smuzhiyun .build_specific = patch_wolfson_wm9704_specific,
504*4882a593Smuzhiyun };
505*4882a593Smuzhiyun
patch_wolfson04(struct snd_ac97 * ac97)506*4882a593Smuzhiyun static int patch_wolfson04(struct snd_ac97 * ac97)
507*4882a593Smuzhiyun {
508*4882a593Smuzhiyun /* WM9704M/9704Q */
509*4882a593Smuzhiyun ac97->build_ops = &patch_wolfson_wm9704_ops;
510*4882a593Smuzhiyun return 0;
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun
patch_wolfson05(struct snd_ac97 * ac97)513*4882a593Smuzhiyun static int patch_wolfson05(struct snd_ac97 * ac97)
514*4882a593Smuzhiyun {
515*4882a593Smuzhiyun /* WM9705, WM9710 */
516*4882a593Smuzhiyun ac97->build_ops = &patch_wolfson_wm9703_ops;
517*4882a593Smuzhiyun #ifdef CONFIG_TOUCHSCREEN_WM9705
518*4882a593Smuzhiyun /* WM9705 touchscreen uses AUX and VIDEO for touch */
519*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
520*4882a593Smuzhiyun #endif
521*4882a593Smuzhiyun return 0;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
525*4882a593Smuzhiyun static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
526*4882a593Smuzhiyun static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
527*4882a593Smuzhiyun static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
528*4882a593Smuzhiyun static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
529*4882a593Smuzhiyun static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
530*4882a593Smuzhiyun static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
531*4882a593Smuzhiyun static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
532*4882a593Smuzhiyun static const char* wm9711_rec_sel[] =
533*4882a593Smuzhiyun {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
534*4882a593Smuzhiyun static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun static const struct ac97_enum wm9711_enum[] = {
537*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
538*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
539*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
540*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
541*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
542*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
543*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
544*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
545*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
546*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
547*4882a593Smuzhiyun };
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
550*4882a593Smuzhiyun AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
551*4882a593Smuzhiyun AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
552*4882a593Smuzhiyun AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
553*4882a593Smuzhiyun AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
554*4882a593Smuzhiyun AC97_ENUM("ALC Function", wm9711_enum[0]),
555*4882a593Smuzhiyun AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
556*4882a593Smuzhiyun AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
557*4882a593Smuzhiyun AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
558*4882a593Smuzhiyun AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
559*4882a593Smuzhiyun AC97_ENUM("ALC NG Type", wm9711_enum[9]),
560*4882a593Smuzhiyun AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
563*4882a593Smuzhiyun AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
564*4882a593Smuzhiyun AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
565*4882a593Smuzhiyun AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
568*4882a593Smuzhiyun AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
569*4882a593Smuzhiyun AC97_ENUM("Out3 Mux", wm9711_enum[2]),
570*4882a593Smuzhiyun AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
571*4882a593Smuzhiyun AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
572*4882a593Smuzhiyun
573*4882a593Smuzhiyun AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
574*4882a593Smuzhiyun AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
575*4882a593Smuzhiyun AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
576*4882a593Smuzhiyun AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
577*4882a593Smuzhiyun AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
578*4882a593Smuzhiyun AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
581*4882a593Smuzhiyun AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
582*4882a593Smuzhiyun AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
583*4882a593Smuzhiyun AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
584*4882a593Smuzhiyun AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
585*4882a593Smuzhiyun AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
588*4882a593Smuzhiyun AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
591*4882a593Smuzhiyun AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
592*4882a593Smuzhiyun AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
595*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
596*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
599*4882a593Smuzhiyun AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
600*4882a593Smuzhiyun AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
601*4882a593Smuzhiyun AC97_ENUM("Capture Select", wm9711_enum[8]),
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
604*4882a593Smuzhiyun AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun AC97_ENUM("Bass Control", wm9711_enum[5]),
607*4882a593Smuzhiyun AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
608*4882a593Smuzhiyun AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
609*4882a593Smuzhiyun AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
612*4882a593Smuzhiyun AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
613*4882a593Smuzhiyun AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
614*4882a593Smuzhiyun AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
617*4882a593Smuzhiyun AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
618*4882a593Smuzhiyun AC97_ENUM("Mic Select Source", wm9711_enum[7]),
619*4882a593Smuzhiyun AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
620*4882a593Smuzhiyun AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
621*4882a593Smuzhiyun AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
624*4882a593Smuzhiyun AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
625*4882a593Smuzhiyun AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
626*4882a593Smuzhiyun AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
627*4882a593Smuzhiyun };
628*4882a593Smuzhiyun
patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)629*4882a593Smuzhiyun static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
630*4882a593Smuzhiyun {
631*4882a593Smuzhiyun int err, i;
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
634*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
635*4882a593Smuzhiyun return err;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
638*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
639*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
640*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
641*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
642*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
643*4882a593Smuzhiyun return 0;
644*4882a593Smuzhiyun }
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
647*4882a593Smuzhiyun .build_specific = patch_wolfson_wm9711_specific,
648*4882a593Smuzhiyun };
649*4882a593Smuzhiyun
patch_wolfson11(struct snd_ac97 * ac97)650*4882a593Smuzhiyun static int patch_wolfson11(struct snd_ac97 * ac97)
651*4882a593Smuzhiyun {
652*4882a593Smuzhiyun /* WM9711, WM9712 */
653*4882a593Smuzhiyun ac97->build_ops = &patch_wolfson_wm9711_ops;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
656*4882a593Smuzhiyun AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun return 0;
659*4882a593Smuzhiyun }
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
662*4882a593Smuzhiyun static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
663*4882a593Smuzhiyun static const char* wm9713_rec_src[] =
664*4882a593Smuzhiyun {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
665*4882a593Smuzhiyun "Mono Mix", "Zh"};
666*4882a593Smuzhiyun static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
667*4882a593Smuzhiyun static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
668*4882a593Smuzhiyun static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
669*4882a593Smuzhiyun static const char* wm9713_spk_pga[] =
670*4882a593Smuzhiyun {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
671*4882a593Smuzhiyun static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
672*4882a593Smuzhiyun static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
673*4882a593Smuzhiyun static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
674*4882a593Smuzhiyun static const char* wm9713_dac_inv[] =
675*4882a593Smuzhiyun {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
676*4882a593Smuzhiyun "Headphone Mix Mono", "NC", "Vmid"};
677*4882a593Smuzhiyun static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
678*4882a593Smuzhiyun static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun static const struct ac97_enum wm9713_enum[] = {
681*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
682*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
683*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
684*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
685*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
686*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
687*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
688*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
689*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
690*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
691*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
692*4882a593Smuzhiyun AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
693*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
694*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
695*4882a593Smuzhiyun };
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
698*4882a593Smuzhiyun AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
699*4882a593Smuzhiyun AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
700*4882a593Smuzhiyun AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
701*4882a593Smuzhiyun AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
704*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
705*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
706*4882a593Smuzhiyun AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
709*4882a593Smuzhiyun AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
710*4882a593Smuzhiyun AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
711*4882a593Smuzhiyun AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
712*4882a593Smuzhiyun AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
713*4882a593Smuzhiyun AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
714*4882a593Smuzhiyun AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
717*4882a593Smuzhiyun AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
718*4882a593Smuzhiyun AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
719*4882a593Smuzhiyun AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
722*4882a593Smuzhiyun AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
723*4882a593Smuzhiyun AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
724*4882a593Smuzhiyun AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
725*4882a593Smuzhiyun AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
726*4882a593Smuzhiyun AC97_ENUM("Capture Select", wm9713_enum[3]),
727*4882a593Smuzhiyun
728*4882a593Smuzhiyun AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
729*4882a593Smuzhiyun AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
730*4882a593Smuzhiyun AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
731*4882a593Smuzhiyun AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
732*4882a593Smuzhiyun AC97_ENUM("ALC Function", wm9713_enum[5]),
733*4882a593Smuzhiyun AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
734*4882a593Smuzhiyun AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
735*4882a593Smuzhiyun AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
736*4882a593Smuzhiyun AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
737*4882a593Smuzhiyun AC97_ENUM("ALC NG Type", wm9713_enum[13]),
738*4882a593Smuzhiyun AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
741*4882a593Smuzhiyun AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
742*4882a593Smuzhiyun AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
743*4882a593Smuzhiyun AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
744*4882a593Smuzhiyun AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
745*4882a593Smuzhiyun AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
748*4882a593Smuzhiyun AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
749*4882a593Smuzhiyun AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
750*4882a593Smuzhiyun AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
751*4882a593Smuzhiyun AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
752*4882a593Smuzhiyun AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
755*4882a593Smuzhiyun AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
756*4882a593Smuzhiyun AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
757*4882a593Smuzhiyun AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
758*4882a593Smuzhiyun AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
759*4882a593Smuzhiyun AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
762*4882a593Smuzhiyun AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
763*4882a593Smuzhiyun AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
764*4882a593Smuzhiyun AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
765*4882a593Smuzhiyun AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
766*4882a593Smuzhiyun AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
769*4882a593Smuzhiyun AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
770*4882a593Smuzhiyun AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
771*4882a593Smuzhiyun AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
772*4882a593Smuzhiyun AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
773*4882a593Smuzhiyun AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
776*4882a593Smuzhiyun AC97_ENUM("Master Input Mux", wm9713_enum[7]),
777*4882a593Smuzhiyun AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
778*4882a593Smuzhiyun AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
779*4882a593Smuzhiyun AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun AC97_ENUM("Bass Control", wm9713_enum[12]),
782*4882a593Smuzhiyun AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
783*4882a593Smuzhiyun AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
784*4882a593Smuzhiyun AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
785*4882a593Smuzhiyun AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
786*4882a593Smuzhiyun AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
787*4882a593Smuzhiyun };
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
790*4882a593Smuzhiyun AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
791*4882a593Smuzhiyun AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
792*4882a593Smuzhiyun AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
793*4882a593Smuzhiyun AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
794*4882a593Smuzhiyun };
795*4882a593Smuzhiyun
patch_wolfson_wm9713_3d(struct snd_ac97 * ac97)796*4882a593Smuzhiyun static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
797*4882a593Smuzhiyun {
798*4882a593Smuzhiyun int err, i;
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
801*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
802*4882a593Smuzhiyun return err;
803*4882a593Smuzhiyun }
804*4882a593Smuzhiyun return 0;
805*4882a593Smuzhiyun }
806*4882a593Smuzhiyun
patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)807*4882a593Smuzhiyun static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun int err, i;
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
812*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
813*4882a593Smuzhiyun return err;
814*4882a593Smuzhiyun }
815*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
816*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
817*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
818*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
819*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
820*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
821*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
822*4882a593Smuzhiyun return 0;
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun #ifdef CONFIG_PM
patch_wolfson_wm9713_suspend(struct snd_ac97 * ac97)826*4882a593Smuzhiyun static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
827*4882a593Smuzhiyun {
828*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
829*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
830*4882a593Smuzhiyun }
831*4882a593Smuzhiyun
patch_wolfson_wm9713_resume(struct snd_ac97 * ac97)832*4882a593Smuzhiyun static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
835*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
836*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
837*4882a593Smuzhiyun }
838*4882a593Smuzhiyun #endif
839*4882a593Smuzhiyun
840*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
841*4882a593Smuzhiyun .build_specific = patch_wolfson_wm9713_specific,
842*4882a593Smuzhiyun .build_3d = patch_wolfson_wm9713_3d,
843*4882a593Smuzhiyun #ifdef CONFIG_PM
844*4882a593Smuzhiyun .suspend = patch_wolfson_wm9713_suspend,
845*4882a593Smuzhiyun .resume = patch_wolfson_wm9713_resume
846*4882a593Smuzhiyun #endif
847*4882a593Smuzhiyun };
848*4882a593Smuzhiyun
patch_wolfson13(struct snd_ac97 * ac97)849*4882a593Smuzhiyun static int patch_wolfson13(struct snd_ac97 * ac97)
850*4882a593Smuzhiyun {
851*4882a593Smuzhiyun /* WM9713, WM9714 */
852*4882a593Smuzhiyun ac97->build_ops = &patch_wolfson_wm9713_ops;
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
855*4882a593Smuzhiyun AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
856*4882a593Smuzhiyun AC97_HAS_NO_STD_PCM;
857*4882a593Smuzhiyun ac97->scaps &= ~AC97_SCAP_MODEM;
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
860*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
861*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun return 0;
864*4882a593Smuzhiyun }
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun /*
867*4882a593Smuzhiyun * Tritech codec
868*4882a593Smuzhiyun */
patch_tritech_tr28028(struct snd_ac97 * ac97)869*4882a593Smuzhiyun static int patch_tritech_tr28028(struct snd_ac97 * ac97)
870*4882a593Smuzhiyun {
871*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x26, 0x0300);
872*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x26, 0x0000);
873*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
874*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
875*4882a593Smuzhiyun return 0;
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun /*
879*4882a593Smuzhiyun * Sigmatel STAC97xx codecs
880*4882a593Smuzhiyun */
patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)881*4882a593Smuzhiyun static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
882*4882a593Smuzhiyun {
883*4882a593Smuzhiyun struct snd_kcontrol *kctl;
884*4882a593Smuzhiyun int err;
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
887*4882a593Smuzhiyun return err;
888*4882a593Smuzhiyun strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
889*4882a593Smuzhiyun kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
890*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
891*4882a593Smuzhiyun return 0;
892*4882a593Smuzhiyun }
893*4882a593Smuzhiyun
patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)894*4882a593Smuzhiyun static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
895*4882a593Smuzhiyun {
896*4882a593Smuzhiyun struct snd_kcontrol *kctl;
897*4882a593Smuzhiyun int err;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
900*4882a593Smuzhiyun return err;
901*4882a593Smuzhiyun strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
902*4882a593Smuzhiyun kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
903*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
904*4882a593Smuzhiyun return err;
905*4882a593Smuzhiyun strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
906*4882a593Smuzhiyun kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
907*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
908*4882a593Smuzhiyun return 0;
909*4882a593Smuzhiyun }
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
912*4882a593Smuzhiyun AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
913*4882a593Smuzhiyun AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun /* "Sigmatel " removed due to excessive name length: */
916*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
917*4882a593Smuzhiyun AC97_SINGLE("Surround Phase Inversion Playback Switch",
918*4882a593Smuzhiyun AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
921*4882a593Smuzhiyun AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
922*4882a593Smuzhiyun AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
923*4882a593Smuzhiyun };
924*4882a593Smuzhiyun
patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)925*4882a593Smuzhiyun static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
926*4882a593Smuzhiyun {
927*4882a593Smuzhiyun int err;
928*4882a593Smuzhiyun
929*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
930*4882a593Smuzhiyun if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
931*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
932*4882a593Smuzhiyun return err;
933*4882a593Smuzhiyun if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
934*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
935*4882a593Smuzhiyun return err;
936*4882a593Smuzhiyun if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
937*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
938*4882a593Smuzhiyun return err;
939*4882a593Smuzhiyun if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
940*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
941*4882a593Smuzhiyun return err;
942*4882a593Smuzhiyun return 0;
943*4882a593Smuzhiyun }
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
946*4882a593Smuzhiyun .build_3d = patch_sigmatel_stac9700_3d,
947*4882a593Smuzhiyun .build_specific = patch_sigmatel_stac97xx_specific
948*4882a593Smuzhiyun };
949*4882a593Smuzhiyun
patch_sigmatel_stac9700(struct snd_ac97 * ac97)950*4882a593Smuzhiyun static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
951*4882a593Smuzhiyun {
952*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9700_ops;
953*4882a593Smuzhiyun return 0;
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun
snd_ac97_stac9708_put_bias(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)956*4882a593Smuzhiyun static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
957*4882a593Smuzhiyun {
958*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
959*4882a593Smuzhiyun int err;
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun mutex_lock(&ac97->page_mutex);
962*4882a593Smuzhiyun snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
963*4882a593Smuzhiyun err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
964*4882a593Smuzhiyun (ucontrol->value.integer.value[0] & 1) << 4);
965*4882a593Smuzhiyun snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
966*4882a593Smuzhiyun mutex_unlock(&ac97->page_mutex);
967*4882a593Smuzhiyun return err;
968*4882a593Smuzhiyun }
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
971*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
972*4882a593Smuzhiyun .name = "Sigmatel Output Bias Switch",
973*4882a593Smuzhiyun .info = snd_ac97_info_volsw,
974*4882a593Smuzhiyun .get = snd_ac97_get_volsw,
975*4882a593Smuzhiyun .put = snd_ac97_stac9708_put_bias,
976*4882a593Smuzhiyun .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
977*4882a593Smuzhiyun };
978*4882a593Smuzhiyun
patch_sigmatel_stac9708_specific(struct snd_ac97 * ac97)979*4882a593Smuzhiyun static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
980*4882a593Smuzhiyun {
981*4882a593Smuzhiyun int err;
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun /* the register bit is writable, but the function is not implemented: */
984*4882a593Smuzhiyun snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
985*4882a593Smuzhiyun
986*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
987*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
988*4882a593Smuzhiyun return err;
989*4882a593Smuzhiyun return patch_sigmatel_stac97xx_specific(ac97);
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
993*4882a593Smuzhiyun .build_3d = patch_sigmatel_stac9708_3d,
994*4882a593Smuzhiyun .build_specific = patch_sigmatel_stac9708_specific
995*4882a593Smuzhiyun };
996*4882a593Smuzhiyun
patch_sigmatel_stac9708(struct snd_ac97 * ac97)997*4882a593Smuzhiyun static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
998*4882a593Smuzhiyun {
999*4882a593Smuzhiyun unsigned int codec72, codec6c;
1000*4882a593Smuzhiyun
1001*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9708_ops;
1002*4882a593Smuzhiyun ac97->caps |= 0x10; /* HP (sigmatel surround) support */
1003*4882a593Smuzhiyun
1004*4882a593Smuzhiyun codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
1005*4882a593Smuzhiyun codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun if ((codec72==0) && (codec6c==0)) {
1008*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1009*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
1010*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1011*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
1012*4882a593Smuzhiyun } else if ((codec72==0x8000) && (codec6c==0)) {
1013*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1014*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
1015*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
1016*4882a593Smuzhiyun } else if ((codec72==0x8000) && (codec6c==0x0080)) {
1017*4882a593Smuzhiyun /* nothing */
1018*4882a593Smuzhiyun }
1019*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1020*4882a593Smuzhiyun return 0;
1021*4882a593Smuzhiyun }
1022*4882a593Smuzhiyun
patch_sigmatel_stac9721(struct snd_ac97 * ac97)1023*4882a593Smuzhiyun static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
1024*4882a593Smuzhiyun {
1025*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9700_ops;
1026*4882a593Smuzhiyun if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1027*4882a593Smuzhiyun // patch for SigmaTel
1028*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1029*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1030*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1031*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1032*4882a593Smuzhiyun }
1033*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1034*4882a593Smuzhiyun return 0;
1035*4882a593Smuzhiyun }
1036*4882a593Smuzhiyun
patch_sigmatel_stac9744(struct snd_ac97 * ac97)1037*4882a593Smuzhiyun static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
1038*4882a593Smuzhiyun {
1039*4882a593Smuzhiyun // patch for SigmaTel
1040*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9700_ops;
1041*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1042*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1043*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1044*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1045*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1046*4882a593Smuzhiyun return 0;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
patch_sigmatel_stac9756(struct snd_ac97 * ac97)1049*4882a593Smuzhiyun static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
1050*4882a593Smuzhiyun {
1051*4882a593Smuzhiyun // patch for SigmaTel
1052*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9700_ops;
1053*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1054*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1055*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1056*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1057*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1058*4882a593Smuzhiyun return 0;
1059*4882a593Smuzhiyun }
1060*4882a593Smuzhiyun
snd_ac97_stac9758_output_jack_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1061*4882a593Smuzhiyun static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1062*4882a593Smuzhiyun {
1063*4882a593Smuzhiyun static const char * const texts[5] = {
1064*4882a593Smuzhiyun "Input/Disabled", "Front Output",
1065*4882a593Smuzhiyun "Rear Output", "Center/LFE Output", "Mixer Output" };
1066*4882a593Smuzhiyun
1067*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 5, texts);
1068*4882a593Smuzhiyun }
1069*4882a593Smuzhiyun
snd_ac97_stac9758_output_jack_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1070*4882a593Smuzhiyun static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1071*4882a593Smuzhiyun {
1072*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1073*4882a593Smuzhiyun int shift = kcontrol->private_value;
1074*4882a593Smuzhiyun unsigned short val;
1075*4882a593Smuzhiyun
1076*4882a593Smuzhiyun val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1077*4882a593Smuzhiyun if (!(val & 4))
1078*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 0;
1079*4882a593Smuzhiyun else
1080*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1081*4882a593Smuzhiyun return 0;
1082*4882a593Smuzhiyun }
1083*4882a593Smuzhiyun
snd_ac97_stac9758_output_jack_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1084*4882a593Smuzhiyun static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1085*4882a593Smuzhiyun {
1086*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1087*4882a593Smuzhiyun int shift = kcontrol->private_value;
1088*4882a593Smuzhiyun unsigned short val;
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 4)
1091*4882a593Smuzhiyun return -EINVAL;
1092*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] == 0)
1093*4882a593Smuzhiyun val = 0;
1094*4882a593Smuzhiyun else
1095*4882a593Smuzhiyun val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1096*4882a593Smuzhiyun return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1097*4882a593Smuzhiyun 7 << shift, val << shift, 0);
1098*4882a593Smuzhiyun }
1099*4882a593Smuzhiyun
snd_ac97_stac9758_input_jack_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1100*4882a593Smuzhiyun static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1101*4882a593Smuzhiyun {
1102*4882a593Smuzhiyun static const char * const texts[7] = {
1103*4882a593Smuzhiyun "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1104*4882a593Smuzhiyun "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1105*4882a593Smuzhiyun
1106*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 7, texts);
1107*4882a593Smuzhiyun }
1108*4882a593Smuzhiyun
snd_ac97_stac9758_input_jack_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1109*4882a593Smuzhiyun static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1110*4882a593Smuzhiyun {
1111*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1112*4882a593Smuzhiyun int shift = kcontrol->private_value;
1113*4882a593Smuzhiyun unsigned short val;
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun val = ac97->regs[AC97_SIGMATEL_INSEL];
1116*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1117*4882a593Smuzhiyun return 0;
1118*4882a593Smuzhiyun }
1119*4882a593Smuzhiyun
snd_ac97_stac9758_input_jack_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1120*4882a593Smuzhiyun static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1121*4882a593Smuzhiyun {
1122*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1123*4882a593Smuzhiyun int shift = kcontrol->private_value;
1124*4882a593Smuzhiyun
1125*4882a593Smuzhiyun return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1126*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] << shift, 0);
1127*4882a593Smuzhiyun }
1128*4882a593Smuzhiyun
snd_ac97_stac9758_phonesel_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1129*4882a593Smuzhiyun static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1130*4882a593Smuzhiyun {
1131*4882a593Smuzhiyun static const char * const texts[3] = {
1132*4882a593Smuzhiyun "None", "Front Jack", "Rear Jack"
1133*4882a593Smuzhiyun };
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts);
1136*4882a593Smuzhiyun }
1137*4882a593Smuzhiyun
snd_ac97_stac9758_phonesel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1138*4882a593Smuzhiyun static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1139*4882a593Smuzhiyun {
1140*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1143*4882a593Smuzhiyun return 0;
1144*4882a593Smuzhiyun }
1145*4882a593Smuzhiyun
snd_ac97_stac9758_phonesel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1146*4882a593Smuzhiyun static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1147*4882a593Smuzhiyun {
1148*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1149*4882a593Smuzhiyun
1150*4882a593Smuzhiyun return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1151*4882a593Smuzhiyun ucontrol->value.enumerated.item[0], 0);
1152*4882a593Smuzhiyun }
1153*4882a593Smuzhiyun
1154*4882a593Smuzhiyun #define STAC9758_OUTPUT_JACK(xname, shift) \
1155*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1156*4882a593Smuzhiyun .info = snd_ac97_stac9758_output_jack_info, \
1157*4882a593Smuzhiyun .get = snd_ac97_stac9758_output_jack_get, \
1158*4882a593Smuzhiyun .put = snd_ac97_stac9758_output_jack_put, \
1159*4882a593Smuzhiyun .private_value = shift }
1160*4882a593Smuzhiyun #define STAC9758_INPUT_JACK(xname, shift) \
1161*4882a593Smuzhiyun { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1162*4882a593Smuzhiyun .info = snd_ac97_stac9758_input_jack_info, \
1163*4882a593Smuzhiyun .get = snd_ac97_stac9758_input_jack_get, \
1164*4882a593Smuzhiyun .put = snd_ac97_stac9758_input_jack_put, \
1165*4882a593Smuzhiyun .private_value = shift }
1166*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
1167*4882a593Smuzhiyun STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1168*4882a593Smuzhiyun STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1169*4882a593Smuzhiyun STAC9758_OUTPUT_JACK("Front Jack", 7),
1170*4882a593Smuzhiyun STAC9758_OUTPUT_JACK("Rear Jack", 10),
1171*4882a593Smuzhiyun STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1172*4882a593Smuzhiyun STAC9758_INPUT_JACK("Mic Input Source", 0),
1173*4882a593Smuzhiyun STAC9758_INPUT_JACK("Line Input Source", 8),
1174*4882a593Smuzhiyun {
1175*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1176*4882a593Smuzhiyun .name = "Headphone Amp",
1177*4882a593Smuzhiyun .info = snd_ac97_stac9758_phonesel_info,
1178*4882a593Smuzhiyun .get = snd_ac97_stac9758_phonesel_get,
1179*4882a593Smuzhiyun .put = snd_ac97_stac9758_phonesel_put
1180*4882a593Smuzhiyun },
1181*4882a593Smuzhiyun AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1182*4882a593Smuzhiyun AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1183*4882a593Smuzhiyun };
1184*4882a593Smuzhiyun
patch_sigmatel_stac9758_specific(struct snd_ac97 * ac97)1185*4882a593Smuzhiyun static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
1186*4882a593Smuzhiyun {
1187*4882a593Smuzhiyun int err;
1188*4882a593Smuzhiyun
1189*4882a593Smuzhiyun err = patch_sigmatel_stac97xx_specific(ac97);
1190*4882a593Smuzhiyun if (err < 0)
1191*4882a593Smuzhiyun return err;
1192*4882a593Smuzhiyun err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1193*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1194*4882a593Smuzhiyun if (err < 0)
1195*4882a593Smuzhiyun return err;
1196*4882a593Smuzhiyun /* DAC-A direct */
1197*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1198*4882a593Smuzhiyun /* DAC-A to Mix = PCM */
1199*4882a593Smuzhiyun /* DAC-B direct = Surround */
1200*4882a593Smuzhiyun /* DAC-B to Mix */
1201*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1202*4882a593Smuzhiyun /* DAC-C direct = Center/LFE */
1203*4882a593Smuzhiyun
1204*4882a593Smuzhiyun return 0;
1205*4882a593Smuzhiyun }
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1208*4882a593Smuzhiyun .build_3d = patch_sigmatel_stac9700_3d,
1209*4882a593Smuzhiyun .build_specific = patch_sigmatel_stac9758_specific
1210*4882a593Smuzhiyun };
1211*4882a593Smuzhiyun
patch_sigmatel_stac9758(struct snd_ac97 * ac97)1212*4882a593Smuzhiyun static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
1213*4882a593Smuzhiyun {
1214*4882a593Smuzhiyun static const unsigned short regs[4] = {
1215*4882a593Smuzhiyun AC97_SIGMATEL_OUTSEL,
1216*4882a593Smuzhiyun AC97_SIGMATEL_IOMISC,
1217*4882a593Smuzhiyun AC97_SIGMATEL_INSEL,
1218*4882a593Smuzhiyun AC97_SIGMATEL_VARIOUS
1219*4882a593Smuzhiyun };
1220*4882a593Smuzhiyun static const unsigned short def_regs[4] = {
1221*4882a593Smuzhiyun /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1222*4882a593Smuzhiyun /* IOMISC */ 0x2001,
1223*4882a593Smuzhiyun /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1224*4882a593Smuzhiyun /* VARIOUS */ 0x0040
1225*4882a593Smuzhiyun };
1226*4882a593Smuzhiyun static const unsigned short m675_regs[4] = {
1227*4882a593Smuzhiyun /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1228*4882a593Smuzhiyun /* IOMISC */ 0x2102, /* HP amp on */
1229*4882a593Smuzhiyun /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1230*4882a593Smuzhiyun /* VARIOUS */ 0x0041 /* stereo mic */
1231*4882a593Smuzhiyun };
1232*4882a593Smuzhiyun const unsigned short *pregs = def_regs;
1233*4882a593Smuzhiyun int i;
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun /* Gateway M675 notebook */
1236*4882a593Smuzhiyun if (ac97->pci &&
1237*4882a593Smuzhiyun ac97->subsystem_vendor == 0x107b &&
1238*4882a593Smuzhiyun ac97->subsystem_device == 0x0601)
1239*4882a593Smuzhiyun pregs = m675_regs;
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun // patch for SigmaTel
1242*4882a593Smuzhiyun ac97->build_ops = &patch_sigmatel_stac9758_ops;
1243*4882a593Smuzhiyun /* FIXME: assume only page 0 for writing cache */
1244*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1245*4882a593Smuzhiyun for (i = 0; i < 4; i++)
1246*4882a593Smuzhiyun snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
1249*4882a593Smuzhiyun return 0;
1250*4882a593Smuzhiyun }
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun /*
1253*4882a593Smuzhiyun * Cirrus Logic CS42xx codecs
1254*4882a593Smuzhiyun */
1255*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
1256*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1257*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1258*4882a593Smuzhiyun };
1259*4882a593Smuzhiyun
patch_cirrus_build_spdif(struct snd_ac97 * ac97)1260*4882a593Smuzhiyun static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
1261*4882a593Smuzhiyun {
1262*4882a593Smuzhiyun int err;
1263*4882a593Smuzhiyun
1264*4882a593Smuzhiyun /* con mask, pro mask, default */
1265*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1266*4882a593Smuzhiyun return err;
1267*4882a593Smuzhiyun /* switch, spsa */
1268*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1269*4882a593Smuzhiyun return err;
1270*4882a593Smuzhiyun switch (ac97->id & AC97_ID_CS_MASK) {
1271*4882a593Smuzhiyun case AC97_ID_CS4205:
1272*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1273*4882a593Smuzhiyun return err;
1274*4882a593Smuzhiyun break;
1275*4882a593Smuzhiyun }
1276*4882a593Smuzhiyun /* set default PCM S/PDIF params */
1277*4882a593Smuzhiyun /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1278*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1279*4882a593Smuzhiyun return 0;
1280*4882a593Smuzhiyun }
1281*4882a593Smuzhiyun
1282*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_cirrus_ops = {
1283*4882a593Smuzhiyun .build_spdif = patch_cirrus_build_spdif
1284*4882a593Smuzhiyun };
1285*4882a593Smuzhiyun
patch_cirrus_spdif(struct snd_ac97 * ac97)1286*4882a593Smuzhiyun static int patch_cirrus_spdif(struct snd_ac97 * ac97)
1287*4882a593Smuzhiyun {
1288*4882a593Smuzhiyun /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1289*4882a593Smuzhiyun WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1290*4882a593Smuzhiyun - sp/dif EA ID is not set, but sp/dif is always present.
1291*4882a593Smuzhiyun - enable/disable is spdif register bit 15.
1292*4882a593Smuzhiyun - sp/dif control register is 0x68. differs from AC97:
1293*4882a593Smuzhiyun - valid is bit 14 (vs 15)
1294*4882a593Smuzhiyun - no DRS
1295*4882a593Smuzhiyun - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1296*4882a593Smuzhiyun - sp/dif ssource select is in 0x5e bits 0,1.
1297*4882a593Smuzhiyun */
1298*4882a593Smuzhiyun
1299*4882a593Smuzhiyun ac97->build_ops = &patch_cirrus_ops;
1300*4882a593Smuzhiyun ac97->flags |= AC97_CS_SPDIF;
1301*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1302*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1303*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1304*4882a593Smuzhiyun return 0;
1305*4882a593Smuzhiyun }
1306*4882a593Smuzhiyun
patch_cirrus_cs4299(struct snd_ac97 * ac97)1307*4882a593Smuzhiyun static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
1308*4882a593Smuzhiyun {
1309*4882a593Smuzhiyun /* force the detection of PC Beep */
1310*4882a593Smuzhiyun ac97->flags |= AC97_HAS_PC_BEEP;
1311*4882a593Smuzhiyun
1312*4882a593Smuzhiyun return patch_cirrus_spdif(ac97);
1313*4882a593Smuzhiyun }
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun /*
1316*4882a593Smuzhiyun * Conexant codecs
1317*4882a593Smuzhiyun */
1318*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
1319*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1320*4882a593Smuzhiyun };
1321*4882a593Smuzhiyun
patch_conexant_build_spdif(struct snd_ac97 * ac97)1322*4882a593Smuzhiyun static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
1323*4882a593Smuzhiyun {
1324*4882a593Smuzhiyun int err;
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun /* con mask, pro mask, default */
1327*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1328*4882a593Smuzhiyun return err;
1329*4882a593Smuzhiyun /* switch */
1330*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1331*4882a593Smuzhiyun return err;
1332*4882a593Smuzhiyun /* set default PCM S/PDIF params */
1333*4882a593Smuzhiyun /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1334*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1335*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1336*4882a593Smuzhiyun return 0;
1337*4882a593Smuzhiyun }
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_conexant_ops = {
1340*4882a593Smuzhiyun .build_spdif = patch_conexant_build_spdif
1341*4882a593Smuzhiyun };
1342*4882a593Smuzhiyun
patch_conexant(struct snd_ac97 * ac97)1343*4882a593Smuzhiyun static int patch_conexant(struct snd_ac97 * ac97)
1344*4882a593Smuzhiyun {
1345*4882a593Smuzhiyun ac97->build_ops = &patch_conexant_ops;
1346*4882a593Smuzhiyun ac97->flags |= AC97_CX_SPDIF;
1347*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1348*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1349*4882a593Smuzhiyun return 0;
1350*4882a593Smuzhiyun }
1351*4882a593Smuzhiyun
patch_cx20551(struct snd_ac97 * ac97)1352*4882a593Smuzhiyun static int patch_cx20551(struct snd_ac97 *ac97)
1353*4882a593Smuzhiyun {
1354*4882a593Smuzhiyun snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
1355*4882a593Smuzhiyun return 0;
1356*4882a593Smuzhiyun }
1357*4882a593Smuzhiyun
1358*4882a593Smuzhiyun /*
1359*4882a593Smuzhiyun * Analog Devices AD18xx, AD19xx codecs
1360*4882a593Smuzhiyun */
1361*4882a593Smuzhiyun #ifdef CONFIG_PM
ad18xx_resume(struct snd_ac97 * ac97)1362*4882a593Smuzhiyun static void ad18xx_resume(struct snd_ac97 *ac97)
1363*4882a593Smuzhiyun {
1364*4882a593Smuzhiyun static const unsigned short setup_regs[] = {
1365*4882a593Smuzhiyun AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1366*4882a593Smuzhiyun };
1367*4882a593Smuzhiyun int i, codec;
1368*4882a593Smuzhiyun
1369*4882a593Smuzhiyun for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1370*4882a593Smuzhiyun unsigned short reg = setup_regs[i];
1371*4882a593Smuzhiyun if (test_bit(reg, ac97->reg_accessed)) {
1372*4882a593Smuzhiyun snd_ac97_write(ac97, reg, ac97->regs[reg]);
1373*4882a593Smuzhiyun snd_ac97_read(ac97, reg);
1374*4882a593Smuzhiyun }
1375*4882a593Smuzhiyun }
1376*4882a593Smuzhiyun
1377*4882a593Smuzhiyun if (! (ac97->flags & AC97_AD_MULTI))
1378*4882a593Smuzhiyun /* normal restore */
1379*4882a593Smuzhiyun snd_ac97_restore_status(ac97);
1380*4882a593Smuzhiyun else {
1381*4882a593Smuzhiyun /* restore the AD18xx codec configurations */
1382*4882a593Smuzhiyun for (codec = 0; codec < 3; codec++) {
1383*4882a593Smuzhiyun if (! ac97->spec.ad18xx.id[codec])
1384*4882a593Smuzhiyun continue;
1385*4882a593Smuzhiyun /* select single codec */
1386*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1387*4882a593Smuzhiyun ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1388*4882a593Smuzhiyun ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1389*4882a593Smuzhiyun }
1390*4882a593Smuzhiyun /* select all codecs */
1391*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1392*4882a593Smuzhiyun
1393*4882a593Smuzhiyun /* restore status */
1394*4882a593Smuzhiyun for (i = 2; i < 0x7c ; i += 2) {
1395*4882a593Smuzhiyun if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1396*4882a593Smuzhiyun continue;
1397*4882a593Smuzhiyun if (test_bit(i, ac97->reg_accessed)) {
1398*4882a593Smuzhiyun /* handle multi codecs for AD18xx */
1399*4882a593Smuzhiyun if (i == AC97_PCM) {
1400*4882a593Smuzhiyun for (codec = 0; codec < 3; codec++) {
1401*4882a593Smuzhiyun if (! ac97->spec.ad18xx.id[codec])
1402*4882a593Smuzhiyun continue;
1403*4882a593Smuzhiyun /* select single codec */
1404*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1405*4882a593Smuzhiyun ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1406*4882a593Smuzhiyun /* update PCM bits */
1407*4882a593Smuzhiyun ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1408*4882a593Smuzhiyun }
1409*4882a593Smuzhiyun /* select all codecs */
1410*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1411*4882a593Smuzhiyun continue;
1412*4882a593Smuzhiyun } else if (i == AC97_AD_TEST ||
1413*4882a593Smuzhiyun i == AC97_AD_CODEC_CFG ||
1414*4882a593Smuzhiyun i == AC97_AD_SERIAL_CFG)
1415*4882a593Smuzhiyun continue; /* ignore */
1416*4882a593Smuzhiyun }
1417*4882a593Smuzhiyun snd_ac97_write(ac97, i, ac97->regs[i]);
1418*4882a593Smuzhiyun snd_ac97_read(ac97, i);
1419*4882a593Smuzhiyun }
1420*4882a593Smuzhiyun }
1421*4882a593Smuzhiyun
1422*4882a593Smuzhiyun snd_ac97_restore_iec958(ac97);
1423*4882a593Smuzhiyun }
1424*4882a593Smuzhiyun
ad1888_resume(struct snd_ac97 * ac97)1425*4882a593Smuzhiyun static void ad1888_resume(struct snd_ac97 *ac97)
1426*4882a593Smuzhiyun {
1427*4882a593Smuzhiyun ad18xx_resume(ac97);
1428*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1429*4882a593Smuzhiyun }
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun #endif
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun static const struct snd_ac97_res_table ad1819_restbl[] = {
1434*4882a593Smuzhiyun { AC97_PHONE, 0x9f1f },
1435*4882a593Smuzhiyun { AC97_MIC, 0x9f1f },
1436*4882a593Smuzhiyun { AC97_LINE, 0x9f1f },
1437*4882a593Smuzhiyun { AC97_CD, 0x9f1f },
1438*4882a593Smuzhiyun { AC97_VIDEO, 0x9f1f },
1439*4882a593Smuzhiyun { AC97_AUX, 0x9f1f },
1440*4882a593Smuzhiyun { AC97_PCM, 0x9f1f },
1441*4882a593Smuzhiyun { } /* terminator */
1442*4882a593Smuzhiyun };
1443*4882a593Smuzhiyun
patch_ad1819(struct snd_ac97 * ac97)1444*4882a593Smuzhiyun static int patch_ad1819(struct snd_ac97 * ac97)
1445*4882a593Smuzhiyun {
1446*4882a593Smuzhiyun unsigned short scfg;
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun // patch for Analog Devices
1449*4882a593Smuzhiyun scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1450*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1451*4882a593Smuzhiyun ac97->res_table = ad1819_restbl;
1452*4882a593Smuzhiyun return 0;
1453*4882a593Smuzhiyun }
1454*4882a593Smuzhiyun
patch_ad1881_unchained(struct snd_ac97 * ac97,int idx,unsigned short mask)1455*4882a593Smuzhiyun static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
1456*4882a593Smuzhiyun {
1457*4882a593Smuzhiyun unsigned short val;
1458*4882a593Smuzhiyun
1459*4882a593Smuzhiyun // test for unchained codec
1460*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1461*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1462*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1463*4882a593Smuzhiyun if ((val & 0xff40) != 0x5340)
1464*4882a593Smuzhiyun return 0;
1465*4882a593Smuzhiyun ac97->spec.ad18xx.unchained[idx] = mask;
1466*4882a593Smuzhiyun ac97->spec.ad18xx.id[idx] = val;
1467*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1468*4882a593Smuzhiyun return mask;
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun
patch_ad1881_chained1(struct snd_ac97 * ac97,int idx,unsigned short codec_bits)1471*4882a593Smuzhiyun static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
1472*4882a593Smuzhiyun {
1473*4882a593Smuzhiyun static const int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1474*4882a593Smuzhiyun unsigned short val;
1475*4882a593Smuzhiyun
1476*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1477*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1478*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1479*4882a593Smuzhiyun if ((val & 0xff40) != 0x5340)
1480*4882a593Smuzhiyun return 0;
1481*4882a593Smuzhiyun if (codec_bits)
1482*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1483*4882a593Smuzhiyun ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1484*4882a593Smuzhiyun ac97->spec.ad18xx.id[idx] = val;
1485*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1486*4882a593Smuzhiyun return 1;
1487*4882a593Smuzhiyun }
1488*4882a593Smuzhiyun
patch_ad1881_chained(struct snd_ac97 * ac97,int unchained_idx,int cidx1,int cidx2)1489*4882a593Smuzhiyun static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
1490*4882a593Smuzhiyun {
1491*4882a593Smuzhiyun // already detected?
1492*4882a593Smuzhiyun if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1493*4882a593Smuzhiyun cidx1 = -1;
1494*4882a593Smuzhiyun if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1495*4882a593Smuzhiyun cidx2 = -1;
1496*4882a593Smuzhiyun if (cidx1 < 0 && cidx2 < 0)
1497*4882a593Smuzhiyun return;
1498*4882a593Smuzhiyun // test for chained codecs
1499*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1500*4882a593Smuzhiyun ac97->spec.ad18xx.unchained[unchained_idx]);
1501*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1502*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1503*4882a593Smuzhiyun if (cidx1 >= 0) {
1504*4882a593Smuzhiyun if (cidx2 < 0)
1505*4882a593Smuzhiyun patch_ad1881_chained1(ac97, cidx1, 0);
1506*4882a593Smuzhiyun else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1507*4882a593Smuzhiyun patch_ad1881_chained1(ac97, cidx2, 0);
1508*4882a593Smuzhiyun else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1509*4882a593Smuzhiyun patch_ad1881_chained1(ac97, cidx1, 0);
1510*4882a593Smuzhiyun } else if (cidx2 >= 0) {
1511*4882a593Smuzhiyun patch_ad1881_chained1(ac97, cidx2, 0);
1512*4882a593Smuzhiyun }
1513*4882a593Smuzhiyun }
1514*4882a593Smuzhiyun
1515*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
1516*4882a593Smuzhiyun #ifdef CONFIG_PM
1517*4882a593Smuzhiyun .resume = ad18xx_resume
1518*4882a593Smuzhiyun #endif
1519*4882a593Smuzhiyun };
1520*4882a593Smuzhiyun
patch_ad1881(struct snd_ac97 * ac97)1521*4882a593Smuzhiyun static int patch_ad1881(struct snd_ac97 * ac97)
1522*4882a593Smuzhiyun {
1523*4882a593Smuzhiyun static const char cfg_idxs[3][2] = {
1524*4882a593Smuzhiyun {2, 1},
1525*4882a593Smuzhiyun {0, 2},
1526*4882a593Smuzhiyun {0, 1}
1527*4882a593Smuzhiyun };
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun // patch for Analog Devices
1530*4882a593Smuzhiyun unsigned short codecs[3];
1531*4882a593Smuzhiyun unsigned short val;
1532*4882a593Smuzhiyun int idx, num;
1533*4882a593Smuzhiyun
1534*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1535*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1536*4882a593Smuzhiyun codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1537*4882a593Smuzhiyun codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1538*4882a593Smuzhiyun codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun if (! (codecs[0] || codecs[1] || codecs[2]))
1541*4882a593Smuzhiyun goto __end;
1542*4882a593Smuzhiyun
1543*4882a593Smuzhiyun for (idx = 0; idx < 3; idx++)
1544*4882a593Smuzhiyun if (ac97->spec.ad18xx.unchained[idx])
1545*4882a593Smuzhiyun patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1546*4882a593Smuzhiyun
1547*4882a593Smuzhiyun if (ac97->spec.ad18xx.id[1]) {
1548*4882a593Smuzhiyun ac97->flags |= AC97_AD_MULTI;
1549*4882a593Smuzhiyun ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1550*4882a593Smuzhiyun }
1551*4882a593Smuzhiyun if (ac97->spec.ad18xx.id[2]) {
1552*4882a593Smuzhiyun ac97->flags |= AC97_AD_MULTI;
1553*4882a593Smuzhiyun ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1554*4882a593Smuzhiyun }
1555*4882a593Smuzhiyun
1556*4882a593Smuzhiyun __end:
1557*4882a593Smuzhiyun /* select all codecs */
1558*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1559*4882a593Smuzhiyun /* check if only one codec is present */
1560*4882a593Smuzhiyun for (idx = num = 0; idx < 3; idx++)
1561*4882a593Smuzhiyun if (ac97->spec.ad18xx.id[idx])
1562*4882a593Smuzhiyun num++;
1563*4882a593Smuzhiyun if (num == 1) {
1564*4882a593Smuzhiyun /* ok, deselect all ID bits */
1565*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1566*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[0] =
1567*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[1] =
1568*4882a593Smuzhiyun ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1569*4882a593Smuzhiyun }
1570*4882a593Smuzhiyun /* required for AD1886/AD1885 combination */
1571*4882a593Smuzhiyun ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1572*4882a593Smuzhiyun if (ac97->spec.ad18xx.id[0]) {
1573*4882a593Smuzhiyun ac97->id &= 0xffff0000;
1574*4882a593Smuzhiyun ac97->id |= ac97->spec.ad18xx.id[0];
1575*4882a593Smuzhiyun }
1576*4882a593Smuzhiyun ac97->build_ops = &patch_ad1881_build_ops;
1577*4882a593Smuzhiyun return 0;
1578*4882a593Smuzhiyun }
1579*4882a593Smuzhiyun
1580*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
1581*4882a593Smuzhiyun AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1582*4882a593Smuzhiyun /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1583*4882a593Smuzhiyun AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1584*4882a593Smuzhiyun AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1585*4882a593Smuzhiyun AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1586*4882a593Smuzhiyun AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1587*4882a593Smuzhiyun };
1588*4882a593Smuzhiyun
1589*4882a593Smuzhiyun static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
1590*4882a593Smuzhiyun
patch_ad1885_specific(struct snd_ac97 * ac97)1591*4882a593Smuzhiyun static int patch_ad1885_specific(struct snd_ac97 * ac97)
1592*4882a593Smuzhiyun {
1593*4882a593Smuzhiyun int err;
1594*4882a593Smuzhiyun
1595*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1596*4882a593Smuzhiyun return err;
1597*4882a593Smuzhiyun reset_tlv(ac97, "Headphone Playback Volume",
1598*4882a593Smuzhiyun db_scale_6bit_6db_max);
1599*4882a593Smuzhiyun return 0;
1600*4882a593Smuzhiyun }
1601*4882a593Smuzhiyun
1602*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
1603*4882a593Smuzhiyun .build_specific = &patch_ad1885_specific,
1604*4882a593Smuzhiyun #ifdef CONFIG_PM
1605*4882a593Smuzhiyun .resume = ad18xx_resume
1606*4882a593Smuzhiyun #endif
1607*4882a593Smuzhiyun };
1608*4882a593Smuzhiyun
patch_ad1885(struct snd_ac97 * ac97)1609*4882a593Smuzhiyun static int patch_ad1885(struct snd_ac97 * ac97)
1610*4882a593Smuzhiyun {
1611*4882a593Smuzhiyun patch_ad1881(ac97);
1612*4882a593Smuzhiyun /* This is required to deal with the Intel D815EEAL2 */
1613*4882a593Smuzhiyun /* i.e. Line out is actually headphone out from codec */
1614*4882a593Smuzhiyun
1615*4882a593Smuzhiyun /* set default */
1616*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1617*4882a593Smuzhiyun
1618*4882a593Smuzhiyun ac97->build_ops = &patch_ad1885_build_ops;
1619*4882a593Smuzhiyun return 0;
1620*4882a593Smuzhiyun }
1621*4882a593Smuzhiyun
patch_ad1886_specific(struct snd_ac97 * ac97)1622*4882a593Smuzhiyun static int patch_ad1886_specific(struct snd_ac97 * ac97)
1623*4882a593Smuzhiyun {
1624*4882a593Smuzhiyun reset_tlv(ac97, "Headphone Playback Volume",
1625*4882a593Smuzhiyun db_scale_6bit_6db_max);
1626*4882a593Smuzhiyun return 0;
1627*4882a593Smuzhiyun }
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
1630*4882a593Smuzhiyun .build_specific = &patch_ad1886_specific,
1631*4882a593Smuzhiyun #ifdef CONFIG_PM
1632*4882a593Smuzhiyun .resume = ad18xx_resume
1633*4882a593Smuzhiyun #endif
1634*4882a593Smuzhiyun };
1635*4882a593Smuzhiyun
patch_ad1886(struct snd_ac97 * ac97)1636*4882a593Smuzhiyun static int patch_ad1886(struct snd_ac97 * ac97)
1637*4882a593Smuzhiyun {
1638*4882a593Smuzhiyun patch_ad1881(ac97);
1639*4882a593Smuzhiyun /* Presario700 workaround */
1640*4882a593Smuzhiyun /* for Jack Sense/SPDIF Register misetting causing */
1641*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1642*4882a593Smuzhiyun ac97->build_ops = &patch_ad1886_build_ops;
1643*4882a593Smuzhiyun return 0;
1644*4882a593Smuzhiyun }
1645*4882a593Smuzhiyun
1646*4882a593Smuzhiyun /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
1647*4882a593Smuzhiyun #define AC97_AD198X_MBC 0x0003 /* mic boost */
1648*4882a593Smuzhiyun #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1649*4882a593Smuzhiyun #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1650*4882a593Smuzhiyun #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1651*4882a593Smuzhiyun #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1652*4882a593Smuzhiyun #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1653*4882a593Smuzhiyun #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1654*4882a593Smuzhiyun #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1655*4882a593Smuzhiyun #define AC97_AD198X_VREF_SHIFT 2
1656*4882a593Smuzhiyun #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1657*4882a593Smuzhiyun #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1658*4882a593Smuzhiyun #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1659*4882a593Smuzhiyun #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1660*4882a593Smuzhiyun #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1661*4882a593Smuzhiyun /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1662*4882a593Smuzhiyun #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1663*4882a593Smuzhiyun #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1664*4882a593Smuzhiyun #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1665*4882a593Smuzhiyun #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1666*4882a593Smuzhiyun #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1667*4882a593Smuzhiyun #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1668*4882a593Smuzhiyun #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun /* MISC 1 bits (AD1986 register 0x76) */
1671*4882a593Smuzhiyun #define AC97_AD1986_MBC 0x0003 /* mic boost */
1672*4882a593Smuzhiyun #define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1673*4882a593Smuzhiyun #define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1674*4882a593Smuzhiyun #define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1675*4882a593Smuzhiyun #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1676*4882a593Smuzhiyun #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1677*4882a593Smuzhiyun #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1678*4882a593Smuzhiyun #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1679*4882a593Smuzhiyun #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1680*4882a593Smuzhiyun #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1681*4882a593Smuzhiyun #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1682*4882a593Smuzhiyun #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1683*4882a593Smuzhiyun #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1684*4882a593Smuzhiyun #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1685*4882a593Smuzhiyun #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1686*4882a593Smuzhiyun /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1687*4882a593Smuzhiyun #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1688*4882a593Smuzhiyun #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1689*4882a593Smuzhiyun #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1690*4882a593Smuzhiyun #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1691*4882a593Smuzhiyun #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1692*4882a593Smuzhiyun #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun /* MISC 2 bits (AD1986 register 0x70) */
1695*4882a593Smuzhiyun #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1696*4882a593Smuzhiyun
1697*4882a593Smuzhiyun #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1698*4882a593Smuzhiyun #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1699*4882a593Smuzhiyun #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1700*4882a593Smuzhiyun #define AC97_AD1986_CVREF_MASK \
1701*4882a593Smuzhiyun (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1702*4882a593Smuzhiyun #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1703*4882a593Smuzhiyun #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1704*4882a593Smuzhiyun #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1705*4882a593Smuzhiyun #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1706*4882a593Smuzhiyun #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1707*4882a593Smuzhiyun #define AC97_AD1986_MVREF_MASK \
1708*4882a593Smuzhiyun (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun /* MISC 3 bits (AD1986 register 0x7a) */
1711*4882a593Smuzhiyun #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1714*4882a593Smuzhiyun #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1715*4882a593Smuzhiyun #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1716*4882a593Smuzhiyun #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1717*4882a593Smuzhiyun #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1718*4882a593Smuzhiyun #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1719*4882a593Smuzhiyun #define AC97_AD1986_LVREF_MASK \
1720*4882a593Smuzhiyun (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1721*4882a593Smuzhiyun #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1722*4882a593Smuzhiyun #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1723*4882a593Smuzhiyun #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1724*4882a593Smuzhiyun /* input select Surround DACs */
1725*4882a593Smuzhiyun #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1726*4882a593Smuzhiyun /* select C/LFE DACs */
1727*4882a593Smuzhiyun #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1728*4882a593Smuzhiyun
1729*4882a593Smuzhiyun /* Serial Config bits (AD1986 register 0x74) (incomplete) */
1730*4882a593Smuzhiyun #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1731*4882a593Smuzhiyun #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1732*4882a593Smuzhiyun #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1733*4882a593Smuzhiyun #define AC97_AD1986_OMS_MASK \
1734*4882a593Smuzhiyun (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1735*4882a593Smuzhiyun #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1736*4882a593Smuzhiyun #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1737*4882a593Smuzhiyun #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1738*4882a593Smuzhiyun #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1739*4882a593Smuzhiyun /* are MIC sources */
1740*4882a593Smuzhiyun #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1741*4882a593Smuzhiyun /* are MIC sources */
1742*4882a593Smuzhiyun #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1743*4882a593Smuzhiyun /* are MIC sources */
1744*4882a593Smuzhiyun #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1745*4882a593Smuzhiyun /* are MIC sources */
1746*4882a593Smuzhiyun
1747*4882a593Smuzhiyun
snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1748*4882a593Smuzhiyun static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1749*4882a593Smuzhiyun {
1750*4882a593Smuzhiyun static const char * const texts[2] = { "AC-Link", "A/D Converter" };
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 2, texts);
1753*4882a593Smuzhiyun }
1754*4882a593Smuzhiyun
snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1755*4882a593Smuzhiyun static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1756*4882a593Smuzhiyun {
1757*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1758*4882a593Smuzhiyun unsigned short val;
1759*4882a593Smuzhiyun
1760*4882a593Smuzhiyun val = ac97->regs[AC97_AD_SERIAL_CFG];
1761*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1762*4882a593Smuzhiyun return 0;
1763*4882a593Smuzhiyun }
1764*4882a593Smuzhiyun
snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1765*4882a593Smuzhiyun static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1766*4882a593Smuzhiyun {
1767*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1768*4882a593Smuzhiyun unsigned short val;
1769*4882a593Smuzhiyun
1770*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 1)
1771*4882a593Smuzhiyun return -EINVAL;
1772*4882a593Smuzhiyun val = ucontrol->value.enumerated.item[0] << 2;
1773*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1774*4882a593Smuzhiyun }
1775*4882a593Smuzhiyun
1776*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
1777*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1778*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1779*4882a593Smuzhiyun .info = snd_ac97_ad198x_spdif_source_info,
1780*4882a593Smuzhiyun .get = snd_ac97_ad198x_spdif_source_get,
1781*4882a593Smuzhiyun .put = snd_ac97_ad198x_spdif_source_put,
1782*4882a593Smuzhiyun };
1783*4882a593Smuzhiyun
patch_ad198x_post_spdif(struct snd_ac97 * ac97)1784*4882a593Smuzhiyun static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
1785*4882a593Smuzhiyun {
1786*4882a593Smuzhiyun return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1787*4882a593Smuzhiyun }
1788*4882a593Smuzhiyun
1789*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
1790*4882a593Smuzhiyun AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1791*4882a593Smuzhiyun AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1792*4882a593Smuzhiyun };
1793*4882a593Smuzhiyun
1794*4882a593Smuzhiyun /* deny list to avoid HP/Line jack-sense controls
1795*4882a593Smuzhiyun * (SS vendor << 16 | device)
1796*4882a593Smuzhiyun */
1797*4882a593Smuzhiyun static const unsigned int ad1981_jacks_denylist[] = {
1798*4882a593Smuzhiyun 0x10140523, /* Thinkpad R40 */
1799*4882a593Smuzhiyun 0x10140534, /* Thinkpad X31 */
1800*4882a593Smuzhiyun 0x10140537, /* Thinkpad T41p */
1801*4882a593Smuzhiyun 0x1014053e, /* Thinkpad R40e */
1802*4882a593Smuzhiyun 0x10140554, /* Thinkpad T42p/R50p */
1803*4882a593Smuzhiyun 0x10140567, /* Thinkpad T43p 2668-G7U */
1804*4882a593Smuzhiyun 0x10140581, /* Thinkpad X41-2527 */
1805*4882a593Smuzhiyun 0x10280160, /* Dell Dimension 2400 */
1806*4882a593Smuzhiyun 0x104380b0, /* Asus A7V8X-MX */
1807*4882a593Smuzhiyun 0x11790241, /* Toshiba Satellite A-15 S127 */
1808*4882a593Smuzhiyun 0x1179ff10, /* Toshiba P500 */
1809*4882a593Smuzhiyun 0x144dc01a, /* Samsung NP-X20C004/SEG */
1810*4882a593Smuzhiyun 0 /* end */
1811*4882a593Smuzhiyun };
1812*4882a593Smuzhiyun
check_list(struct snd_ac97 * ac97,const unsigned int * list)1813*4882a593Smuzhiyun static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1816*4882a593Smuzhiyun for (; *list; list++)
1817*4882a593Smuzhiyun if (*list == subid)
1818*4882a593Smuzhiyun return 1;
1819*4882a593Smuzhiyun return 0;
1820*4882a593Smuzhiyun }
1821*4882a593Smuzhiyun
patch_ad1981a_specific(struct snd_ac97 * ac97)1822*4882a593Smuzhiyun static int patch_ad1981a_specific(struct snd_ac97 * ac97)
1823*4882a593Smuzhiyun {
1824*4882a593Smuzhiyun if (check_list(ac97, ad1981_jacks_denylist))
1825*4882a593Smuzhiyun return 0;
1826*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1827*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1828*4882a593Smuzhiyun }
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1831*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
1832*4882a593Smuzhiyun .build_specific = patch_ad1981a_specific,
1833*4882a593Smuzhiyun #ifdef CONFIG_PM
1834*4882a593Smuzhiyun .resume = ad18xx_resume
1835*4882a593Smuzhiyun #endif
1836*4882a593Smuzhiyun };
1837*4882a593Smuzhiyun
1838*4882a593Smuzhiyun /* allow list to enable HP jack-sense bits
1839*4882a593Smuzhiyun * (SS vendor << 16 | device)
1840*4882a593Smuzhiyun */
1841*4882a593Smuzhiyun static const unsigned int ad1981_jacks_allowlist[] = {
1842*4882a593Smuzhiyun 0x0e11005a, /* HP nc4000/4010 */
1843*4882a593Smuzhiyun 0x103c0890, /* HP nc6000 */
1844*4882a593Smuzhiyun 0x103c0938, /* HP nc4220 */
1845*4882a593Smuzhiyun 0x103c099c, /* HP nx6110 */
1846*4882a593Smuzhiyun 0x103c0944, /* HP nc6220 */
1847*4882a593Smuzhiyun 0x103c0934, /* HP nc8220 */
1848*4882a593Smuzhiyun 0x103c006d, /* HP nx9105 */
1849*4882a593Smuzhiyun 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
1850*4882a593Smuzhiyun 0x17340088, /* FSC Scenic-W */
1851*4882a593Smuzhiyun 0 /* end */
1852*4882a593Smuzhiyun };
1853*4882a593Smuzhiyun
check_ad1981_hp_jack_sense(struct snd_ac97 * ac97)1854*4882a593Smuzhiyun static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
1855*4882a593Smuzhiyun {
1856*4882a593Smuzhiyun if (check_list(ac97, ad1981_jacks_allowlist))
1857*4882a593Smuzhiyun /* enable headphone jack sense */
1858*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1859*4882a593Smuzhiyun }
1860*4882a593Smuzhiyun
patch_ad1981a(struct snd_ac97 * ac97)1861*4882a593Smuzhiyun static int patch_ad1981a(struct snd_ac97 *ac97)
1862*4882a593Smuzhiyun {
1863*4882a593Smuzhiyun patch_ad1881(ac97);
1864*4882a593Smuzhiyun ac97->build_ops = &patch_ad1981a_build_ops;
1865*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1866*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
1867*4882a593Smuzhiyun check_ad1981_hp_jack_sense(ac97);
1868*4882a593Smuzhiyun return 0;
1869*4882a593Smuzhiyun }
1870*4882a593Smuzhiyun
1871*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
1872*4882a593Smuzhiyun AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1873*4882a593Smuzhiyun
patch_ad1981b_specific(struct snd_ac97 * ac97)1874*4882a593Smuzhiyun static int patch_ad1981b_specific(struct snd_ac97 *ac97)
1875*4882a593Smuzhiyun {
1876*4882a593Smuzhiyun int err;
1877*4882a593Smuzhiyun
1878*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1879*4882a593Smuzhiyun return err;
1880*4882a593Smuzhiyun if (check_list(ac97, ad1981_jacks_denylist))
1881*4882a593Smuzhiyun return 0;
1882*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1883*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1884*4882a593Smuzhiyun }
1885*4882a593Smuzhiyun
1886*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1887*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
1888*4882a593Smuzhiyun .build_specific = patch_ad1981b_specific,
1889*4882a593Smuzhiyun #ifdef CONFIG_PM
1890*4882a593Smuzhiyun .resume = ad18xx_resume
1891*4882a593Smuzhiyun #endif
1892*4882a593Smuzhiyun };
1893*4882a593Smuzhiyun
patch_ad1981b(struct snd_ac97 * ac97)1894*4882a593Smuzhiyun static int patch_ad1981b(struct snd_ac97 *ac97)
1895*4882a593Smuzhiyun {
1896*4882a593Smuzhiyun patch_ad1881(ac97);
1897*4882a593Smuzhiyun ac97->build_ops = &patch_ad1981b_build_ops;
1898*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1899*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
1900*4882a593Smuzhiyun check_ad1981_hp_jack_sense(ac97);
1901*4882a593Smuzhiyun return 0;
1902*4882a593Smuzhiyun }
1903*4882a593Smuzhiyun
1904*4882a593Smuzhiyun #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
1905*4882a593Smuzhiyun
snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1906*4882a593Smuzhiyun static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1907*4882a593Smuzhiyun {
1908*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1909*4882a593Smuzhiyun unsigned short val;
1910*4882a593Smuzhiyun
1911*4882a593Smuzhiyun val = ac97->regs[AC97_AD_MISC];
1912*4882a593Smuzhiyun ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1913*4882a593Smuzhiyun if (ac97->spec.ad18xx.lo_as_master)
1914*4882a593Smuzhiyun ucontrol->value.integer.value[0] =
1915*4882a593Smuzhiyun !ucontrol->value.integer.value[0];
1916*4882a593Smuzhiyun return 0;
1917*4882a593Smuzhiyun }
1918*4882a593Smuzhiyun
snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1919*4882a593Smuzhiyun static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1920*4882a593Smuzhiyun {
1921*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1922*4882a593Smuzhiyun unsigned short val;
1923*4882a593Smuzhiyun
1924*4882a593Smuzhiyun val = !ucontrol->value.integer.value[0];
1925*4882a593Smuzhiyun if (ac97->spec.ad18xx.lo_as_master)
1926*4882a593Smuzhiyun val = !val;
1927*4882a593Smuzhiyun val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1928*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1929*4882a593Smuzhiyun AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1930*4882a593Smuzhiyun }
1931*4882a593Smuzhiyun
snd_ac97_ad1888_downmix_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1932*4882a593Smuzhiyun static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1933*4882a593Smuzhiyun {
1934*4882a593Smuzhiyun static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1935*4882a593Smuzhiyun
1936*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts);
1937*4882a593Smuzhiyun }
1938*4882a593Smuzhiyun
snd_ac97_ad1888_downmix_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1939*4882a593Smuzhiyun static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1940*4882a593Smuzhiyun {
1941*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1942*4882a593Smuzhiyun unsigned short val;
1943*4882a593Smuzhiyun
1944*4882a593Smuzhiyun val = ac97->regs[AC97_AD_MISC];
1945*4882a593Smuzhiyun if (!(val & AC97_AD198X_DMIX1))
1946*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 0;
1947*4882a593Smuzhiyun else
1948*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1949*4882a593Smuzhiyun return 0;
1950*4882a593Smuzhiyun }
1951*4882a593Smuzhiyun
snd_ac97_ad1888_downmix_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1952*4882a593Smuzhiyun static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1953*4882a593Smuzhiyun {
1954*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1955*4882a593Smuzhiyun unsigned short val;
1956*4882a593Smuzhiyun
1957*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 2)
1958*4882a593Smuzhiyun return -EINVAL;
1959*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] == 0)
1960*4882a593Smuzhiyun val = 0;
1961*4882a593Smuzhiyun else
1962*4882a593Smuzhiyun val = AC97_AD198X_DMIX1 |
1963*4882a593Smuzhiyun ((ucontrol->value.enumerated.item[0] - 1) << 8);
1964*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1965*4882a593Smuzhiyun AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1966*4882a593Smuzhiyun }
1967*4882a593Smuzhiyun
ad1888_update_jacks(struct snd_ac97 * ac97)1968*4882a593Smuzhiyun static void ad1888_update_jacks(struct snd_ac97 *ac97)
1969*4882a593Smuzhiyun {
1970*4882a593Smuzhiyun unsigned short val = 0;
1971*4882a593Smuzhiyun /* clear LODIS if shared jack is to be used for Surround out */
1972*4882a593Smuzhiyun if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
1973*4882a593Smuzhiyun val |= (1 << 12);
1974*4882a593Smuzhiyun /* clear CLDIS if shared jack is to be used for C/LFE out */
1975*4882a593Smuzhiyun if (is_shared_micin(ac97))
1976*4882a593Smuzhiyun val |= (1 << 11);
1977*4882a593Smuzhiyun /* shared Line-In */
1978*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1979*4882a593Smuzhiyun }
1980*4882a593Smuzhiyun
1981*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
1982*4882a593Smuzhiyun {
1983*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1984*4882a593Smuzhiyun .name = "Exchange Front/Surround",
1985*4882a593Smuzhiyun .info = snd_ac97_ad1888_lohpsel_info,
1986*4882a593Smuzhiyun .get = snd_ac97_ad1888_lohpsel_get,
1987*4882a593Smuzhiyun .put = snd_ac97_ad1888_lohpsel_put
1988*4882a593Smuzhiyun },
1989*4882a593Smuzhiyun AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
1990*4882a593Smuzhiyun AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
1991*4882a593Smuzhiyun AC97_AD_HPFD_SHIFT, 1, 1),
1992*4882a593Smuzhiyun AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1993*4882a593Smuzhiyun {
1994*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1995*4882a593Smuzhiyun .name = "Downmix",
1996*4882a593Smuzhiyun .info = snd_ac97_ad1888_downmix_info,
1997*4882a593Smuzhiyun .get = snd_ac97_ad1888_downmix_get,
1998*4882a593Smuzhiyun .put = snd_ac97_ad1888_downmix_put
1999*4882a593Smuzhiyun },
2000*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2001*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
2002*4882a593Smuzhiyun
2003*4882a593Smuzhiyun AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2004*4882a593Smuzhiyun AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
2005*4882a593Smuzhiyun };
2006*4882a593Smuzhiyun
patch_ad1888_specific(struct snd_ac97 * ac97)2007*4882a593Smuzhiyun static int patch_ad1888_specific(struct snd_ac97 *ac97)
2008*4882a593Smuzhiyun {
2009*4882a593Smuzhiyun if (!ac97->spec.ad18xx.lo_as_master) {
2010*4882a593Smuzhiyun /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2011*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2012*4882a593Smuzhiyun "Master Surround Playback");
2013*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
2014*4882a593Smuzhiyun "Master Playback");
2015*4882a593Smuzhiyun }
2016*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
2017*4882a593Smuzhiyun }
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
2020*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
2021*4882a593Smuzhiyun .build_specific = patch_ad1888_specific,
2022*4882a593Smuzhiyun #ifdef CONFIG_PM
2023*4882a593Smuzhiyun .resume = ad1888_resume,
2024*4882a593Smuzhiyun #endif
2025*4882a593Smuzhiyun .update_jacks = ad1888_update_jacks,
2026*4882a593Smuzhiyun };
2027*4882a593Smuzhiyun
patch_ad1888(struct snd_ac97 * ac97)2028*4882a593Smuzhiyun static int patch_ad1888(struct snd_ac97 * ac97)
2029*4882a593Smuzhiyun {
2030*4882a593Smuzhiyun unsigned short misc;
2031*4882a593Smuzhiyun
2032*4882a593Smuzhiyun patch_ad1881(ac97);
2033*4882a593Smuzhiyun ac97->build_ops = &patch_ad1888_build_ops;
2034*4882a593Smuzhiyun
2035*4882a593Smuzhiyun /*
2036*4882a593Smuzhiyun * LO can be used as a real line-out on some devices,
2037*4882a593Smuzhiyun * and we need to revert the front/surround mixer switches
2038*4882a593Smuzhiyun */
2039*4882a593Smuzhiyun if (ac97->subsystem_vendor == 0x1043 &&
2040*4882a593Smuzhiyun ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
2041*4882a593Smuzhiyun ac97->spec.ad18xx.lo_as_master = 1;
2042*4882a593Smuzhiyun
2043*4882a593Smuzhiyun misc = snd_ac97_read(ac97, AC97_AD_MISC);
2044*4882a593Smuzhiyun /* AD-compatible mode */
2045*4882a593Smuzhiyun /* Stereo mutes enabled */
2046*4882a593Smuzhiyun misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
2047*4882a593Smuzhiyun if (!ac97->spec.ad18xx.lo_as_master)
2048*4882a593Smuzhiyun /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2049*4882a593Smuzhiyun /* it seems that most vendors connect line-out connector to
2050*4882a593Smuzhiyun * headphone out of AC'97
2051*4882a593Smuzhiyun */
2052*4882a593Smuzhiyun misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
2055*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
2056*4882a593Smuzhiyun return 0;
2057*4882a593Smuzhiyun }
2058*4882a593Smuzhiyun
patch_ad1980_specific(struct snd_ac97 * ac97)2059*4882a593Smuzhiyun static int patch_ad1980_specific(struct snd_ac97 *ac97)
2060*4882a593Smuzhiyun {
2061*4882a593Smuzhiyun int err;
2062*4882a593Smuzhiyun
2063*4882a593Smuzhiyun if ((err = patch_ad1888_specific(ac97)) < 0)
2064*4882a593Smuzhiyun return err;
2065*4882a593Smuzhiyun return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2066*4882a593Smuzhiyun }
2067*4882a593Smuzhiyun
2068*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
2069*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
2070*4882a593Smuzhiyun .build_specific = patch_ad1980_specific,
2071*4882a593Smuzhiyun #ifdef CONFIG_PM
2072*4882a593Smuzhiyun .resume = ad18xx_resume,
2073*4882a593Smuzhiyun #endif
2074*4882a593Smuzhiyun .update_jacks = ad1888_update_jacks,
2075*4882a593Smuzhiyun };
2076*4882a593Smuzhiyun
patch_ad1980(struct snd_ac97 * ac97)2077*4882a593Smuzhiyun static int patch_ad1980(struct snd_ac97 * ac97)
2078*4882a593Smuzhiyun {
2079*4882a593Smuzhiyun patch_ad1888(ac97);
2080*4882a593Smuzhiyun ac97->build_ops = &patch_ad1980_build_ops;
2081*4882a593Smuzhiyun return 0;
2082*4882a593Smuzhiyun }
2083*4882a593Smuzhiyun
snd_ac97_ad1985_vrefout_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)2084*4882a593Smuzhiyun static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2085*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
2086*4882a593Smuzhiyun {
2087*4882a593Smuzhiyun static const char * const texts[4] = {
2088*4882a593Smuzhiyun "High-Z", "3.7 V", "2.25 V", "0 V"
2089*4882a593Smuzhiyun };
2090*4882a593Smuzhiyun
2091*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 4, texts);
2092*4882a593Smuzhiyun }
2093*4882a593Smuzhiyun
snd_ac97_ad1985_vrefout_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2094*4882a593Smuzhiyun static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
2095*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2096*4882a593Smuzhiyun {
2097*4882a593Smuzhiyun static const int reg2ctrl[4] = {2, 0, 1, 3};
2098*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2099*4882a593Smuzhiyun unsigned short val;
2100*4882a593Smuzhiyun val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
2101*4882a593Smuzhiyun >> AC97_AD198X_VREF_SHIFT;
2102*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = reg2ctrl[val];
2103*4882a593Smuzhiyun return 0;
2104*4882a593Smuzhiyun }
2105*4882a593Smuzhiyun
snd_ac97_ad1985_vrefout_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2106*4882a593Smuzhiyun static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
2107*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2108*4882a593Smuzhiyun {
2109*4882a593Smuzhiyun static const int ctrl2reg[4] = {1, 2, 0, 3};
2110*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2111*4882a593Smuzhiyun unsigned short val;
2112*4882a593Smuzhiyun
2113*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] > 3)
2114*4882a593Smuzhiyun return -EINVAL;
2115*4882a593Smuzhiyun val = ctrl2reg[ucontrol->value.enumerated.item[0]]
2116*4882a593Smuzhiyun << AC97_AD198X_VREF_SHIFT;
2117*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_AD_MISC,
2118*4882a593Smuzhiyun AC97_AD198X_VREF_MASK, val);
2119*4882a593Smuzhiyun }
2120*4882a593Smuzhiyun
2121*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
2122*4882a593Smuzhiyun AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2123*4882a593Smuzhiyun {
2124*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2125*4882a593Smuzhiyun .name = "Exchange Front/Surround",
2126*4882a593Smuzhiyun .info = snd_ac97_ad1888_lohpsel_info,
2127*4882a593Smuzhiyun .get = snd_ac97_ad1888_lohpsel_get,
2128*4882a593Smuzhiyun .put = snd_ac97_ad1888_lohpsel_put
2129*4882a593Smuzhiyun },
2130*4882a593Smuzhiyun AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
2131*4882a593Smuzhiyun AC97_SINGLE("Spread Front to Surround and Center/LFE",
2132*4882a593Smuzhiyun AC97_AD_MISC, 7, 1, 0),
2133*4882a593Smuzhiyun {
2134*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2135*4882a593Smuzhiyun .name = "Downmix",
2136*4882a593Smuzhiyun .info = snd_ac97_ad1888_downmix_info,
2137*4882a593Smuzhiyun .get = snd_ac97_ad1888_downmix_get,
2138*4882a593Smuzhiyun .put = snd_ac97_ad1888_downmix_put
2139*4882a593Smuzhiyun },
2140*4882a593Smuzhiyun {
2141*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2142*4882a593Smuzhiyun .name = "V_REFOUT",
2143*4882a593Smuzhiyun .info = snd_ac97_ad1985_vrefout_info,
2144*4882a593Smuzhiyun .get = snd_ac97_ad1985_vrefout_get,
2145*4882a593Smuzhiyun .put = snd_ac97_ad1985_vrefout_put
2146*4882a593Smuzhiyun },
2147*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2148*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
2149*4882a593Smuzhiyun
2150*4882a593Smuzhiyun AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2151*4882a593Smuzhiyun AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
2152*4882a593Smuzhiyun };
2153*4882a593Smuzhiyun
ad1985_update_jacks(struct snd_ac97 * ac97)2154*4882a593Smuzhiyun static void ad1985_update_jacks(struct snd_ac97 *ac97)
2155*4882a593Smuzhiyun {
2156*4882a593Smuzhiyun ad1888_update_jacks(ac97);
2157*4882a593Smuzhiyun /* clear OMS if shared jack is to be used for C/LFE out */
2158*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
2159*4882a593Smuzhiyun is_shared_micin(ac97) ? 1 << 9 : 0);
2160*4882a593Smuzhiyun }
2161*4882a593Smuzhiyun
patch_ad1985_specific(struct snd_ac97 * ac97)2162*4882a593Smuzhiyun static int patch_ad1985_specific(struct snd_ac97 *ac97)
2163*4882a593Smuzhiyun {
2164*4882a593Smuzhiyun int err;
2165*4882a593Smuzhiyun
2166*4882a593Smuzhiyun /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2167*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2168*4882a593Smuzhiyun "Master Surround Playback");
2169*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2170*4882a593Smuzhiyun
2171*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2172*4882a593Smuzhiyun return err;
2173*4882a593Smuzhiyun
2174*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_ad1985_controls,
2175*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_ad1985_controls));
2176*4882a593Smuzhiyun }
2177*4882a593Smuzhiyun
2178*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
2179*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
2180*4882a593Smuzhiyun .build_specific = patch_ad1985_specific,
2181*4882a593Smuzhiyun #ifdef CONFIG_PM
2182*4882a593Smuzhiyun .resume = ad18xx_resume,
2183*4882a593Smuzhiyun #endif
2184*4882a593Smuzhiyun .update_jacks = ad1985_update_jacks,
2185*4882a593Smuzhiyun };
2186*4882a593Smuzhiyun
patch_ad1985(struct snd_ac97 * ac97)2187*4882a593Smuzhiyun static int patch_ad1985(struct snd_ac97 * ac97)
2188*4882a593Smuzhiyun {
2189*4882a593Smuzhiyun unsigned short misc;
2190*4882a593Smuzhiyun
2191*4882a593Smuzhiyun patch_ad1881(ac97);
2192*4882a593Smuzhiyun ac97->build_ops = &patch_ad1985_build_ops;
2193*4882a593Smuzhiyun misc = snd_ac97_read(ac97, AC97_AD_MISC);
2194*4882a593Smuzhiyun /* switch front/surround line-out/hp-out */
2195*4882a593Smuzhiyun /* AD-compatible mode */
2196*4882a593Smuzhiyun /* Stereo mutes enabled */
2197*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
2198*4882a593Smuzhiyun AC97_AD198X_LOSEL |
2199*4882a593Smuzhiyun AC97_AD198X_HPSEL |
2200*4882a593Smuzhiyun AC97_AD198X_MSPLT |
2201*4882a593Smuzhiyun AC97_AD198X_AC97NC);
2202*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
2203*4882a593Smuzhiyun
2204*4882a593Smuzhiyun /* update current jack configuration */
2205*4882a593Smuzhiyun ad1985_update_jacks(ac97);
2206*4882a593Smuzhiyun
2207*4882a593Smuzhiyun /* on AD1985 rev. 3, AC'97 revision bits are zero */
2208*4882a593Smuzhiyun ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2209*4882a593Smuzhiyun return 0;
2210*4882a593Smuzhiyun }
2211*4882a593Smuzhiyun
2212*4882a593Smuzhiyun #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
2213*4882a593Smuzhiyun
snd_ac97_ad1986_lososel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2214*4882a593Smuzhiyun static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
2215*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2216*4882a593Smuzhiyun {
2217*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2218*4882a593Smuzhiyun unsigned short val;
2219*4882a593Smuzhiyun
2220*4882a593Smuzhiyun val = ac97->regs[AC97_AD_MISC3];
2221*4882a593Smuzhiyun ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
2222*4882a593Smuzhiyun return 0;
2223*4882a593Smuzhiyun }
2224*4882a593Smuzhiyun
snd_ac97_ad1986_lososel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2225*4882a593Smuzhiyun static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
2226*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2227*4882a593Smuzhiyun {
2228*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2229*4882a593Smuzhiyun int ret0;
2230*4882a593Smuzhiyun int ret1;
2231*4882a593Smuzhiyun int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
2232*4882a593Smuzhiyun
2233*4882a593Smuzhiyun ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
2234*4882a593Smuzhiyun ucontrol->value.integer.value[0] != 0
2235*4882a593Smuzhiyun ? AC97_AD1986_LOSEL : 0);
2236*4882a593Smuzhiyun if (ret0 < 0)
2237*4882a593Smuzhiyun return ret0;
2238*4882a593Smuzhiyun
2239*4882a593Smuzhiyun /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2240*4882a593Smuzhiyun ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2241*4882a593Smuzhiyun (ucontrol->value.integer.value[0] != 0
2242*4882a593Smuzhiyun || sprd)
2243*4882a593Smuzhiyun ? AC97_AD1986_SOSEL : 0);
2244*4882a593Smuzhiyun if (ret1 < 0)
2245*4882a593Smuzhiyun return ret1;
2246*4882a593Smuzhiyun
2247*4882a593Smuzhiyun return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2248*4882a593Smuzhiyun }
2249*4882a593Smuzhiyun
snd_ac97_ad1986_spread_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2250*4882a593Smuzhiyun static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
2251*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2252*4882a593Smuzhiyun {
2253*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2254*4882a593Smuzhiyun unsigned short val;
2255*4882a593Smuzhiyun
2256*4882a593Smuzhiyun val = ac97->regs[AC97_AD_MISC];
2257*4882a593Smuzhiyun ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
2258*4882a593Smuzhiyun return 0;
2259*4882a593Smuzhiyun }
2260*4882a593Smuzhiyun
snd_ac97_ad1986_spread_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2261*4882a593Smuzhiyun static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
2262*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2263*4882a593Smuzhiyun {
2264*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2265*4882a593Smuzhiyun int ret0;
2266*4882a593Smuzhiyun int ret1;
2267*4882a593Smuzhiyun int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
2268*4882a593Smuzhiyun
2269*4882a593Smuzhiyun ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
2270*4882a593Smuzhiyun ucontrol->value.integer.value[0] != 0
2271*4882a593Smuzhiyun ? AC97_AD1986_SPRD : 0);
2272*4882a593Smuzhiyun if (ret0 < 0)
2273*4882a593Smuzhiyun return ret0;
2274*4882a593Smuzhiyun
2275*4882a593Smuzhiyun /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2276*4882a593Smuzhiyun ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2277*4882a593Smuzhiyun (ucontrol->value.integer.value[0] != 0
2278*4882a593Smuzhiyun || sprd)
2279*4882a593Smuzhiyun ? AC97_AD1986_SOSEL : 0);
2280*4882a593Smuzhiyun if (ret1 < 0)
2281*4882a593Smuzhiyun return ret1;
2282*4882a593Smuzhiyun
2283*4882a593Smuzhiyun return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2284*4882a593Smuzhiyun }
2285*4882a593Smuzhiyun
snd_ac97_ad1986_miclisel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2286*4882a593Smuzhiyun static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
2287*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2288*4882a593Smuzhiyun {
2289*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2290*4882a593Smuzhiyun
2291*4882a593Smuzhiyun ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
2292*4882a593Smuzhiyun return 0;
2293*4882a593Smuzhiyun }
2294*4882a593Smuzhiyun
snd_ac97_ad1986_miclisel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2295*4882a593Smuzhiyun static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
2296*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2297*4882a593Smuzhiyun {
2298*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2299*4882a593Smuzhiyun unsigned char swap = ucontrol->value.integer.value[0] != 0;
2300*4882a593Smuzhiyun
2301*4882a593Smuzhiyun if (swap != ac97->spec.ad18xx.swap_mic_linein) {
2302*4882a593Smuzhiyun ac97->spec.ad18xx.swap_mic_linein = swap;
2303*4882a593Smuzhiyun if (ac97->build_ops->update_jacks)
2304*4882a593Smuzhiyun ac97->build_ops->update_jacks(ac97);
2305*4882a593Smuzhiyun return 1;
2306*4882a593Smuzhiyun }
2307*4882a593Smuzhiyun return 0;
2308*4882a593Smuzhiyun }
2309*4882a593Smuzhiyun
snd_ac97_ad1986_vrefout_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2310*4882a593Smuzhiyun static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
2311*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2312*4882a593Smuzhiyun {
2313*4882a593Smuzhiyun /* Use MIC_1/2 V_REFOUT as the "get" value */
2314*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2315*4882a593Smuzhiyun unsigned short val;
2316*4882a593Smuzhiyun unsigned short reg = ac97->regs[AC97_AD_MISC2];
2317*4882a593Smuzhiyun if ((reg & AC97_AD1986_MVREF0) != 0)
2318*4882a593Smuzhiyun val = 2;
2319*4882a593Smuzhiyun else if ((reg & AC97_AD1986_MVREF1) != 0)
2320*4882a593Smuzhiyun val = 3;
2321*4882a593Smuzhiyun else if ((reg & AC97_AD1986_MVREF2) != 0)
2322*4882a593Smuzhiyun val = 1;
2323*4882a593Smuzhiyun else
2324*4882a593Smuzhiyun val = 0;
2325*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = val;
2326*4882a593Smuzhiyun return 0;
2327*4882a593Smuzhiyun }
2328*4882a593Smuzhiyun
snd_ac97_ad1986_vrefout_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2329*4882a593Smuzhiyun static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
2330*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2331*4882a593Smuzhiyun {
2332*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2333*4882a593Smuzhiyun unsigned short cval;
2334*4882a593Smuzhiyun unsigned short lval;
2335*4882a593Smuzhiyun unsigned short mval;
2336*4882a593Smuzhiyun int cret;
2337*4882a593Smuzhiyun int lret;
2338*4882a593Smuzhiyun int mret;
2339*4882a593Smuzhiyun
2340*4882a593Smuzhiyun switch (ucontrol->value.enumerated.item[0])
2341*4882a593Smuzhiyun {
2342*4882a593Smuzhiyun case 0: /* High-Z */
2343*4882a593Smuzhiyun cval = 0;
2344*4882a593Smuzhiyun lval = 0;
2345*4882a593Smuzhiyun mval = 0;
2346*4882a593Smuzhiyun break;
2347*4882a593Smuzhiyun case 1: /* 3.7 V */
2348*4882a593Smuzhiyun cval = AC97_AD1986_CVREF2;
2349*4882a593Smuzhiyun lval = AC97_AD1986_LVREF2;
2350*4882a593Smuzhiyun mval = AC97_AD1986_MVREF2;
2351*4882a593Smuzhiyun break;
2352*4882a593Smuzhiyun case 2: /* 2.25 V */
2353*4882a593Smuzhiyun cval = AC97_AD1986_CVREF0;
2354*4882a593Smuzhiyun lval = AC97_AD1986_LVREF0;
2355*4882a593Smuzhiyun mval = AC97_AD1986_MVREF0;
2356*4882a593Smuzhiyun break;
2357*4882a593Smuzhiyun case 3: /* 0 V */
2358*4882a593Smuzhiyun cval = AC97_AD1986_CVREF1;
2359*4882a593Smuzhiyun lval = AC97_AD1986_LVREF1;
2360*4882a593Smuzhiyun mval = AC97_AD1986_MVREF1;
2361*4882a593Smuzhiyun break;
2362*4882a593Smuzhiyun default:
2363*4882a593Smuzhiyun return -EINVAL;
2364*4882a593Smuzhiyun }
2365*4882a593Smuzhiyun
2366*4882a593Smuzhiyun cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2367*4882a593Smuzhiyun AC97_AD1986_CVREF_MASK, cval);
2368*4882a593Smuzhiyun if (cret < 0)
2369*4882a593Smuzhiyun return cret;
2370*4882a593Smuzhiyun lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
2371*4882a593Smuzhiyun AC97_AD1986_LVREF_MASK, lval);
2372*4882a593Smuzhiyun if (lret < 0)
2373*4882a593Smuzhiyun return lret;
2374*4882a593Smuzhiyun mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2375*4882a593Smuzhiyun AC97_AD1986_MVREF_MASK, mval);
2376*4882a593Smuzhiyun if (mret < 0)
2377*4882a593Smuzhiyun return mret;
2378*4882a593Smuzhiyun
2379*4882a593Smuzhiyun return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
2380*4882a593Smuzhiyun }
2381*4882a593Smuzhiyun
2382*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
2383*4882a593Smuzhiyun AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2384*4882a593Smuzhiyun {
2385*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2386*4882a593Smuzhiyun .name = "Exchange Front/Surround",
2387*4882a593Smuzhiyun .info = snd_ac97_ad1986_bool_info,
2388*4882a593Smuzhiyun .get = snd_ac97_ad1986_lososel_get,
2389*4882a593Smuzhiyun .put = snd_ac97_ad1986_lososel_put
2390*4882a593Smuzhiyun },
2391*4882a593Smuzhiyun {
2392*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2393*4882a593Smuzhiyun .name = "Exchange Mic/Line In",
2394*4882a593Smuzhiyun .info = snd_ac97_ad1986_bool_info,
2395*4882a593Smuzhiyun .get = snd_ac97_ad1986_miclisel_get,
2396*4882a593Smuzhiyun .put = snd_ac97_ad1986_miclisel_put
2397*4882a593Smuzhiyun },
2398*4882a593Smuzhiyun {
2399*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2400*4882a593Smuzhiyun .name = "Spread Front to Surround and Center/LFE",
2401*4882a593Smuzhiyun .info = snd_ac97_ad1986_bool_info,
2402*4882a593Smuzhiyun .get = snd_ac97_ad1986_spread_get,
2403*4882a593Smuzhiyun .put = snd_ac97_ad1986_spread_put
2404*4882a593Smuzhiyun },
2405*4882a593Smuzhiyun {
2406*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2407*4882a593Smuzhiyun .name = "Downmix",
2408*4882a593Smuzhiyun .info = snd_ac97_ad1888_downmix_info,
2409*4882a593Smuzhiyun .get = snd_ac97_ad1888_downmix_get,
2410*4882a593Smuzhiyun .put = snd_ac97_ad1888_downmix_put
2411*4882a593Smuzhiyun },
2412*4882a593Smuzhiyun {
2413*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2414*4882a593Smuzhiyun .name = "V_REFOUT",
2415*4882a593Smuzhiyun .info = snd_ac97_ad1985_vrefout_info,
2416*4882a593Smuzhiyun .get = snd_ac97_ad1986_vrefout_get,
2417*4882a593Smuzhiyun .put = snd_ac97_ad1986_vrefout_put
2418*4882a593Smuzhiyun },
2419*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2420*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
2421*4882a593Smuzhiyun
2422*4882a593Smuzhiyun AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2423*4882a593Smuzhiyun AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
2424*4882a593Smuzhiyun };
2425*4882a593Smuzhiyun
ad1986_update_jacks(struct snd_ac97 * ac97)2426*4882a593Smuzhiyun static void ad1986_update_jacks(struct snd_ac97 *ac97)
2427*4882a593Smuzhiyun {
2428*4882a593Smuzhiyun unsigned short misc_val = 0;
2429*4882a593Smuzhiyun unsigned short ser_val;
2430*4882a593Smuzhiyun
2431*4882a593Smuzhiyun /* disable SURROUND and CENTER/LFE if not surround mode */
2432*4882a593Smuzhiyun if (!is_surround_on(ac97))
2433*4882a593Smuzhiyun misc_val |= AC97_AD1986_SODIS;
2434*4882a593Smuzhiyun if (!is_clfe_on(ac97))
2435*4882a593Smuzhiyun misc_val |= AC97_AD1986_CLDIS;
2436*4882a593Smuzhiyun
2437*4882a593Smuzhiyun /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2438*4882a593Smuzhiyun if (is_shared_linein(ac97))
2439*4882a593Smuzhiyun misc_val |= AC97_AD1986_LISEL_SURR;
2440*4882a593Smuzhiyun else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2441*4882a593Smuzhiyun misc_val |= AC97_AD1986_LISEL_MIC;
2442*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_MISC,
2443*4882a593Smuzhiyun AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
2444*4882a593Smuzhiyun AC97_AD1986_LISEL_MASK,
2445*4882a593Smuzhiyun misc_val);
2446*4882a593Smuzhiyun
2447*4882a593Smuzhiyun /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2448*4882a593Smuzhiyun if (is_shared_micin(ac97))
2449*4882a593Smuzhiyun ser_val = AC97_AD1986_OMS_C;
2450*4882a593Smuzhiyun else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2451*4882a593Smuzhiyun ser_val = AC97_AD1986_OMS_L;
2452*4882a593Smuzhiyun else
2453*4882a593Smuzhiyun ser_val = AC97_AD1986_OMS_M;
2454*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
2455*4882a593Smuzhiyun AC97_AD1986_OMS_MASK,
2456*4882a593Smuzhiyun ser_val);
2457*4882a593Smuzhiyun }
2458*4882a593Smuzhiyun
patch_ad1986_specific(struct snd_ac97 * ac97)2459*4882a593Smuzhiyun static int patch_ad1986_specific(struct snd_ac97 *ac97)
2460*4882a593Smuzhiyun {
2461*4882a593Smuzhiyun int err;
2462*4882a593Smuzhiyun
2463*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2464*4882a593Smuzhiyun return err;
2465*4882a593Smuzhiyun
2466*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_ad1986_controls,
2467*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_ad1985_controls));
2468*4882a593Smuzhiyun }
2469*4882a593Smuzhiyun
2470*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
2471*4882a593Smuzhiyun .build_post_spdif = patch_ad198x_post_spdif,
2472*4882a593Smuzhiyun .build_specific = patch_ad1986_specific,
2473*4882a593Smuzhiyun #ifdef CONFIG_PM
2474*4882a593Smuzhiyun .resume = ad18xx_resume,
2475*4882a593Smuzhiyun #endif
2476*4882a593Smuzhiyun .update_jacks = ad1986_update_jacks,
2477*4882a593Smuzhiyun };
2478*4882a593Smuzhiyun
patch_ad1986(struct snd_ac97 * ac97)2479*4882a593Smuzhiyun static int patch_ad1986(struct snd_ac97 * ac97)
2480*4882a593Smuzhiyun {
2481*4882a593Smuzhiyun patch_ad1881(ac97);
2482*4882a593Smuzhiyun ac97->build_ops = &patch_ad1986_build_ops;
2483*4882a593Smuzhiyun ac97->flags |= AC97_STEREO_MUTES;
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun /* update current jack configuration */
2486*4882a593Smuzhiyun ad1986_update_jacks(ac97);
2487*4882a593Smuzhiyun
2488*4882a593Smuzhiyun return 0;
2489*4882a593Smuzhiyun }
2490*4882a593Smuzhiyun
2491*4882a593Smuzhiyun /*
2492*4882a593Smuzhiyun * realtek ALC203: use mono-out for pin 37
2493*4882a593Smuzhiyun */
patch_alc203(struct snd_ac97 * ac97)2494*4882a593Smuzhiyun static int patch_alc203(struct snd_ac97 *ac97)
2495*4882a593Smuzhiyun {
2496*4882a593Smuzhiyun snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
2497*4882a593Smuzhiyun return 0;
2498*4882a593Smuzhiyun }
2499*4882a593Smuzhiyun
2500*4882a593Smuzhiyun /*
2501*4882a593Smuzhiyun * realtek ALC65x/850 codecs
2502*4882a593Smuzhiyun */
alc650_update_jacks(struct snd_ac97 * ac97)2503*4882a593Smuzhiyun static void alc650_update_jacks(struct snd_ac97 *ac97)
2504*4882a593Smuzhiyun {
2505*4882a593Smuzhiyun int shared;
2506*4882a593Smuzhiyun
2507*4882a593Smuzhiyun /* shared Line-In / Surround Out */
2508*4882a593Smuzhiyun shared = is_shared_surrout(ac97);
2509*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2510*4882a593Smuzhiyun shared ? (1 << 9) : 0);
2511*4882a593Smuzhiyun /* update shared Mic In / Center/LFE Out */
2512*4882a593Smuzhiyun shared = is_shared_clfeout(ac97);
2513*4882a593Smuzhiyun /* disable/enable vref */
2514*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2515*4882a593Smuzhiyun shared ? (1 << 12) : 0);
2516*4882a593Smuzhiyun /* turn on/off center-on-mic */
2517*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2518*4882a593Smuzhiyun shared ? (1 << 10) : 0);
2519*4882a593Smuzhiyun /* GPIO0 high for mic */
2520*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2521*4882a593Smuzhiyun shared ? 0 : 0x100);
2522*4882a593Smuzhiyun }
2523*4882a593Smuzhiyun
alc650_swap_surround_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2524*4882a593Smuzhiyun static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol,
2525*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
2526*4882a593Smuzhiyun {
2527*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2528*4882a593Smuzhiyun struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK];
2529*4882a593Smuzhiyun
2530*4882a593Smuzhiyun if (map) {
2531*4882a593Smuzhiyun if (ucontrol->value.integer.value[0])
2532*4882a593Smuzhiyun map->chmap = snd_pcm_std_chmaps;
2533*4882a593Smuzhiyun else
2534*4882a593Smuzhiyun map->chmap = snd_pcm_alt_chmaps;
2535*4882a593Smuzhiyun }
2536*4882a593Smuzhiyun return snd_ac97_put_volsw(kcontrol, ucontrol);
2537*4882a593Smuzhiyun }
2538*4882a593Smuzhiyun
2539*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
2540*4882a593Smuzhiyun AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2541*4882a593Smuzhiyun AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2542*4882a593Smuzhiyun AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2543*4882a593Smuzhiyun AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2544*4882a593Smuzhiyun /* 4: Analog Input To Surround */
2545*4882a593Smuzhiyun /* 5: Analog Input To Center/LFE */
2546*4882a593Smuzhiyun /* 6: Independent Master Volume Right */
2547*4882a593Smuzhiyun /* 7: Independent Master Volume Left */
2548*4882a593Smuzhiyun /* 8: reserved */
2549*4882a593Smuzhiyun /* 9: Line-In/Surround share */
2550*4882a593Smuzhiyun /* 10: Mic/CLFE share */
2551*4882a593Smuzhiyun /* 11-13: in IEC958 controls */
2552*4882a593Smuzhiyun {
2553*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2554*4882a593Smuzhiyun .name = "Swap Surround Slot",
2555*4882a593Smuzhiyun .info = snd_ac97_info_volsw,
2556*4882a593Smuzhiyun .get = snd_ac97_get_volsw,
2557*4882a593Smuzhiyun .put = alc650_swap_surround_put,
2558*4882a593Smuzhiyun .private_value = AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0),
2559*4882a593Smuzhiyun },
2560*4882a593Smuzhiyun #if 0 /* always set in patch_alc650 */
2561*4882a593Smuzhiyun AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2562*4882a593Smuzhiyun AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2563*4882a593Smuzhiyun AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2564*4882a593Smuzhiyun AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2565*4882a593Smuzhiyun AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2566*4882a593Smuzhiyun AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2567*4882a593Smuzhiyun #endif
2568*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2569*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
2570*4882a593Smuzhiyun };
2571*4882a593Smuzhiyun
2572*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
2573*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
2574*4882a593Smuzhiyun AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2575*4882a593Smuzhiyun /* disable this controls since it doesn't work as expected */
2576*4882a593Smuzhiyun /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2577*4882a593Smuzhiyun };
2578*4882a593Smuzhiyun
2579*4882a593Smuzhiyun static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
2580*4882a593Smuzhiyun
patch_alc650_specific(struct snd_ac97 * ac97)2581*4882a593Smuzhiyun static int patch_alc650_specific(struct snd_ac97 * ac97)
2582*4882a593Smuzhiyun {
2583*4882a593Smuzhiyun int err;
2584*4882a593Smuzhiyun
2585*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2586*4882a593Smuzhiyun return err;
2587*4882a593Smuzhiyun if (ac97->ext_id & AC97_EI_SPDIF) {
2588*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2589*4882a593Smuzhiyun return err;
2590*4882a593Smuzhiyun }
2591*4882a593Smuzhiyun if (ac97->id != AC97_ID_ALC650F)
2592*4882a593Smuzhiyun reset_tlv(ac97, "Master Playback Volume",
2593*4882a593Smuzhiyun db_scale_5bit_3db_max);
2594*4882a593Smuzhiyun return 0;
2595*4882a593Smuzhiyun }
2596*4882a593Smuzhiyun
2597*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_alc650_ops = {
2598*4882a593Smuzhiyun .build_specific = patch_alc650_specific,
2599*4882a593Smuzhiyun .update_jacks = alc650_update_jacks
2600*4882a593Smuzhiyun };
2601*4882a593Smuzhiyun
patch_alc650(struct snd_ac97 * ac97)2602*4882a593Smuzhiyun static int patch_alc650(struct snd_ac97 * ac97)
2603*4882a593Smuzhiyun {
2604*4882a593Smuzhiyun unsigned short val;
2605*4882a593Smuzhiyun
2606*4882a593Smuzhiyun ac97->build_ops = &patch_alc650_ops;
2607*4882a593Smuzhiyun
2608*4882a593Smuzhiyun /* determine the revision */
2609*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2610*4882a593Smuzhiyun if (val < 3)
2611*4882a593Smuzhiyun ac97->id = 0x414c4720; /* Old version */
2612*4882a593Smuzhiyun else if (val < 0x10)
2613*4882a593Smuzhiyun ac97->id = 0x414c4721; /* D version */
2614*4882a593Smuzhiyun else if (val < 0x20)
2615*4882a593Smuzhiyun ac97->id = 0x414c4722; /* E version */
2616*4882a593Smuzhiyun else if (val < 0x30)
2617*4882a593Smuzhiyun ac97->id = 0x414c4723; /* F version */
2618*4882a593Smuzhiyun
2619*4882a593Smuzhiyun /* revision E or F */
2620*4882a593Smuzhiyun /* FIXME: what about revision D ? */
2621*4882a593Smuzhiyun ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2622*4882a593Smuzhiyun ac97->id == 0x414c4723);
2623*4882a593Smuzhiyun
2624*4882a593Smuzhiyun /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2625*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2626*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2627*4882a593Smuzhiyun
2628*4882a593Smuzhiyun /* Enable SPDIF-IN only on Rev.E and above */
2629*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2630*4882a593Smuzhiyun /* SPDIF IN with pin 47 */
2631*4882a593Smuzhiyun if (ac97->spec.dev_flags &&
2632*4882a593Smuzhiyun /* ASUS A6KM requires EAPD */
2633*4882a593Smuzhiyun ! (ac97->subsystem_vendor == 0x1043 &&
2634*4882a593Smuzhiyun ac97->subsystem_device == 0x1103))
2635*4882a593Smuzhiyun val |= 0x03; /* enable */
2636*4882a593Smuzhiyun else
2637*4882a593Smuzhiyun val &= ~0x03; /* disable */
2638*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2639*4882a593Smuzhiyun
2640*4882a593Smuzhiyun /* set default: slot 3,4,7,8,6,9
2641*4882a593Smuzhiyun spdif-in monitor off, analog-spdif off, spdif-in off
2642*4882a593Smuzhiyun center on mic off, surround on line-in off
2643*4882a593Smuzhiyun downmix off, duplicate front off
2644*4882a593Smuzhiyun */
2645*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun /* set GPIO0 for mic bias */
2648*4882a593Smuzhiyun /* GPIO0 pin output, no interrupt, high */
2649*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2650*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2651*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2652*4882a593Smuzhiyun (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2653*4882a593Smuzhiyun
2654*4882a593Smuzhiyun /* full DAC volume */
2655*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2656*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2657*4882a593Smuzhiyun return 0;
2658*4882a593Smuzhiyun }
2659*4882a593Smuzhiyun
alc655_update_jacks(struct snd_ac97 * ac97)2660*4882a593Smuzhiyun static void alc655_update_jacks(struct snd_ac97 *ac97)
2661*4882a593Smuzhiyun {
2662*4882a593Smuzhiyun int shared;
2663*4882a593Smuzhiyun
2664*4882a593Smuzhiyun /* shared Line-In / Surround Out */
2665*4882a593Smuzhiyun shared = is_shared_surrout(ac97);
2666*4882a593Smuzhiyun ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2667*4882a593Smuzhiyun shared ? (1 << 9) : 0, 0);
2668*4882a593Smuzhiyun /* update shared Mic In / Center/LFE Out */
2669*4882a593Smuzhiyun shared = is_shared_clfeout(ac97);
2670*4882a593Smuzhiyun /* misc control; vrefout disable */
2671*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2672*4882a593Smuzhiyun shared ? (1 << 12) : 0);
2673*4882a593Smuzhiyun ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2674*4882a593Smuzhiyun shared ? (1 << 10) : 0, 0);
2675*4882a593Smuzhiyun }
2676*4882a593Smuzhiyun
2677*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
2678*4882a593Smuzhiyun AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2679*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2680*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
2681*4882a593Smuzhiyun };
2682*4882a593Smuzhiyun
alc655_iec958_route_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)2683*4882a593Smuzhiyun static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2684*4882a593Smuzhiyun {
2685*4882a593Smuzhiyun static const char * const texts_655[3] = {
2686*4882a593Smuzhiyun "PCM", "Analog In", "IEC958 In"
2687*4882a593Smuzhiyun };
2688*4882a593Smuzhiyun static const char * const texts_658[4] = {
2689*4882a593Smuzhiyun "PCM", "Analog1 In", "Analog2 In", "IEC958 In"
2690*4882a593Smuzhiyun };
2691*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2692*4882a593Smuzhiyun
2693*4882a593Smuzhiyun if (ac97->spec.dev_flags)
2694*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
2695*4882a593Smuzhiyun else
2696*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
2697*4882a593Smuzhiyun }
2698*4882a593Smuzhiyun
alc655_iec958_route_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2699*4882a593Smuzhiyun static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2700*4882a593Smuzhiyun {
2701*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2702*4882a593Smuzhiyun unsigned short val;
2703*4882a593Smuzhiyun
2704*4882a593Smuzhiyun val = ac97->regs[AC97_ALC650_MULTICH];
2705*4882a593Smuzhiyun val = (val >> 12) & 3;
2706*4882a593Smuzhiyun if (ac97->spec.dev_flags && val == 3)
2707*4882a593Smuzhiyun val = 0;
2708*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = val;
2709*4882a593Smuzhiyun return 0;
2710*4882a593Smuzhiyun }
2711*4882a593Smuzhiyun
alc655_iec958_route_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2712*4882a593Smuzhiyun static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2713*4882a593Smuzhiyun {
2714*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2715*4882a593Smuzhiyun
2716*4882a593Smuzhiyun return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2717*4882a593Smuzhiyun (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2718*4882a593Smuzhiyun 0);
2719*4882a593Smuzhiyun }
2720*4882a593Smuzhiyun
2721*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
2722*4882a593Smuzhiyun AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
2723*4882a593Smuzhiyun /* disable this controls since it doesn't work as expected */
2724*4882a593Smuzhiyun /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2725*4882a593Smuzhiyun {
2726*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2727*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2728*4882a593Smuzhiyun .info = alc655_iec958_route_info,
2729*4882a593Smuzhiyun .get = alc655_iec958_route_get,
2730*4882a593Smuzhiyun .put = alc655_iec958_route_put,
2731*4882a593Smuzhiyun },
2732*4882a593Smuzhiyun };
2733*4882a593Smuzhiyun
patch_alc655_specific(struct snd_ac97 * ac97)2734*4882a593Smuzhiyun static int patch_alc655_specific(struct snd_ac97 * ac97)
2735*4882a593Smuzhiyun {
2736*4882a593Smuzhiyun int err;
2737*4882a593Smuzhiyun
2738*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2739*4882a593Smuzhiyun return err;
2740*4882a593Smuzhiyun if (ac97->ext_id & AC97_EI_SPDIF) {
2741*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2742*4882a593Smuzhiyun return err;
2743*4882a593Smuzhiyun }
2744*4882a593Smuzhiyun return 0;
2745*4882a593Smuzhiyun }
2746*4882a593Smuzhiyun
2747*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_alc655_ops = {
2748*4882a593Smuzhiyun .build_specific = patch_alc655_specific,
2749*4882a593Smuzhiyun .update_jacks = alc655_update_jacks
2750*4882a593Smuzhiyun };
2751*4882a593Smuzhiyun
patch_alc655(struct snd_ac97 * ac97)2752*4882a593Smuzhiyun static int patch_alc655(struct snd_ac97 * ac97)
2753*4882a593Smuzhiyun {
2754*4882a593Smuzhiyun unsigned int val;
2755*4882a593Smuzhiyun
2756*4882a593Smuzhiyun if (ac97->id == AC97_ID_ALC658) {
2757*4882a593Smuzhiyun ac97->spec.dev_flags = 1; /* ALC658 */
2758*4882a593Smuzhiyun if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2759*4882a593Smuzhiyun ac97->id = AC97_ID_ALC658D;
2760*4882a593Smuzhiyun ac97->spec.dev_flags = 2;
2761*4882a593Smuzhiyun }
2762*4882a593Smuzhiyun }
2763*4882a593Smuzhiyun
2764*4882a593Smuzhiyun ac97->build_ops = &patch_alc655_ops;
2765*4882a593Smuzhiyun
2766*4882a593Smuzhiyun /* assume only page 0 for writing cache */
2767*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2768*4882a593Smuzhiyun
2769*4882a593Smuzhiyun /* adjust default values */
2770*4882a593Smuzhiyun val = snd_ac97_read(ac97, 0x7a); /* misc control */
2771*4882a593Smuzhiyun if (ac97->spec.dev_flags) /* ALC658 */
2772*4882a593Smuzhiyun val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2773*4882a593Smuzhiyun else { /* ALC655 */
2774*4882a593Smuzhiyun if (ac97->subsystem_vendor == 0x1462 &&
2775*4882a593Smuzhiyun (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2776*4882a593Smuzhiyun ac97->subsystem_device == 0x0161 || /* LG K1 Express */
2777*4882a593Smuzhiyun ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
2778*4882a593Smuzhiyun ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
2779*4882a593Smuzhiyun ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
2780*4882a593Smuzhiyun val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2781*4882a593Smuzhiyun else
2782*4882a593Smuzhiyun val |= (1 << 1); /* Pin 47 is spdif input pin */
2783*4882a593Smuzhiyun /* this seems missing on some hardwares */
2784*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF;
2785*4882a593Smuzhiyun }
2786*4882a593Smuzhiyun val &= ~(1 << 12); /* vref enable */
2787*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x7a, val);
2788*4882a593Smuzhiyun /* set default: spdif-in enabled,
2789*4882a593Smuzhiyun spdif-in monitor off, spdif-in PCM off
2790*4882a593Smuzhiyun center on mic off, surround on line-in off
2791*4882a593Smuzhiyun duplicate front off
2792*4882a593Smuzhiyun */
2793*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2794*4882a593Smuzhiyun
2795*4882a593Smuzhiyun /* full DAC volume */
2796*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2797*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2798*4882a593Smuzhiyun
2799*4882a593Smuzhiyun /* update undocumented bit... */
2800*4882a593Smuzhiyun if (ac97->id == AC97_ID_ALC658D)
2801*4882a593Smuzhiyun snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2802*4882a593Smuzhiyun
2803*4882a593Smuzhiyun return 0;
2804*4882a593Smuzhiyun }
2805*4882a593Smuzhiyun
2806*4882a593Smuzhiyun
2807*4882a593Smuzhiyun #define AC97_ALC850_JACK_SELECT 0x76
2808*4882a593Smuzhiyun #define AC97_ALC850_MISC1 0x7a
2809*4882a593Smuzhiyun #define AC97_ALC850_MULTICH 0x6a
2810*4882a593Smuzhiyun
alc850_update_jacks(struct snd_ac97 * ac97)2811*4882a593Smuzhiyun static void alc850_update_jacks(struct snd_ac97 *ac97)
2812*4882a593Smuzhiyun {
2813*4882a593Smuzhiyun int shared;
2814*4882a593Smuzhiyun int aux_is_back_surround;
2815*4882a593Smuzhiyun
2816*4882a593Smuzhiyun /* shared Line-In / Surround Out */
2817*4882a593Smuzhiyun shared = is_shared_surrout(ac97);
2818*4882a593Smuzhiyun /* SURR 1kOhm (bit4), Amp (bit5) */
2819*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2820*4882a593Smuzhiyun shared ? (1<<5) : (1<<4));
2821*4882a593Smuzhiyun /* LINE-IN = 0, SURROUND = 2 */
2822*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2823*4882a593Smuzhiyun shared ? (2<<12) : (0<<12));
2824*4882a593Smuzhiyun /* update shared Mic In / Center/LFE Out */
2825*4882a593Smuzhiyun shared = is_shared_clfeout(ac97);
2826*4882a593Smuzhiyun /* Vref disable (bit12), 1kOhm (bit13) */
2827*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2828*4882a593Smuzhiyun shared ? (1<<12) : (1<<13));
2829*4882a593Smuzhiyun /* MIC-IN = 1, CENTER-LFE = 5 */
2830*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2831*4882a593Smuzhiyun shared ? (5<<4) : (1<<4));
2832*4882a593Smuzhiyun
2833*4882a593Smuzhiyun aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2834*4882a593Smuzhiyun /* Aux is Back Surround */
2835*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2836*4882a593Smuzhiyun aux_is_back_surround ? (1<<10) : (0<<10));
2837*4882a593Smuzhiyun }
2838*4882a593Smuzhiyun
2839*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2840*4882a593Smuzhiyun AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2841*4882a593Smuzhiyun AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2842*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2843*4882a593Smuzhiyun AC97_CHANNEL_MODE_8CH_CTL,
2844*4882a593Smuzhiyun };
2845*4882a593Smuzhiyun
patch_alc850_specific(struct snd_ac97 * ac97)2846*4882a593Smuzhiyun static int patch_alc850_specific(struct snd_ac97 *ac97)
2847*4882a593Smuzhiyun {
2848*4882a593Smuzhiyun int err;
2849*4882a593Smuzhiyun
2850*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2851*4882a593Smuzhiyun return err;
2852*4882a593Smuzhiyun if (ac97->ext_id & AC97_EI_SPDIF) {
2853*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2854*4882a593Smuzhiyun return err;
2855*4882a593Smuzhiyun }
2856*4882a593Smuzhiyun return 0;
2857*4882a593Smuzhiyun }
2858*4882a593Smuzhiyun
2859*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_alc850_ops = {
2860*4882a593Smuzhiyun .build_specific = patch_alc850_specific,
2861*4882a593Smuzhiyun .update_jacks = alc850_update_jacks
2862*4882a593Smuzhiyun };
2863*4882a593Smuzhiyun
patch_alc850(struct snd_ac97 * ac97)2864*4882a593Smuzhiyun static int patch_alc850(struct snd_ac97 *ac97)
2865*4882a593Smuzhiyun {
2866*4882a593Smuzhiyun ac97->build_ops = &patch_alc850_ops;
2867*4882a593Smuzhiyun
2868*4882a593Smuzhiyun ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2869*4882a593Smuzhiyun ac97->flags |= AC97_HAS_8CH;
2870*4882a593Smuzhiyun
2871*4882a593Smuzhiyun /* assume only page 0 for writing cache */
2872*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2873*4882a593Smuzhiyun
2874*4882a593Smuzhiyun /* adjust default values */
2875*4882a593Smuzhiyun /* set default: spdif-in enabled,
2876*4882a593Smuzhiyun spdif-in monitor off, spdif-in PCM off
2877*4882a593Smuzhiyun center on mic off, surround on line-in off
2878*4882a593Smuzhiyun duplicate front off
2879*4882a593Smuzhiyun NB default bit 10=0 = Aux is Capture, not Back Surround
2880*4882a593Smuzhiyun */
2881*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2882*4882a593Smuzhiyun /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2883*4882a593Smuzhiyun * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2884*4882a593Smuzhiyun */
2885*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2886*4882a593Smuzhiyun (1<<7)|(0<<12)|(1<<13)|(0<<14));
2887*4882a593Smuzhiyun /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2888*4882a593Smuzhiyun * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2889*4882a593Smuzhiyun */
2890*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2891*4882a593Smuzhiyun (1<<11)|(0<<12)|(1<<15));
2892*4882a593Smuzhiyun
2893*4882a593Smuzhiyun /* full DAC volume */
2894*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2895*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2896*4882a593Smuzhiyun return 0;
2897*4882a593Smuzhiyun }
2898*4882a593Smuzhiyun
patch_aztech_azf3328_specific(struct snd_ac97 * ac97)2899*4882a593Smuzhiyun static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97)
2900*4882a593Smuzhiyun {
2901*4882a593Smuzhiyun struct snd_kcontrol *kctl_3d_center =
2902*4882a593Smuzhiyun snd_ac97_find_mixer_ctl(ac97, "3D Control - Center");
2903*4882a593Smuzhiyun struct snd_kcontrol *kctl_3d_depth =
2904*4882a593Smuzhiyun snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth");
2905*4882a593Smuzhiyun
2906*4882a593Smuzhiyun /*
2907*4882a593Smuzhiyun * 3D register is different from AC97 standard layout
2908*4882a593Smuzhiyun * (also do some renaming, to resemble Windows driver naming)
2909*4882a593Smuzhiyun */
2910*4882a593Smuzhiyun if (kctl_3d_center) {
2911*4882a593Smuzhiyun kctl_3d_center->private_value =
2912*4882a593Smuzhiyun AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0);
2913*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97,
2914*4882a593Smuzhiyun "3D Control - Center", "3D Control - Width"
2915*4882a593Smuzhiyun );
2916*4882a593Smuzhiyun }
2917*4882a593Smuzhiyun if (kctl_3d_depth)
2918*4882a593Smuzhiyun kctl_3d_depth->private_value =
2919*4882a593Smuzhiyun AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0);
2920*4882a593Smuzhiyun
2921*4882a593Smuzhiyun /* Aztech Windows driver calls the
2922*4882a593Smuzhiyun equivalent control "Modem Playback", thus rename it: */
2923*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97,
2924*4882a593Smuzhiyun "Master Mono Playback", "Modem Playback"
2925*4882a593Smuzhiyun );
2926*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97,
2927*4882a593Smuzhiyun "Headphone Playback", "FM Synth Playback"
2928*4882a593Smuzhiyun );
2929*4882a593Smuzhiyun
2930*4882a593Smuzhiyun return 0;
2931*4882a593Smuzhiyun }
2932*4882a593Smuzhiyun
2933*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = {
2934*4882a593Smuzhiyun .build_specific = patch_aztech_azf3328_specific
2935*4882a593Smuzhiyun };
2936*4882a593Smuzhiyun
patch_aztech_azf3328(struct snd_ac97 * ac97)2937*4882a593Smuzhiyun static int patch_aztech_azf3328(struct snd_ac97 *ac97)
2938*4882a593Smuzhiyun {
2939*4882a593Smuzhiyun ac97->build_ops = &patch_aztech_azf3328_ops;
2940*4882a593Smuzhiyun return 0;
2941*4882a593Smuzhiyun }
2942*4882a593Smuzhiyun
2943*4882a593Smuzhiyun /*
2944*4882a593Smuzhiyun * C-Media CM97xx codecs
2945*4882a593Smuzhiyun */
cm9738_update_jacks(struct snd_ac97 * ac97)2946*4882a593Smuzhiyun static void cm9738_update_jacks(struct snd_ac97 *ac97)
2947*4882a593Smuzhiyun {
2948*4882a593Smuzhiyun /* shared Line-In / Surround Out */
2949*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2950*4882a593Smuzhiyun is_shared_surrout(ac97) ? (1 << 10) : 0);
2951*4882a593Smuzhiyun }
2952*4882a593Smuzhiyun
2953*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
2954*4882a593Smuzhiyun AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2955*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
2956*4882a593Smuzhiyun AC97_CHANNEL_MODE_4CH_CTL,
2957*4882a593Smuzhiyun };
2958*4882a593Smuzhiyun
patch_cm9738_specific(struct snd_ac97 * ac97)2959*4882a593Smuzhiyun static int patch_cm9738_specific(struct snd_ac97 * ac97)
2960*4882a593Smuzhiyun {
2961*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2962*4882a593Smuzhiyun }
2963*4882a593Smuzhiyun
2964*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_cm9738_ops = {
2965*4882a593Smuzhiyun .build_specific = patch_cm9738_specific,
2966*4882a593Smuzhiyun .update_jacks = cm9738_update_jacks
2967*4882a593Smuzhiyun };
2968*4882a593Smuzhiyun
patch_cm9738(struct snd_ac97 * ac97)2969*4882a593Smuzhiyun static int patch_cm9738(struct snd_ac97 * ac97)
2970*4882a593Smuzhiyun {
2971*4882a593Smuzhiyun ac97->build_ops = &patch_cm9738_ops;
2972*4882a593Smuzhiyun /* FIXME: can anyone confirm below? */
2973*4882a593Smuzhiyun /* CM9738 has no PCM volume although the register reacts */
2974*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_PCM_VOL;
2975*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2976*4882a593Smuzhiyun
2977*4882a593Smuzhiyun return 0;
2978*4882a593Smuzhiyun }
2979*4882a593Smuzhiyun
snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)2980*4882a593Smuzhiyun static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2981*4882a593Smuzhiyun {
2982*4882a593Smuzhiyun static const char * const texts[] = { "Analog", "Digital" };
2983*4882a593Smuzhiyun
2984*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 2, texts);
2985*4882a593Smuzhiyun }
2986*4882a593Smuzhiyun
snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2987*4882a593Smuzhiyun static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2988*4882a593Smuzhiyun {
2989*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2990*4882a593Smuzhiyun unsigned short val;
2991*4882a593Smuzhiyun
2992*4882a593Smuzhiyun val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2993*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2994*4882a593Smuzhiyun return 0;
2995*4882a593Smuzhiyun }
2996*4882a593Smuzhiyun
snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)2997*4882a593Smuzhiyun static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2998*4882a593Smuzhiyun {
2999*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3000*4882a593Smuzhiyun
3001*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
3002*4882a593Smuzhiyun 0x01 << 1,
3003*4882a593Smuzhiyun (ucontrol->value.enumerated.item[0] & 0x01) << 1);
3004*4882a593Smuzhiyun }
3005*4882a593Smuzhiyun
3006*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
3007*4882a593Smuzhiyun /* BIT 0: SPDI_EN - always true */
3008*4882a593Smuzhiyun { /* BIT 1: SPDIFS */
3009*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3010*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3011*4882a593Smuzhiyun .info = snd_ac97_cmedia_spdif_playback_source_info,
3012*4882a593Smuzhiyun .get = snd_ac97_cmedia_spdif_playback_source_get,
3013*4882a593Smuzhiyun .put = snd_ac97_cmedia_spdif_playback_source_put,
3014*4882a593Smuzhiyun },
3015*4882a593Smuzhiyun /* BIT 2: IG_SPIV */
3016*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
3017*4882a593Smuzhiyun /* BIT 3: SPI2F */
3018*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
3019*4882a593Smuzhiyun /* BIT 4: SPI2SDI */
3020*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
3021*4882a593Smuzhiyun /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
3022*4882a593Smuzhiyun };
3023*4882a593Smuzhiyun
cm9739_update_jacks(struct snd_ac97 * ac97)3024*4882a593Smuzhiyun static void cm9739_update_jacks(struct snd_ac97 *ac97)
3025*4882a593Smuzhiyun {
3026*4882a593Smuzhiyun /* shared Line-In / Surround Out */
3027*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
3028*4882a593Smuzhiyun is_shared_surrout(ac97) ? (1 << 10) : 0);
3029*4882a593Smuzhiyun /* shared Mic In / Center/LFE Out **/
3030*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
3031*4882a593Smuzhiyun is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
3032*4882a593Smuzhiyun }
3033*4882a593Smuzhiyun
3034*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
3035*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
3036*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
3037*4882a593Smuzhiyun };
3038*4882a593Smuzhiyun
patch_cm9739_specific(struct snd_ac97 * ac97)3039*4882a593Smuzhiyun static int patch_cm9739_specific(struct snd_ac97 * ac97)
3040*4882a593Smuzhiyun {
3041*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
3042*4882a593Smuzhiyun }
3043*4882a593Smuzhiyun
patch_cm9739_post_spdif(struct snd_ac97 * ac97)3044*4882a593Smuzhiyun static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
3045*4882a593Smuzhiyun {
3046*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
3047*4882a593Smuzhiyun }
3048*4882a593Smuzhiyun
3049*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_cm9739_ops = {
3050*4882a593Smuzhiyun .build_specific = patch_cm9739_specific,
3051*4882a593Smuzhiyun .build_post_spdif = patch_cm9739_post_spdif,
3052*4882a593Smuzhiyun .update_jacks = cm9739_update_jacks
3053*4882a593Smuzhiyun };
3054*4882a593Smuzhiyun
patch_cm9739(struct snd_ac97 * ac97)3055*4882a593Smuzhiyun static int patch_cm9739(struct snd_ac97 * ac97)
3056*4882a593Smuzhiyun {
3057*4882a593Smuzhiyun unsigned short val;
3058*4882a593Smuzhiyun
3059*4882a593Smuzhiyun ac97->build_ops = &patch_cm9739_ops;
3060*4882a593Smuzhiyun
3061*4882a593Smuzhiyun /* CM9739/A has no Master and PCM volume although the register reacts */
3062*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
3063*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
3064*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
3065*4882a593Smuzhiyun
3066*4882a593Smuzhiyun /* check spdif */
3067*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
3068*4882a593Smuzhiyun if (val & AC97_EA_SPCV) {
3069*4882a593Smuzhiyun /* enable spdif in */
3070*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3071*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
3072*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3073*4882a593Smuzhiyun } else {
3074*4882a593Smuzhiyun ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
3075*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = 0;
3076*4882a593Smuzhiyun }
3077*4882a593Smuzhiyun
3078*4882a593Smuzhiyun /* set-up multi channel */
3079*4882a593Smuzhiyun /* bit 14: 0 = SPDIF, 1 = EAPD */
3080*4882a593Smuzhiyun /* bit 13: enable internal vref output for mic */
3081*4882a593Smuzhiyun /* bit 12: disable center/lfe (switchable) */
3082*4882a593Smuzhiyun /* bit 10: disable surround/line (switchable) */
3083*4882a593Smuzhiyun /* bit 9: mix 2 surround off */
3084*4882a593Smuzhiyun /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
3085*4882a593Smuzhiyun /* bit 3: undocumented; surround? */
3086*4882a593Smuzhiyun /* bit 0: dB */
3087*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
3088*4882a593Smuzhiyun val |= (1 << 3);
3089*4882a593Smuzhiyun val |= (1 << 13);
3090*4882a593Smuzhiyun if (! (ac97->ext_id & AC97_EI_SPDIF))
3091*4882a593Smuzhiyun val |= (1 << 14);
3092*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
3093*4882a593Smuzhiyun
3094*4882a593Smuzhiyun /* FIXME: set up GPIO */
3095*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x70, 0x0100);
3096*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x72, 0x0020);
3097*4882a593Smuzhiyun /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3098*4882a593Smuzhiyun if (ac97->pci &&
3099*4882a593Smuzhiyun ac97->subsystem_vendor == 0x1043 &&
3100*4882a593Smuzhiyun ac97->subsystem_device == 0x1843) {
3101*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3102*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
3103*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
3104*4882a593Smuzhiyun snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
3105*4882a593Smuzhiyun }
3106*4882a593Smuzhiyun
3107*4882a593Smuzhiyun return 0;
3108*4882a593Smuzhiyun }
3109*4882a593Smuzhiyun
3110*4882a593Smuzhiyun #define AC97_CM9761_MULTI_CHAN 0x64
3111*4882a593Smuzhiyun #define AC97_CM9761_FUNC 0x66
3112*4882a593Smuzhiyun #define AC97_CM9761_SPDIF_CTRL 0x6c
3113*4882a593Smuzhiyun
cm9761_update_jacks(struct snd_ac97 * ac97)3114*4882a593Smuzhiyun static void cm9761_update_jacks(struct snd_ac97 *ac97)
3115*4882a593Smuzhiyun {
3116*4882a593Smuzhiyun /* FIXME: check the bits for each model
3117*4882a593Smuzhiyun * model 83 is confirmed to work
3118*4882a593Smuzhiyun */
3119*4882a593Smuzhiyun static const unsigned short surr_on[3][2] = {
3120*4882a593Smuzhiyun { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3121*4882a593Smuzhiyun { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3122*4882a593Smuzhiyun { 0x0000, 0x0008 }, /* 9761-83 */
3123*4882a593Smuzhiyun };
3124*4882a593Smuzhiyun static const unsigned short clfe_on[3][2] = {
3125*4882a593Smuzhiyun { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3126*4882a593Smuzhiyun { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3127*4882a593Smuzhiyun { 0x0000, 0x1000 }, /* 9761-83 */
3128*4882a593Smuzhiyun };
3129*4882a593Smuzhiyun static const unsigned short surr_shared[3][2] = {
3130*4882a593Smuzhiyun { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3131*4882a593Smuzhiyun { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3132*4882a593Smuzhiyun { 0x0000, 0x0400 }, /* 9761-83 */
3133*4882a593Smuzhiyun };
3134*4882a593Smuzhiyun static const unsigned short clfe_shared[3][2] = {
3135*4882a593Smuzhiyun { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3136*4882a593Smuzhiyun { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3137*4882a593Smuzhiyun { 0x2000, 0x0800 }, /* 9761-83 */
3138*4882a593Smuzhiyun };
3139*4882a593Smuzhiyun unsigned short val = 0;
3140*4882a593Smuzhiyun
3141*4882a593Smuzhiyun val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
3142*4882a593Smuzhiyun val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
3143*4882a593Smuzhiyun val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3144*4882a593Smuzhiyun val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
3145*4882a593Smuzhiyun
3146*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
3147*4882a593Smuzhiyun }
3148*4882a593Smuzhiyun
3149*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
3150*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
3151*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
3152*4882a593Smuzhiyun };
3153*4882a593Smuzhiyun
cm9761_spdif_out_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3154*4882a593Smuzhiyun static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3155*4882a593Smuzhiyun {
3156*4882a593Smuzhiyun static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
3157*4882a593Smuzhiyun
3158*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 3, texts);
3159*4882a593Smuzhiyun }
3160*4882a593Smuzhiyun
cm9761_spdif_out_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3161*4882a593Smuzhiyun static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3162*4882a593Smuzhiyun {
3163*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3164*4882a593Smuzhiyun
3165*4882a593Smuzhiyun if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
3166*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
3167*4882a593Smuzhiyun else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
3168*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
3169*4882a593Smuzhiyun else
3170*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = 0; /* AC-link */
3171*4882a593Smuzhiyun return 0;
3172*4882a593Smuzhiyun }
3173*4882a593Smuzhiyun
cm9761_spdif_out_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3174*4882a593Smuzhiyun static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3175*4882a593Smuzhiyun {
3176*4882a593Smuzhiyun struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3177*4882a593Smuzhiyun
3178*4882a593Smuzhiyun if (ucontrol->value.enumerated.item[0] == 2)
3179*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
3180*4882a593Smuzhiyun snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
3181*4882a593Smuzhiyun return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
3182*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3183*4882a593Smuzhiyun }
3184*4882a593Smuzhiyun
3185*4882a593Smuzhiyun static const char * const cm9761_dac_clock[] = {
3186*4882a593Smuzhiyun "AC-Link", "SPDIF-In", "Both"
3187*4882a593Smuzhiyun };
3188*4882a593Smuzhiyun static const struct ac97_enum cm9761_dac_clock_enum =
3189*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3190*4882a593Smuzhiyun
3191*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
3192*4882a593Smuzhiyun { /* BIT 1: SPDIFS */
3193*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3194*4882a593Smuzhiyun .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3195*4882a593Smuzhiyun .info = cm9761_spdif_out_source_info,
3196*4882a593Smuzhiyun .get = cm9761_spdif_out_source_get,
3197*4882a593Smuzhiyun .put = cm9761_spdif_out_source_put,
3198*4882a593Smuzhiyun },
3199*4882a593Smuzhiyun /* BIT 2: IG_SPIV */
3200*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
3201*4882a593Smuzhiyun /* BIT 3: SPI2F */
3202*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
3203*4882a593Smuzhiyun /* BIT 4: SPI2SDI */
3204*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
3205*4882a593Smuzhiyun /* BIT 9-10: DAC_CTL */
3206*4882a593Smuzhiyun AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
3207*4882a593Smuzhiyun };
3208*4882a593Smuzhiyun
patch_cm9761_post_spdif(struct snd_ac97 * ac97)3209*4882a593Smuzhiyun static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
3210*4882a593Smuzhiyun {
3211*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
3212*4882a593Smuzhiyun }
3213*4882a593Smuzhiyun
patch_cm9761_specific(struct snd_ac97 * ac97)3214*4882a593Smuzhiyun static int patch_cm9761_specific(struct snd_ac97 * ac97)
3215*4882a593Smuzhiyun {
3216*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
3217*4882a593Smuzhiyun }
3218*4882a593Smuzhiyun
3219*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_cm9761_ops = {
3220*4882a593Smuzhiyun .build_specific = patch_cm9761_specific,
3221*4882a593Smuzhiyun .build_post_spdif = patch_cm9761_post_spdif,
3222*4882a593Smuzhiyun .update_jacks = cm9761_update_jacks
3223*4882a593Smuzhiyun };
3224*4882a593Smuzhiyun
patch_cm9761(struct snd_ac97 * ac97)3225*4882a593Smuzhiyun static int patch_cm9761(struct snd_ac97 *ac97)
3226*4882a593Smuzhiyun {
3227*4882a593Smuzhiyun unsigned short val;
3228*4882a593Smuzhiyun
3229*4882a593Smuzhiyun /* CM9761 has no PCM volume although the register reacts */
3230*4882a593Smuzhiyun /* Master volume seems to have _some_ influence on the analog
3231*4882a593Smuzhiyun * input sounds
3232*4882a593Smuzhiyun */
3233*4882a593Smuzhiyun ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
3234*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
3235*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
3236*4882a593Smuzhiyun
3237*4882a593Smuzhiyun ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
3238*4882a593Smuzhiyun if (ac97->id == AC97_ID_CM9761_82) {
3239*4882a593Smuzhiyun unsigned short tmp;
3240*4882a593Smuzhiyun /* check page 1, reg 0x60 */
3241*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_INT_PAGING);
3242*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
3243*4882a593Smuzhiyun tmp = snd_ac97_read(ac97, 0x60);
3244*4882a593Smuzhiyun ac97->spec.dev_flags = tmp & 1; /* revision B? */
3245*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
3246*4882a593Smuzhiyun } else if (ac97->id == AC97_ID_CM9761_83)
3247*4882a593Smuzhiyun ac97->spec.dev_flags = 2;
3248*4882a593Smuzhiyun
3249*4882a593Smuzhiyun ac97->build_ops = &patch_cm9761_ops;
3250*4882a593Smuzhiyun
3251*4882a593Smuzhiyun /* enable spdif */
3252*4882a593Smuzhiyun /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3253*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF;
3254*4882a593Smuzhiyun /* to be sure: we overwrite the ext status bits */
3255*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
3256*4882a593Smuzhiyun /* Don't set 0x0200 here. This results in the silent analog output */
3257*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
3258*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3259*4882a593Smuzhiyun
3260*4882a593Smuzhiyun /* set-up multi channel */
3261*4882a593Smuzhiyun /* bit 15: pc master beep off
3262*4882a593Smuzhiyun * bit 14: pin47 = EAPD/SPDIF
3263*4882a593Smuzhiyun * bit 13: vref ctl [= cm9739]
3264*4882a593Smuzhiyun * bit 12: CLFE control (reverted on rev B)
3265*4882a593Smuzhiyun * bit 11: Mic/center share (reverted on rev B)
3266*4882a593Smuzhiyun * bit 10: suddound/line share
3267*4882a593Smuzhiyun * bit 9: Analog-in mix -> surround
3268*4882a593Smuzhiyun * bit 8: Analog-in mix -> CLFE
3269*4882a593Smuzhiyun * bit 7: Mic/LFE share (mic/center/lfe)
3270*4882a593Smuzhiyun * bit 5: vref select (9761A)
3271*4882a593Smuzhiyun * bit 4: front control
3272*4882a593Smuzhiyun * bit 3: surround control (revereted with rev B)
3273*4882a593Smuzhiyun * bit 2: front mic
3274*4882a593Smuzhiyun * bit 1: stereo mic
3275*4882a593Smuzhiyun * bit 0: mic boost level (0=20dB, 1=30dB)
3276*4882a593Smuzhiyun */
3277*4882a593Smuzhiyun
3278*4882a593Smuzhiyun #if 0
3279*4882a593Smuzhiyun if (ac97->spec.dev_flags)
3280*4882a593Smuzhiyun val = 0x0214;
3281*4882a593Smuzhiyun else
3282*4882a593Smuzhiyun val = 0x321c;
3283*4882a593Smuzhiyun #endif
3284*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
3285*4882a593Smuzhiyun val |= (1 << 4); /* front on */
3286*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
3287*4882a593Smuzhiyun
3288*4882a593Smuzhiyun /* FIXME: set up GPIO */
3289*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x70, 0x0100);
3290*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x72, 0x0020);
3291*4882a593Smuzhiyun
3292*4882a593Smuzhiyun return 0;
3293*4882a593Smuzhiyun }
3294*4882a593Smuzhiyun
3295*4882a593Smuzhiyun #define AC97_CM9780_SIDE 0x60
3296*4882a593Smuzhiyun #define AC97_CM9780_JACK 0x62
3297*4882a593Smuzhiyun #define AC97_CM9780_MIXER 0x64
3298*4882a593Smuzhiyun #define AC97_CM9780_MULTI_CHAN 0x66
3299*4882a593Smuzhiyun #define AC97_CM9780_SPDIF 0x6c
3300*4882a593Smuzhiyun
3301*4882a593Smuzhiyun static const char * const cm9780_ch_select[] = {
3302*4882a593Smuzhiyun "Front", "Side", "Center/LFE", "Rear"
3303*4882a593Smuzhiyun };
3304*4882a593Smuzhiyun static const struct ac97_enum cm9780_ch_select_enum =
3305*4882a593Smuzhiyun AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
3306*4882a593Smuzhiyun static const struct snd_kcontrol_new cm9780_controls[] = {
3307*4882a593Smuzhiyun AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
3308*4882a593Smuzhiyun AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
3309*4882a593Smuzhiyun AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
3310*4882a593Smuzhiyun };
3311*4882a593Smuzhiyun
patch_cm9780_specific(struct snd_ac97 * ac97)3312*4882a593Smuzhiyun static int patch_cm9780_specific(struct snd_ac97 *ac97)
3313*4882a593Smuzhiyun {
3314*4882a593Smuzhiyun return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
3315*4882a593Smuzhiyun }
3316*4882a593Smuzhiyun
3317*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_cm9780_ops = {
3318*4882a593Smuzhiyun .build_specific = patch_cm9780_specific,
3319*4882a593Smuzhiyun .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
3320*4882a593Smuzhiyun };
3321*4882a593Smuzhiyun
patch_cm9780(struct snd_ac97 * ac97)3322*4882a593Smuzhiyun static int patch_cm9780(struct snd_ac97 *ac97)
3323*4882a593Smuzhiyun {
3324*4882a593Smuzhiyun unsigned short val;
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun ac97->build_ops = &patch_cm9780_ops;
3327*4882a593Smuzhiyun
3328*4882a593Smuzhiyun /* enable spdif */
3329*4882a593Smuzhiyun if (ac97->ext_id & AC97_EI_SPDIF) {
3330*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3331*4882a593Smuzhiyun val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
3332*4882a593Smuzhiyun val |= 0x1; /* SPDI_EN */
3333*4882a593Smuzhiyun snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
3334*4882a593Smuzhiyun }
3335*4882a593Smuzhiyun
3336*4882a593Smuzhiyun return 0;
3337*4882a593Smuzhiyun }
3338*4882a593Smuzhiyun
3339*4882a593Smuzhiyun /*
3340*4882a593Smuzhiyun * VIA VT1613 codec
3341*4882a593Smuzhiyun */
3342*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3343*4882a593Smuzhiyun AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3344*4882a593Smuzhiyun };
3345*4882a593Smuzhiyun
patch_vt1613_specific(struct snd_ac97 * ac97)3346*4882a593Smuzhiyun static int patch_vt1613_specific(struct snd_ac97 *ac97)
3347*4882a593Smuzhiyun {
3348*4882a593Smuzhiyun return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3349*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_controls_vt1613));
3350*4882a593Smuzhiyun };
3351*4882a593Smuzhiyun
3352*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_vt1613_ops = {
3353*4882a593Smuzhiyun .build_specific = patch_vt1613_specific
3354*4882a593Smuzhiyun };
3355*4882a593Smuzhiyun
patch_vt1613(struct snd_ac97 * ac97)3356*4882a593Smuzhiyun static int patch_vt1613(struct snd_ac97 *ac97)
3357*4882a593Smuzhiyun {
3358*4882a593Smuzhiyun ac97->build_ops = &patch_vt1613_ops;
3359*4882a593Smuzhiyun
3360*4882a593Smuzhiyun ac97->flags |= AC97_HAS_NO_VIDEO;
3361*4882a593Smuzhiyun ac97->caps |= AC97_BC_HEADPHONE;
3362*4882a593Smuzhiyun
3363*4882a593Smuzhiyun return 0;
3364*4882a593Smuzhiyun }
3365*4882a593Smuzhiyun
3366*4882a593Smuzhiyun /*
3367*4882a593Smuzhiyun * VIA VT1616 codec
3368*4882a593Smuzhiyun */
3369*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
3370*4882a593Smuzhiyun AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3371*4882a593Smuzhiyun AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3372*4882a593Smuzhiyun AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3373*4882a593Smuzhiyun AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3374*4882a593Smuzhiyun };
3375*4882a593Smuzhiyun
3376*4882a593Smuzhiyun static const char * const follower_vols_vt1616[] = {
3377*4882a593Smuzhiyun "Front Playback Volume",
3378*4882a593Smuzhiyun "Surround Playback Volume",
3379*4882a593Smuzhiyun "Center Playback Volume",
3380*4882a593Smuzhiyun "LFE Playback Volume",
3381*4882a593Smuzhiyun NULL
3382*4882a593Smuzhiyun };
3383*4882a593Smuzhiyun
3384*4882a593Smuzhiyun static const char * const follower_sws_vt1616[] = {
3385*4882a593Smuzhiyun "Front Playback Switch",
3386*4882a593Smuzhiyun "Surround Playback Switch",
3387*4882a593Smuzhiyun "Center Playback Switch",
3388*4882a593Smuzhiyun "LFE Playback Switch",
3389*4882a593Smuzhiyun NULL
3390*4882a593Smuzhiyun };
3391*4882a593Smuzhiyun
3392*4882a593Smuzhiyun /* find a mixer control element with the given name */
snd_ac97_find_mixer_ctl(struct snd_ac97 * ac97,const char * name)3393*4882a593Smuzhiyun static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
3394*4882a593Smuzhiyun const char *name)
3395*4882a593Smuzhiyun {
3396*4882a593Smuzhiyun struct snd_ctl_elem_id id;
3397*4882a593Smuzhiyun memset(&id, 0, sizeof(id));
3398*4882a593Smuzhiyun id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
3399*4882a593Smuzhiyun strcpy(id.name, name);
3400*4882a593Smuzhiyun return snd_ctl_find_id(ac97->bus->card, &id);
3401*4882a593Smuzhiyun }
3402*4882a593Smuzhiyun
3403*4882a593Smuzhiyun /* create a virtual master control and add followers */
snd_ac97_add_vmaster(struct snd_ac97 * ac97,char * name,const unsigned int * tlv,const char * const * followers)3404*4882a593Smuzhiyun static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
3405*4882a593Smuzhiyun const unsigned int *tlv,
3406*4882a593Smuzhiyun const char * const *followers)
3407*4882a593Smuzhiyun {
3408*4882a593Smuzhiyun struct snd_kcontrol *kctl;
3409*4882a593Smuzhiyun const char * const *s;
3410*4882a593Smuzhiyun int err;
3411*4882a593Smuzhiyun
3412*4882a593Smuzhiyun kctl = snd_ctl_make_virtual_master(name, tlv);
3413*4882a593Smuzhiyun if (!kctl)
3414*4882a593Smuzhiyun return -ENOMEM;
3415*4882a593Smuzhiyun err = snd_ctl_add(ac97->bus->card, kctl);
3416*4882a593Smuzhiyun if (err < 0)
3417*4882a593Smuzhiyun return err;
3418*4882a593Smuzhiyun
3419*4882a593Smuzhiyun for (s = followers; *s; s++) {
3420*4882a593Smuzhiyun struct snd_kcontrol *sctl;
3421*4882a593Smuzhiyun
3422*4882a593Smuzhiyun sctl = snd_ac97_find_mixer_ctl(ac97, *s);
3423*4882a593Smuzhiyun if (!sctl) {
3424*4882a593Smuzhiyun dev_dbg(ac97->bus->card->dev,
3425*4882a593Smuzhiyun "Cannot find follower %s, skipped\n", *s);
3426*4882a593Smuzhiyun continue;
3427*4882a593Smuzhiyun }
3428*4882a593Smuzhiyun err = snd_ctl_add_follower(kctl, sctl);
3429*4882a593Smuzhiyun if (err < 0)
3430*4882a593Smuzhiyun return err;
3431*4882a593Smuzhiyun }
3432*4882a593Smuzhiyun return 0;
3433*4882a593Smuzhiyun }
3434*4882a593Smuzhiyun
patch_vt1616_specific(struct snd_ac97 * ac97)3435*4882a593Smuzhiyun static int patch_vt1616_specific(struct snd_ac97 * ac97)
3436*4882a593Smuzhiyun {
3437*4882a593Smuzhiyun struct snd_kcontrol *kctl;
3438*4882a593Smuzhiyun int err;
3439*4882a593Smuzhiyun
3440*4882a593Smuzhiyun if (snd_ac97_try_bit(ac97, 0x5a, 9))
3441*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
3442*4882a593Smuzhiyun return err;
3443*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
3444*4882a593Smuzhiyun return err;
3445*4882a593Smuzhiyun
3446*4882a593Smuzhiyun /* There is already a misnamed master switch. Rename it. */
3447*4882a593Smuzhiyun kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
3448*4882a593Smuzhiyun if (!kctl)
3449*4882a593Smuzhiyun return -EINVAL;
3450*4882a593Smuzhiyun
3451*4882a593Smuzhiyun snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
3452*4882a593Smuzhiyun
3453*4882a593Smuzhiyun err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
3454*4882a593Smuzhiyun kctl->tlv.p, follower_vols_vt1616);
3455*4882a593Smuzhiyun if (err < 0)
3456*4882a593Smuzhiyun return err;
3457*4882a593Smuzhiyun
3458*4882a593Smuzhiyun err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
3459*4882a593Smuzhiyun NULL, follower_sws_vt1616);
3460*4882a593Smuzhiyun if (err < 0)
3461*4882a593Smuzhiyun return err;
3462*4882a593Smuzhiyun
3463*4882a593Smuzhiyun return 0;
3464*4882a593Smuzhiyun }
3465*4882a593Smuzhiyun
3466*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_vt1616_ops = {
3467*4882a593Smuzhiyun .build_specific = patch_vt1616_specific
3468*4882a593Smuzhiyun };
3469*4882a593Smuzhiyun
patch_vt1616(struct snd_ac97 * ac97)3470*4882a593Smuzhiyun static int patch_vt1616(struct snd_ac97 * ac97)
3471*4882a593Smuzhiyun {
3472*4882a593Smuzhiyun ac97->build_ops = &patch_vt1616_ops;
3473*4882a593Smuzhiyun return 0;
3474*4882a593Smuzhiyun }
3475*4882a593Smuzhiyun
3476*4882a593Smuzhiyun /*
3477*4882a593Smuzhiyun * VT1617A codec
3478*4882a593Smuzhiyun */
3479*4882a593Smuzhiyun
3480*4882a593Smuzhiyun /*
3481*4882a593Smuzhiyun * unfortunately, the vt1617a stashes the twiddlers required for
3482*4882a593Smuzhiyun * noodling the i/o jacks on 2 different regs. that means that we can't
3483*4882a593Smuzhiyun * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3484*4882a593Smuzhiyun * are own funcs.
3485*4882a593Smuzhiyun *
3486*4882a593Smuzhiyun * NB: this is absolutely and utterly different from the vt1618. dunno
3487*4882a593Smuzhiyun * about the 1616.
3488*4882a593Smuzhiyun */
3489*4882a593Smuzhiyun
3490*4882a593Smuzhiyun /* copied from ac97_surround_jack_mode_info() */
snd_ac97_vt1617a_smart51_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3491*4882a593Smuzhiyun static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3492*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
3493*4882a593Smuzhiyun {
3494*4882a593Smuzhiyun /* ordering in this list reflects vt1617a docs for Reg 20 and
3495*4882a593Smuzhiyun * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3496*4882a593Smuzhiyun * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3497*4882a593Smuzhiyun * counter-intuitive */
3498*4882a593Smuzhiyun
3499*4882a593Smuzhiyun static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
3500*4882a593Smuzhiyun "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3501*4882a593Smuzhiyun "LineIn Mic2", "LineIn Mic2 Mic1",
3502*4882a593Smuzhiyun "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
3503*4882a593Smuzhiyun
3504*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 8, texts);
3505*4882a593Smuzhiyun }
3506*4882a593Smuzhiyun
snd_ac97_vt1617a_smart51_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3507*4882a593Smuzhiyun static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3508*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3509*4882a593Smuzhiyun {
3510*4882a593Smuzhiyun ushort usSM51, usMS;
3511*4882a593Smuzhiyun
3512*4882a593Smuzhiyun struct snd_ac97 *pac97;
3513*4882a593Smuzhiyun
3514*4882a593Smuzhiyun pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3515*4882a593Smuzhiyun
3516*4882a593Smuzhiyun /* grab our desired bits, then mash them together in a manner
3517*4882a593Smuzhiyun * consistent with Table 6 on page 17 in the 1617a docs */
3518*4882a593Smuzhiyun
3519*4882a593Smuzhiyun usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3520*4882a593Smuzhiyun usMS = snd_ac97_read(pac97, 0x20) >> 8;
3521*4882a593Smuzhiyun
3522*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3523*4882a593Smuzhiyun
3524*4882a593Smuzhiyun return 0;
3525*4882a593Smuzhiyun }
3526*4882a593Smuzhiyun
snd_ac97_vt1617a_smart51_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3527*4882a593Smuzhiyun static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3528*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3529*4882a593Smuzhiyun {
3530*4882a593Smuzhiyun ushort usSM51, usMS, usReg;
3531*4882a593Smuzhiyun
3532*4882a593Smuzhiyun struct snd_ac97 *pac97;
3533*4882a593Smuzhiyun
3534*4882a593Smuzhiyun pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3535*4882a593Smuzhiyun
3536*4882a593Smuzhiyun usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3537*4882a593Smuzhiyun usMS = ucontrol->value.enumerated.item[0] & 1;
3538*4882a593Smuzhiyun
3539*4882a593Smuzhiyun /* push our values into the register - consider that things will be left
3540*4882a593Smuzhiyun * in a funky state if the write fails */
3541*4882a593Smuzhiyun
3542*4882a593Smuzhiyun usReg = snd_ac97_read(pac97, 0x7a);
3543*4882a593Smuzhiyun snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3544*4882a593Smuzhiyun usReg = snd_ac97_read(pac97, 0x20);
3545*4882a593Smuzhiyun snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
3546*4882a593Smuzhiyun
3547*4882a593Smuzhiyun return 0;
3548*4882a593Smuzhiyun }
3549*4882a593Smuzhiyun
3550*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3551*4882a593Smuzhiyun
3552*4882a593Smuzhiyun AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3553*4882a593Smuzhiyun /*
3554*4882a593Smuzhiyun * These are used to enable/disable surround sound on motherboards
3555*4882a593Smuzhiyun * that have 3 bidirectional analog jacks
3556*4882a593Smuzhiyun */
3557*4882a593Smuzhiyun {
3558*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3559*4882a593Smuzhiyun .name = "Smart 5.1 Select",
3560*4882a593Smuzhiyun .info = snd_ac97_vt1617a_smart51_info,
3561*4882a593Smuzhiyun .get = snd_ac97_vt1617a_smart51_get,
3562*4882a593Smuzhiyun .put = snd_ac97_vt1617a_smart51_put,
3563*4882a593Smuzhiyun },
3564*4882a593Smuzhiyun };
3565*4882a593Smuzhiyun
patch_vt1617a(struct snd_ac97 * ac97)3566*4882a593Smuzhiyun static int patch_vt1617a(struct snd_ac97 * ac97)
3567*4882a593Smuzhiyun {
3568*4882a593Smuzhiyun int err = 0;
3569*4882a593Smuzhiyun int val;
3570*4882a593Smuzhiyun
3571*4882a593Smuzhiyun /* we choose to not fail out at this point, but we tell the
3572*4882a593Smuzhiyun caller when we return */
3573*4882a593Smuzhiyun
3574*4882a593Smuzhiyun err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3575*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_controls_vt1617a));
3576*4882a593Smuzhiyun
3577*4882a593Smuzhiyun /* bring analog power consumption to normal by turning off the
3578*4882a593Smuzhiyun * headphone amplifier, like WinXP driver for EPIA SP
3579*4882a593Smuzhiyun */
3580*4882a593Smuzhiyun /* We need to check the bit before writing it.
3581*4882a593Smuzhiyun * On some (many?) hardwares, setting bit actually clears it!
3582*4882a593Smuzhiyun */
3583*4882a593Smuzhiyun val = snd_ac97_read(ac97, 0x5c);
3584*4882a593Smuzhiyun if (!(val & 0x20))
3585*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x5c, 0x20);
3586*4882a593Smuzhiyun
3587*4882a593Smuzhiyun ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3588*4882a593Smuzhiyun ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
3589*4882a593Smuzhiyun ac97->build_ops = &patch_vt1616_ops;
3590*4882a593Smuzhiyun
3591*4882a593Smuzhiyun return err;
3592*4882a593Smuzhiyun }
3593*4882a593Smuzhiyun
3594*4882a593Smuzhiyun /* VIA VT1618 8 CHANNEL AC97 CODEC
3595*4882a593Smuzhiyun *
3596*4882a593Smuzhiyun * VIA implements 'Smart 5.1' completely differently on the 1618 than
3597*4882a593Smuzhiyun * it does on the 1617a. awesome! They seem to have sourced this
3598*4882a593Smuzhiyun * particular revision of the technology from somebody else, it's
3599*4882a593Smuzhiyun * called Universal Audio Jack and it shows up on some other folk's chips
3600*4882a593Smuzhiyun * as well.
3601*4882a593Smuzhiyun *
3602*4882a593Smuzhiyun * ordering in this list reflects vt1618 docs for Reg 60h and
3603*4882a593Smuzhiyun * the block diagram, DACs are as follows:
3604*4882a593Smuzhiyun *
3605*4882a593Smuzhiyun * OUT_O -> Front,
3606*4882a593Smuzhiyun * OUT_1 -> Surround,
3607*4882a593Smuzhiyun * OUT_2 -> C/LFE
3608*4882a593Smuzhiyun *
3609*4882a593Smuzhiyun * Unlike the 1617a, each OUT has a consistent set of mappings
3610*4882a593Smuzhiyun * for all bitpatterns other than 00:
3611*4882a593Smuzhiyun *
3612*4882a593Smuzhiyun * 01 Unmixed Output
3613*4882a593Smuzhiyun * 10 Line In
3614*4882a593Smuzhiyun * 11 Mic In
3615*4882a593Smuzhiyun *
3616*4882a593Smuzhiyun * Special Case of 00:
3617*4882a593Smuzhiyun *
3618*4882a593Smuzhiyun * OUT_0 Mixed Output
3619*4882a593Smuzhiyun * OUT_1 Reserved
3620*4882a593Smuzhiyun * OUT_2 Reserved
3621*4882a593Smuzhiyun *
3622*4882a593Smuzhiyun * I have no idea what the hell Reserved does, but on an MSI
3623*4882a593Smuzhiyun * CN700T, i have to set it to get 5.1 output - YMMV, bad
3624*4882a593Smuzhiyun * shit may happen.
3625*4882a593Smuzhiyun *
3626*4882a593Smuzhiyun * If other chips use Universal Audio Jack, then this code might be applicable
3627*4882a593Smuzhiyun * to them.
3628*4882a593Smuzhiyun */
3629*4882a593Smuzhiyun
3630*4882a593Smuzhiyun struct vt1618_uaj_item {
3631*4882a593Smuzhiyun unsigned short mask;
3632*4882a593Smuzhiyun unsigned short shift;
3633*4882a593Smuzhiyun const char * const items[4];
3634*4882a593Smuzhiyun };
3635*4882a593Smuzhiyun
3636*4882a593Smuzhiyun /* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
3637*4882a593Smuzhiyun
3638*4882a593Smuzhiyun static const struct vt1618_uaj_item vt1618_uaj[3] = {
3639*4882a593Smuzhiyun {
3640*4882a593Smuzhiyun /* speaker jack */
3641*4882a593Smuzhiyun .mask = 0x03,
3642*4882a593Smuzhiyun .shift = 0,
3643*4882a593Smuzhiyun .items = {
3644*4882a593Smuzhiyun "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
3645*4882a593Smuzhiyun }
3646*4882a593Smuzhiyun },
3647*4882a593Smuzhiyun {
3648*4882a593Smuzhiyun /* line jack */
3649*4882a593Smuzhiyun .mask = 0x0c,
3650*4882a593Smuzhiyun .shift = 2,
3651*4882a593Smuzhiyun .items = {
3652*4882a593Smuzhiyun "Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
3653*4882a593Smuzhiyun }
3654*4882a593Smuzhiyun },
3655*4882a593Smuzhiyun {
3656*4882a593Smuzhiyun /* mic jack */
3657*4882a593Smuzhiyun .mask = 0x30,
3658*4882a593Smuzhiyun .shift = 4,
3659*4882a593Smuzhiyun .items = {
3660*4882a593Smuzhiyun "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
3661*4882a593Smuzhiyun },
3662*4882a593Smuzhiyun },
3663*4882a593Smuzhiyun };
3664*4882a593Smuzhiyun
snd_ac97_vt1618_UAJ_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3665*4882a593Smuzhiyun static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
3666*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
3667*4882a593Smuzhiyun {
3668*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 4,
3669*4882a593Smuzhiyun vt1618_uaj[kcontrol->private_value].items);
3670*4882a593Smuzhiyun }
3671*4882a593Smuzhiyun
3672*4882a593Smuzhiyun /* All of the vt1618 Universal Audio Jack twiddlers are on
3673*4882a593Smuzhiyun * Vendor Defined Register 0x60, page 0. The bits, and thus
3674*4882a593Smuzhiyun * the mask, are the only thing that changes
3675*4882a593Smuzhiyun */
snd_ac97_vt1618_UAJ_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3676*4882a593Smuzhiyun static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
3677*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3678*4882a593Smuzhiyun {
3679*4882a593Smuzhiyun unsigned short datpag, uaj;
3680*4882a593Smuzhiyun struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
3681*4882a593Smuzhiyun
3682*4882a593Smuzhiyun mutex_lock(&pac97->page_mutex);
3683*4882a593Smuzhiyun
3684*4882a593Smuzhiyun datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
3685*4882a593Smuzhiyun snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
3686*4882a593Smuzhiyun
3687*4882a593Smuzhiyun uaj = snd_ac97_read(pac97, 0x60) &
3688*4882a593Smuzhiyun vt1618_uaj[kcontrol->private_value].mask;
3689*4882a593Smuzhiyun
3690*4882a593Smuzhiyun snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
3691*4882a593Smuzhiyun mutex_unlock(&pac97->page_mutex);
3692*4882a593Smuzhiyun
3693*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] = uaj >>
3694*4882a593Smuzhiyun vt1618_uaj[kcontrol->private_value].shift;
3695*4882a593Smuzhiyun
3696*4882a593Smuzhiyun return 0;
3697*4882a593Smuzhiyun }
3698*4882a593Smuzhiyun
snd_ac97_vt1618_UAJ_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3699*4882a593Smuzhiyun static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
3700*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3701*4882a593Smuzhiyun {
3702*4882a593Smuzhiyun return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
3703*4882a593Smuzhiyun vt1618_uaj[kcontrol->private_value].mask,
3704*4882a593Smuzhiyun ucontrol->value.enumerated.item[0]<<
3705*4882a593Smuzhiyun vt1618_uaj[kcontrol->private_value].shift,
3706*4882a593Smuzhiyun 0);
3707*4882a593Smuzhiyun }
3708*4882a593Smuzhiyun
3709*4882a593Smuzhiyun /* config aux in jack - not found on 3 jack motherboards or soundcards */
3710*4882a593Smuzhiyun
snd_ac97_vt1618_aux_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)3711*4882a593Smuzhiyun static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
3712*4882a593Smuzhiyun struct snd_ctl_elem_info *uinfo)
3713*4882a593Smuzhiyun {
3714*4882a593Smuzhiyun static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
3715*4882a593Smuzhiyun
3716*4882a593Smuzhiyun return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
3717*4882a593Smuzhiyun }
3718*4882a593Smuzhiyun
snd_ac97_vt1618_aux_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3719*4882a593Smuzhiyun static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
3720*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3721*4882a593Smuzhiyun {
3722*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] =
3723*4882a593Smuzhiyun (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
3724*4882a593Smuzhiyun return 0;
3725*4882a593Smuzhiyun }
3726*4882a593Smuzhiyun
snd_ac97_vt1618_aux_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)3727*4882a593Smuzhiyun static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
3728*4882a593Smuzhiyun struct snd_ctl_elem_value *ucontrol)
3729*4882a593Smuzhiyun {
3730*4882a593Smuzhiyun /* toggle surround rear dac power */
3731*4882a593Smuzhiyun
3732*4882a593Smuzhiyun snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
3733*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] << 3);
3734*4882a593Smuzhiyun
3735*4882a593Smuzhiyun /* toggle aux in surround rear out jack */
3736*4882a593Smuzhiyun
3737*4882a593Smuzhiyun return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
3738*4882a593Smuzhiyun ucontrol->value.enumerated.item[0] << 3);
3739*4882a593Smuzhiyun }
3740*4882a593Smuzhiyun
3741*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
3742*4882a593Smuzhiyun AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0),
3743*4882a593Smuzhiyun AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0),
3744*4882a593Smuzhiyun AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1),
3745*4882a593Smuzhiyun AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1),
3746*4882a593Smuzhiyun AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1),
3747*4882a593Smuzhiyun AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1),
3748*4882a593Smuzhiyun {
3749*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3750*4882a593Smuzhiyun .name = "Speaker Jack Mode",
3751*4882a593Smuzhiyun .info = snd_ac97_vt1618_UAJ_info,
3752*4882a593Smuzhiyun .get = snd_ac97_vt1618_UAJ_get,
3753*4882a593Smuzhiyun .put = snd_ac97_vt1618_UAJ_put,
3754*4882a593Smuzhiyun .private_value = 0
3755*4882a593Smuzhiyun },
3756*4882a593Smuzhiyun {
3757*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3758*4882a593Smuzhiyun .name = "Line Jack Mode",
3759*4882a593Smuzhiyun .info = snd_ac97_vt1618_UAJ_info,
3760*4882a593Smuzhiyun .get = snd_ac97_vt1618_UAJ_get,
3761*4882a593Smuzhiyun .put = snd_ac97_vt1618_UAJ_put,
3762*4882a593Smuzhiyun .private_value = 1
3763*4882a593Smuzhiyun },
3764*4882a593Smuzhiyun {
3765*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3766*4882a593Smuzhiyun .name = "Mic Jack Mode",
3767*4882a593Smuzhiyun .info = snd_ac97_vt1618_UAJ_info,
3768*4882a593Smuzhiyun .get = snd_ac97_vt1618_UAJ_get,
3769*4882a593Smuzhiyun .put = snd_ac97_vt1618_UAJ_put,
3770*4882a593Smuzhiyun .private_value = 2
3771*4882a593Smuzhiyun },
3772*4882a593Smuzhiyun {
3773*4882a593Smuzhiyun .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3774*4882a593Smuzhiyun .name = "Aux Jack Mode",
3775*4882a593Smuzhiyun .info = snd_ac97_vt1618_aux_info,
3776*4882a593Smuzhiyun .get = snd_ac97_vt1618_aux_get,
3777*4882a593Smuzhiyun .put = snd_ac97_vt1618_aux_put,
3778*4882a593Smuzhiyun }
3779*4882a593Smuzhiyun };
3780*4882a593Smuzhiyun
patch_vt1618(struct snd_ac97 * ac97)3781*4882a593Smuzhiyun static int patch_vt1618(struct snd_ac97 *ac97)
3782*4882a593Smuzhiyun {
3783*4882a593Smuzhiyun return patch_build_controls(ac97, snd_ac97_controls_vt1618,
3784*4882a593Smuzhiyun ARRAY_SIZE(snd_ac97_controls_vt1618));
3785*4882a593Smuzhiyun }
3786*4882a593Smuzhiyun
3787*4882a593Smuzhiyun /*
3788*4882a593Smuzhiyun */
it2646_update_jacks(struct snd_ac97 * ac97)3789*4882a593Smuzhiyun static void it2646_update_jacks(struct snd_ac97 *ac97)
3790*4882a593Smuzhiyun {
3791*4882a593Smuzhiyun /* shared Line-In / Surround Out */
3792*4882a593Smuzhiyun snd_ac97_update_bits(ac97, 0x76, 1 << 9,
3793*4882a593Smuzhiyun is_shared_surrout(ac97) ? (1<<9) : 0);
3794*4882a593Smuzhiyun /* shared Mic / Center/LFE Out */
3795*4882a593Smuzhiyun snd_ac97_update_bits(ac97, 0x76, 1 << 10,
3796*4882a593Smuzhiyun is_shared_clfeout(ac97) ? (1<<10) : 0);
3797*4882a593Smuzhiyun }
3798*4882a593Smuzhiyun
3799*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
3800*4882a593Smuzhiyun AC97_SURROUND_JACK_MODE_CTL,
3801*4882a593Smuzhiyun AC97_CHANNEL_MODE_CTL,
3802*4882a593Smuzhiyun };
3803*4882a593Smuzhiyun
3804*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
3805*4882a593Smuzhiyun AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
3806*4882a593Smuzhiyun AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3807*4882a593Smuzhiyun AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3808*4882a593Smuzhiyun };
3809*4882a593Smuzhiyun
patch_it2646_specific(struct snd_ac97 * ac97)3810*4882a593Smuzhiyun static int patch_it2646_specific(struct snd_ac97 * ac97)
3811*4882a593Smuzhiyun {
3812*4882a593Smuzhiyun int err;
3813*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
3814*4882a593Smuzhiyun return err;
3815*4882a593Smuzhiyun if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
3816*4882a593Smuzhiyun return err;
3817*4882a593Smuzhiyun return 0;
3818*4882a593Smuzhiyun }
3819*4882a593Smuzhiyun
3820*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_it2646_ops = {
3821*4882a593Smuzhiyun .build_specific = patch_it2646_specific,
3822*4882a593Smuzhiyun .update_jacks = it2646_update_jacks
3823*4882a593Smuzhiyun };
3824*4882a593Smuzhiyun
patch_it2646(struct snd_ac97 * ac97)3825*4882a593Smuzhiyun static int patch_it2646(struct snd_ac97 * ac97)
3826*4882a593Smuzhiyun {
3827*4882a593Smuzhiyun ac97->build_ops = &patch_it2646_ops;
3828*4882a593Smuzhiyun /* full DAC volume */
3829*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x5E, 0x0808);
3830*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x7A, 0x0808);
3831*4882a593Smuzhiyun return 0;
3832*4882a593Smuzhiyun }
3833*4882a593Smuzhiyun
3834*4882a593Smuzhiyun /*
3835*4882a593Smuzhiyun * Si3036 codec
3836*4882a593Smuzhiyun */
3837*4882a593Smuzhiyun
3838*4882a593Smuzhiyun #define AC97_SI3036_CHIP_ID 0x5a
3839*4882a593Smuzhiyun #define AC97_SI3036_LINE_CFG 0x5c
3840*4882a593Smuzhiyun
3841*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
3842*4882a593Smuzhiyun AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3843*4882a593Smuzhiyun };
3844*4882a593Smuzhiyun
patch_si3036_specific(struct snd_ac97 * ac97)3845*4882a593Smuzhiyun static int patch_si3036_specific(struct snd_ac97 * ac97)
3846*4882a593Smuzhiyun {
3847*4882a593Smuzhiyun int idx, err;
3848*4882a593Smuzhiyun for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
3849*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
3850*4882a593Smuzhiyun return err;
3851*4882a593Smuzhiyun return 0;
3852*4882a593Smuzhiyun }
3853*4882a593Smuzhiyun
3854*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_si3036_ops = {
3855*4882a593Smuzhiyun .build_specific = patch_si3036_specific,
3856*4882a593Smuzhiyun };
3857*4882a593Smuzhiyun
mpatch_si3036(struct snd_ac97 * ac97)3858*4882a593Smuzhiyun static int mpatch_si3036(struct snd_ac97 * ac97)
3859*4882a593Smuzhiyun {
3860*4882a593Smuzhiyun ac97->build_ops = &patch_si3036_ops;
3861*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
3862*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x68, 0);
3863*4882a593Smuzhiyun return 0;
3864*4882a593Smuzhiyun }
3865*4882a593Smuzhiyun
3866*4882a593Smuzhiyun /*
3867*4882a593Smuzhiyun * LM 4550 Codec
3868*4882a593Smuzhiyun *
3869*4882a593Smuzhiyun * We use a static resolution table since LM4550 codec cannot be
3870*4882a593Smuzhiyun * properly autoprobed to determine the resolution via
3871*4882a593Smuzhiyun * check_volume_resolution().
3872*4882a593Smuzhiyun */
3873*4882a593Smuzhiyun
3874*4882a593Smuzhiyun static const struct snd_ac97_res_table lm4550_restbl[] = {
3875*4882a593Smuzhiyun { AC97_MASTER, 0x1f1f },
3876*4882a593Smuzhiyun { AC97_HEADPHONE, 0x1f1f },
3877*4882a593Smuzhiyun { AC97_MASTER_MONO, 0x001f },
3878*4882a593Smuzhiyun { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
3879*4882a593Smuzhiyun { AC97_PHONE, 0x001f },
3880*4882a593Smuzhiyun { AC97_MIC, 0x001f },
3881*4882a593Smuzhiyun { AC97_LINE, 0x1f1f },
3882*4882a593Smuzhiyun { AC97_CD, 0x1f1f },
3883*4882a593Smuzhiyun { AC97_VIDEO, 0x1f1f },
3884*4882a593Smuzhiyun { AC97_AUX, 0x1f1f },
3885*4882a593Smuzhiyun { AC97_PCM, 0x1f1f },
3886*4882a593Smuzhiyun { AC97_REC_GAIN, 0x0f0f },
3887*4882a593Smuzhiyun { } /* terminator */
3888*4882a593Smuzhiyun };
3889*4882a593Smuzhiyun
patch_lm4550(struct snd_ac97 * ac97)3890*4882a593Smuzhiyun static int patch_lm4550(struct snd_ac97 *ac97)
3891*4882a593Smuzhiyun {
3892*4882a593Smuzhiyun ac97->res_table = lm4550_restbl;
3893*4882a593Smuzhiyun return 0;
3894*4882a593Smuzhiyun }
3895*4882a593Smuzhiyun
3896*4882a593Smuzhiyun /*
3897*4882a593Smuzhiyun * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3898*4882a593Smuzhiyun */
3899*4882a593Smuzhiyun static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
3900*4882a593Smuzhiyun /* enable/disable headphone driver which allows direct connection to
3901*4882a593Smuzhiyun stereo headphone without the use of external DC blocking
3902*4882a593Smuzhiyun capacitors */
3903*4882a593Smuzhiyun AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3904*4882a593Smuzhiyun /* Filter used to compensate the DC offset is added in the ADC to remove idle
3905*4882a593Smuzhiyun tones from the audio band. */
3906*4882a593Smuzhiyun AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3907*4882a593Smuzhiyun /* Control smart-low-power mode feature. Allows automatic power down
3908*4882a593Smuzhiyun of unused blocks in the ADC analog front end and the PLL. */
3909*4882a593Smuzhiyun AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3910*4882a593Smuzhiyun };
3911*4882a593Smuzhiyun
patch_ucb1400_specific(struct snd_ac97 * ac97)3912*4882a593Smuzhiyun static int patch_ucb1400_specific(struct snd_ac97 * ac97)
3913*4882a593Smuzhiyun {
3914*4882a593Smuzhiyun int idx, err;
3915*4882a593Smuzhiyun for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
3916*4882a593Smuzhiyun if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
3917*4882a593Smuzhiyun return err;
3918*4882a593Smuzhiyun return 0;
3919*4882a593Smuzhiyun }
3920*4882a593Smuzhiyun
3921*4882a593Smuzhiyun static const struct snd_ac97_build_ops patch_ucb1400_ops = {
3922*4882a593Smuzhiyun .build_specific = patch_ucb1400_specific,
3923*4882a593Smuzhiyun };
3924*4882a593Smuzhiyun
patch_ucb1400(struct snd_ac97 * ac97)3925*4882a593Smuzhiyun static int patch_ucb1400(struct snd_ac97 * ac97)
3926*4882a593Smuzhiyun {
3927*4882a593Smuzhiyun ac97->build_ops = &patch_ucb1400_ops;
3928*4882a593Smuzhiyun /* enable headphone driver and smart low power mode by default */
3929*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x6a, 0x0050);
3930*4882a593Smuzhiyun snd_ac97_write_cache(ac97, 0x6c, 0x0030);
3931*4882a593Smuzhiyun return 0;
3932*4882a593Smuzhiyun }
3933