ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pci / ac97 / ac97_patch.c
1 /*
2  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3  *  Universal interface for Audio Codec '97
4  *
5  *  For more details look to AC '97 component specification revision 2.2
6  *  by Intel Corporation (http://developer.intel.com) and to datasheets
7  *  for specific codecs.
8  *
9  *
10  *   This program is free software; you can redistribute it and/or modify
11  *   it under the terms of the GNU General Public License as published by
12  *   the Free Software Foundation; either version 2 of the License, or
13  *   (at your option) any later version.
14  *
15  *   This program is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with this program; if not, write to the Free Software
22  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  *
24  */
25
26 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/control.h>
33 #include <sound/ac97_codec.h>
34 #include "ac97_patch.h"
35 #include "ac97_id.h"
36 #include "ac97_local.h"
37
38 #define chip_t ac97_t
39
40 /*
41  *  Chip specific initialization
42  */
43
44 static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count)
45 {
46         int idx, err;
47
48         for (idx = 0; idx < count; idx++)
49                 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
50                         return err;
51         return 0;
52 }
53
54 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
55
56 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
57 static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
58 {
59         static char *texts[3] = {
60                 "Standard", "Small", "Smaller"
61         };
62
63         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
64         uinfo->count = 1;
65         uinfo->value.enumerated.items = 3;
66         if (uinfo->value.enumerated.item > 2)
67                 uinfo->value.enumerated.item = 2;
68         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
69         return 0;
70 }
71
72 static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
73 {
74         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
75         unsigned short val;
76
77         val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
78         val = (val >> 10) & 3;
79         if (val > 0)    /* 0 = invalid */
80                 val--;
81         ucontrol->value.enumerated.item[0] = val;
82         return 0;
83 }
84
85 static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
86 {
87         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
88         unsigned short val;
89
90         if (ucontrol->value.enumerated.item[0] > 2)
91                 return -EINVAL;
92         val = (ucontrol->value.enumerated.item[0] + 1) << 10;
93         return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
94 }
95
96 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
97 {
98         .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
99         .name   = "3D Control - Speaker",
100         .info   = snd_ac97_ymf753_info_speaker,
101         .get    = snd_ac97_ymf753_get_speaker,
102         .put    = snd_ac97_ymf753_put_speaker,
103 };
104
105 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
106 static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
107 {
108         static char *texts[2] = { "AC-Link", "A/D Converter" };
109
110         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
111         uinfo->count = 1;
112         uinfo->value.enumerated.items = 2;
113         if (uinfo->value.enumerated.item > 1)
114                 uinfo->value.enumerated.item = 1;
115         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
116         return 0;
117 }
118
119 static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
120 {
121         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
122         unsigned short val;
123
124         val = ac97->regs[AC97_YMF753_DIT_CTRL2];
125         ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
126         return 0;
127 }
128
129 static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
130 {
131         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
132         unsigned short val;
133
134         if (ucontrol->value.enumerated.item[0] > 1)
135                 return -EINVAL;
136         val = ucontrol->value.enumerated.item[0] << 1;
137         return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
138 }
139
140 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
141    The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
142    By default, no output pin is selected, and the S/PDIF signal is not output.
143    There is also a bit to mute S/PDIF output in a vendor-specific register. */
144 static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
145 {
146         static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
147
148         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
149         uinfo->count = 1;
150         uinfo->value.enumerated.items = 3;
151         if (uinfo->value.enumerated.item > 2)
152                 uinfo->value.enumerated.item = 2;
153         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
154         return 0;
155 }
156
157 static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
158 {
159         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
160         unsigned short val;
161
162         val = ac97->regs[AC97_YMF753_DIT_CTRL2];
163         ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
164         return 0;
165 }
166
167 static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
168 {
169         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
170         unsigned short val;
171
172         if (ucontrol->value.enumerated.item[0] > 2)
173                 return -EINVAL;
174         val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
175               (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
176         return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
177         /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
178            snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
179 }
180
181 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
182         {
183                 .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
184                 .name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
185                 .info   = snd_ac97_ymf753_spdif_source_info,
186                 .get    = snd_ac97_ymf753_spdif_source_get,
187                 .put    = snd_ac97_ymf753_spdif_source_put,
188         },
189         {
190                 .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
191                 .name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
192                 .info   = snd_ac97_ymf753_spdif_output_pin_info,
193                 .get    = snd_ac97_ymf753_spdif_output_pin_get,
194                 .put    = snd_ac97_ymf753_spdif_output_pin_put,
195         },
196         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
197 };
198
199 static int patch_yamaha_ymf753_3d(ac97_t * ac97)
200 {
201         snd_kcontrol_t *kctl;
202         int err;
203
204         if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
205                 return err;
206         strcpy(kctl->id.name, "3D Control - Wide");
207         kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16);
208         snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
209         if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
210                 return err;
211         snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
212         return 0;
213 }
214
215 static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97)
216 {
217         int err;
218
219         if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
220                 return err;
221         return 0;
222 }
223
224 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
225         .build_3d       = patch_yamaha_ymf753_3d,
226         .build_post_spdif = patch_yamaha_ymf753_post_spdif
227 };
228
229 int patch_yamaha_ymf753(ac97_t * ac97)
230 {
231         /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
232            This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
233            The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
234            The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
235            By default, no output pin is selected, and the S/PDIF signal is not output.
236            There is also a bit to mute S/PDIF output in a vendor-specific register.
237         */
238         ac97->build_ops = &patch_yamaha_ymf753_ops;
239         ac97->caps |= AC97_BC_BASS_TREBLE;
240         ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
241         return 0;
242 }
243
244 /*
245  * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
246  *  removed broken wolfson00 patch.
247  *  added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
248  */
249
250 int patch_wolfson03(ac97_t * ac97)
251 {
252         /* This is known to work for the ViewSonic ViewPad 1000
253            Randolph Bentson <bentson@holmsjoen.com> */
254
255         // WM9703/9707/9708/9717
256         snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
257         snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000);
258         return 0;
259 }
260   
261 int patch_wolfson04(ac97_t * ac97)
262 {
263         // WM9704M/9704Q
264         // set front and rear mixer volume
265         snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
266         snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808);
267         
268         // patch for DVD noise
269         snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
270  
271         // init vol
272         snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808);
273  
274         // set rear surround volume
275         snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
276         return 0;
277 }
278   
279 int patch_wolfson05(ac97_t * ac97)
280 {
281         // WM9705, WM9710
282         // set front mixer volume
283         snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
284         return 0;
285 }
286
287 int patch_wolfson11(ac97_t * ac97)
288 {
289         // WM9711, WM9712
290         // set out3 volume
291         snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808);
292         return 0;
293 }
294
295 /*
296  * Tritech codec
297  */
298 int patch_tritech_tr28028(ac97_t * ac97)
299 {
300         snd_ac97_write_cache(ac97, 0x26, 0x0300);
301         snd_ac97_write_cache(ac97, 0x26, 0x0000);
302         snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
303         snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
304         return 0;
305 }
306
307 /*
308  * Sigmatel STAC97xx codecs
309  */
310 static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
311 {
312         snd_kcontrol_t *kctl;
313         int err;
314
315         if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
316                 return err;
317         strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
318         kctl->private_value = AC97_3D_CONTROL | (3 << 16);
319         snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
320         return 0;
321 }
322
323 static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
324 {
325         snd_kcontrol_t *kctl;
326         int err;
327
328         if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
329                 return err;
330         strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
331         kctl->private_value = AC97_3D_CONTROL | (3 << 16);
332         if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
333                 return err;
334         strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
335         kctl->private_value = AC97_3D_CONTROL | (2 << 8) | (3 << 16);
336         snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
337         return 0;
338 }
339
340 static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
341 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
342
343 static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
344 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
345
346 static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
347 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
348 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
349 };
350
351 static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
352 {
353         int err;
354
355         snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
356         if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
357                 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
358                         return err;
359         if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
360                 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
361                         return err;
362         if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
363                 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
364                         return err;
365         if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
366                 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
367                         return err;
368         return 0;
369 }
370
371 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
372         .build_3d       = patch_sigmatel_stac9700_3d,
373         .build_specific = patch_sigmatel_stac97xx_specific
374 };
375
376 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
377         .build_3d       = patch_sigmatel_stac9708_3d,
378         .build_specific = patch_sigmatel_stac97xx_specific
379 };
380
381 int patch_sigmatel_stac9700(ac97_t * ac97)
382 {
383         ac97->build_ops = &patch_sigmatel_stac9700_ops;
384         return 0;
385 }
386
387 int patch_sigmatel_stac9708(ac97_t * ac97)
388 {
389         unsigned int codec72, codec6c;
390
391         ac97->build_ops = &patch_sigmatel_stac9708_ops;
392
393         codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
394         codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
395
396         if ((codec72==0) && (codec6c==0)) {
397                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
398                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
399                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
400                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
401         } else if ((codec72==0x8000) && (codec6c==0)) {
402                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
403                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
404                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
405         } else if ((codec72==0x8000) && (codec6c==0x0080)) {
406                 /* nothing */
407         }
408         snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
409         return 0;
410 }
411
412 int patch_sigmatel_stac9721(ac97_t * ac97)
413 {
414         ac97->build_ops = &patch_sigmatel_stac9700_ops;
415         if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
416                 // patch for SigmaTel
417                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
418                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
419                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
420                 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
421         }
422         snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
423         return 0;
424 }
425
426 int patch_sigmatel_stac9744(ac97_t * ac97)
427 {
428         // patch for SigmaTel
429         ac97->build_ops = &patch_sigmatel_stac9700_ops;
430         snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
431         snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
432         snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
433         snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
434         snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
435         return 0;
436 }
437
438 int patch_sigmatel_stac9756(ac97_t * ac97)
439 {
440         // patch for SigmaTel
441         ac97->build_ops = &patch_sigmatel_stac9700_ops;
442         snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
443         snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
444         snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
445         snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
446         snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
447         return 0;
448 }
449
450 int patch_sigmatel_stac9758(ac97_t * ac97)
451 {
452         // patch for SigmaTel
453         ac97->build_ops = &patch_sigmatel_stac9700_ops;
454         // turn on stereo speaker, headphone and line-out
455         snd_ac97_write_cache(ac97, AC97_SIGMATEL_OUTSEL, 0x9040);
456         // headphone select and boost
457         snd_ac97_write_cache(ac97, AC97_SIGMATEL_IOMISC, 0x2102);
458         // enable mic
459         snd_ac97_write_cache(ac97, AC97_SIGMATEL_INSEL, 0x0203);
460         // enable stereo mic
461         snd_ac97_write_cache(ac97, AC97_SIGMATEL_VARIOUS, 0x0001);
462         return 0;
463 }
464
465 /*
466  * Cirrus Logic CS42xx codecs
467  */
468 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
469         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
470         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
471 };
472
473 static int patch_cirrus_build_spdif(ac97_t * ac97)
474 {
475         int err;
476
477         if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
478                 return err;
479         if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
480                 return err;
481         switch (ac97->id & AC97_ID_CS_MASK) {
482         case AC97_ID_CS4205:
483                 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
484                         return err;
485                 break;
486         }
487         /* set default PCM S/PDIF params */
488         /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
489         snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
490         return 0;
491 }
492
493 static struct snd_ac97_build_ops patch_cirrus_ops = {
494         .build_spdif = patch_cirrus_build_spdif
495 };
496
497 int patch_cirrus_spdif(ac97_t * ac97)
498 {
499         /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
500            WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC?  *sigh*
501            - sp/dif EA ID is not set, but sp/dif is always present.
502            - enable/disable is spdif register bit 15.
503            - sp/dif control register is 0x68.  differs from AC97:
504            - valid is bit 14 (vs 15)
505            - no DRS
506            - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
507            - sp/dif ssource select is in 0x5e bits 0,1.
508         */
509
510         ac97->build_ops = &patch_cirrus_ops;
511         ac97->flags |= AC97_CS_SPDIF; 
512         ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
513         ac97->ext_id |= AC97_EI_SPDIF;  /* force the detection of spdif */
514         snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
515         return 0;
516 }
517
518 int patch_cirrus_cs4299(ac97_t * ac97)
519 {
520         /* force the detection of PC Beep */
521         ac97->flags |= AC97_HAS_PC_BEEP;
522         
523         return patch_cirrus_spdif(ac97);
524 }
525
526 /*
527  * Conexant codecs
528  */
529 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
530         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
531 };
532
533 static int patch_conexant_build_spdif(ac97_t * ac97)
534 {
535         int err;
536
537         if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
538                 return err;
539         if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
540                 return err;
541         /* set default PCM S/PDIF params */
542         /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
543         snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
544                              snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
545         return 0;
546 }
547
548 static struct snd_ac97_build_ops patch_conexant_ops = {
549         .build_spdif = patch_conexant_build_spdif
550 };
551
552 int patch_conexant(ac97_t * ac97)
553 {
554         ac97->build_ops = &patch_conexant_ops;
555         ac97->flags |= AC97_CX_SPDIF;
556         ac97->ext_id |= AC97_EI_SPDIF;  /* force the detection of spdif */
557         return 0;
558 }
559
560 /*
561  * Analog Device AD18xx, AD19xx codecs
562  */
563 int patch_ad1819(ac97_t * ac97)
564 {
565         unsigned short scfg;
566
567         // patch for Analog Devices
568         scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
569         snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
570         return 0;
571 }
572
573 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
574 {
575         unsigned short val;
576
577         // test for unchained codec
578         snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
579         snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);  /* ID0C, ID1C, SDIE = off */
580         val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
581         if ((val & 0xff40) != 0x5340)
582                 return 0;
583         ac97->spec.ad18xx.unchained[idx] = mask;
584         ac97->spec.ad18xx.id[idx] = val;
585         ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
586         return mask;
587 }
588
589 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
590 {
591         static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
592         unsigned short val;
593         
594         snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
595         snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004);  // SDIE
596         val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
597         if ((val & 0xff40) != 0x5340)
598                 return 0;
599         if (codec_bits)
600                 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
601         ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
602         ac97->spec.ad18xx.id[idx] = val;
603         ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
604         return 1;
605 }
606
607 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
608 {
609         // already detected?
610         if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
611                 cidx1 = -1;
612         if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
613                 cidx2 = -1;
614         if (cidx1 < 0 && cidx2 < 0)
615                 return;
616         // test for chained codecs
617         snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
618                              ac97->spec.ad18xx.unchained[unchained_idx]);
619         snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002);          // ID1C
620         ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
621         if (cidx1 >= 0) {
622                 if (patch_ad1881_chained1(ac97, cidx1, 0x0006))         // SDIE | ID1C
623                         patch_ad1881_chained1(ac97, cidx2, 0);
624                 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006))    // SDIE | ID1C
625                         patch_ad1881_chained1(ac97, cidx1, 0);
626         } else if (cidx2 >= 0) {
627                 patch_ad1881_chained1(ac97, cidx2, 0);
628         }
629 }
630
631 int patch_ad1881(ac97_t * ac97)
632 {
633         static const char cfg_idxs[3][2] = {
634                 {2, 1},
635                 {0, 2},
636                 {0, 1}
637         };
638         
639         // patch for Analog Devices
640         unsigned short codecs[3];
641         unsigned short val;
642         int idx, num;
643
644         init_MUTEX(&ac97->spec.ad18xx.mutex);
645
646         val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
647         snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
648         codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
649         codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
650         codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
651
652         snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
653
654         for (idx = 0; idx < 3; idx++)
655                 if (ac97->spec.ad18xx.unchained[idx])
656                         patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
657
658         if (ac97->spec.ad18xx.id[1]) {
659                 ac97->flags |= AC97_AD_MULTI;
660                 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
661         }
662         if (ac97->spec.ad18xx.id[2]) {
663                 ac97->flags |= AC97_AD_MULTI;
664                 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
665         }
666
667       __end:
668         /* select all codecs */
669         snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
670         /* check if only one codec is present */
671         for (idx = num = 0; idx < 3; idx++)
672                 if (ac97->spec.ad18xx.id[idx])
673                         num++;
674         if (num == 1) {
675                 /* ok, deselect all ID bits */
676                 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
677                 ac97->spec.ad18xx.codec_cfg[0] = 
678                         ac97->spec.ad18xx.codec_cfg[1] = 
679                         ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
680         }
681         /* required for AD1886/AD1885 combination */
682         ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
683         if (ac97->spec.ad18xx.id[0]) {
684                 ac97->id &= 0xffff0000;
685                 ac97->id |= ac97->spec.ad18xx.id[0];
686         }
687         return 0;
688 }
689
690 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
691         AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
692         /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
693         AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
694         AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
695 };
696
697 static int patch_ad1885_specific(ac97_t * ac97)
698 {
699         int err;
700
701         if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
702                 return err;
703         return 0;
704 }
705
706 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
707         .build_specific = &patch_ad1885_specific
708 };
709
710 int patch_ad1885(ac97_t * ac97)
711 {
712         unsigned short jack;
713
714         patch_ad1881(ac97);
715         /* This is required to deal with the Intel D815EEAL2 */
716         /* i.e. Line out is actually headphone out from codec */
717
718         /* turn off jack sense bits D8 & D9 */
719         jack = snd_ac97_read(ac97, AC97_AD_JACK_SPDIF);
720         snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, jack | 0x0300);
721
722         /* set default */
723         snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
724
725         ac97->build_ops = &patch_ad1885_build_ops;
726         return 0;
727 }
728
729 int patch_ad1886(ac97_t * ac97)
730 {
731         patch_ad1881(ac97);
732         /* Presario700 workaround */
733         /* for Jack Sense/SPDIF Register misetting causing */
734         snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
735         return 0;
736 }
737
738 /* MISC bits */
739 #define AC97_AD198X_MBC         0x0003  /* mic boost */
740 #define AC97_AD198X_MBC_20      0x0000  /* +20dB */
741 #define AC97_AD198X_MBC_10      0x0001  /* +10dB */
742 #define AC97_AD198X_MBC_30      0x0002  /* +30dB */
743 #define AC97_AD198X_VREFD       0x0004  /* VREF high-Z */
744 #define AC97_AD198X_VREFH       0x0008  /* 2.25V, 3.7V */
745 #define AC97_AD198X_VREF_0      0x000c  /* 0V */
746 #define AC97_AD198X_SRU         0x0010  /* sample rate unlock */
747 #define AC97_AD198X_LOSEL       0x0020  /* LINE_OUT amplifiers input select */
748 #define AC97_AD198X_2MIC        0x0040  /* 2-channel mic select */
749 #define AC97_AD198X_SPRD        0x0080  /* SPREAD enable */
750 #define AC97_AD198X_DMIX0       0x0100  /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
751 #define AC97_AD198X_DMIX1       0x0200  /* downmix mode: 1 = enabled */
752 #define AC97_AD198X_HPSEL       0x0400  /* headphone amplifier input select */
753 #define AC97_AD198X_CLDIS       0x0800  /* center/lfe disable */
754 #define AC97_AD198X_LODIS       0x1000  /* LINE_OUT disable */
755 #define AC97_AD198X_MSPLT       0x2000  /* mute split */
756 #define AC97_AD198X_AC97NC      0x4000  /* AC97 no compatible mode */
757 #define AC97_AD198X_DACZ        0x8000  /* DAC zero-fill mode */
758
759
760 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
761 {
762         static char *texts[2] = { "AC-Link", "A/D Converter" };
763
764         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
765         uinfo->count = 1;
766         uinfo->value.enumerated.items = 2;
767         if (uinfo->value.enumerated.item > 1)
768                 uinfo->value.enumerated.item = 1;
769         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
770         return 0;
771 }
772
773 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
774 {
775         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
776         unsigned short val;
777
778         val = ac97->regs[AC97_AD_SERIAL_CFG];
779         ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
780         return 0;
781 }
782
783 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
784 {
785         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
786         unsigned short val;
787
788         if (ucontrol->value.enumerated.item[0] > 1)
789                 return -EINVAL;
790         val = ucontrol->value.enumerated.item[0] << 2;
791         return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
792 }
793
794 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
795         .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
796         .name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
797         .info   = snd_ac97_ad198x_spdif_source_info,
798         .get    = snd_ac97_ad198x_spdif_source_get,
799         .put    = snd_ac97_ad198x_spdif_source_put,
800 };
801
802 static int patch_ad198x_post_spdif(ac97_t * ac97)
803 {
804         return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
805 }
806
807 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
808         .build_post_spdif = patch_ad198x_post_spdif
809 };
810
811 int patch_ad1981a(ac97_t *ac97)
812 {
813         patch_ad1881(ac97);
814         ac97->build_ops = &patch_ad1981a_build_ops;
815         snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
816         ac97->flags |= AC97_STEREO_MUTES;
817         return 0;
818 }
819
820 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
821 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
822
823 static int patch_ad1981b_specific(ac97_t *ac97)
824 {
825         return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
826 }
827
828 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
829         .build_post_spdif = patch_ad198x_post_spdif,
830         .build_specific = patch_ad1981b_specific
831 };
832
833 int patch_ad1981b(ac97_t *ac97)
834 {
835         patch_ad1881(ac97);
836         ac97->build_ops = &patch_ad1981b_build_ops;
837         snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
838         ac97->flags |= AC97_STEREO_MUTES;
839         return 0;
840 }
841
842 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
843 {
844         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
845         uinfo->count = 1;
846         uinfo->value.integer.min = 0;
847         uinfo->value.integer.max = 1;
848         return 0;
849 }
850
851 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
852 {
853         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
854         unsigned short val;
855
856         val = ac97->regs[AC97_AD_MISC];
857         ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
858         return 0;
859 }
860
861 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
862 {
863         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
864         unsigned short val;
865
866         val = !ucontrol->value.integer.value[0]
867                 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
868         return snd_ac97_update_bits(ac97, AC97_AD_MISC,
869                                     AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
870 }
871
872 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
873 {
874         static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
875
876         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
877         uinfo->count = 1;
878         uinfo->value.enumerated.items = 3;
879         if (uinfo->value.enumerated.item > 2)
880                 uinfo->value.enumerated.item = 2;
881         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
882         return 0;
883 }
884
885 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
886 {
887         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
888         unsigned short val;
889
890         val = ac97->regs[AC97_AD_MISC];
891         if (!(val & AC97_AD198X_DMIX1))
892                 ucontrol->value.enumerated.item[0] = 0;
893         else
894                 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
895         return 0;
896 }
897
898 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
899 {
900         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
901         unsigned short val;
902
903         if (ucontrol->value.enumerated.item[0] > 2)
904                 return -EINVAL;
905         if (ucontrol->value.enumerated.item[0] == 0)
906                 val = 0;
907         else
908                 val = AC97_AD198X_DMIX1 |
909                         ((ucontrol->value.enumerated.item[0] - 1) << 8);
910         return snd_ac97_update_bits(ac97, AC97_AD_MISC,
911                                     AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
912 }
913
914 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
915         {
916                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
917                 .name = "Exchange Front/Surround",
918                 .info = snd_ac97_ad1888_lohpsel_info,
919                 .get = snd_ac97_ad1888_lohpsel_get,
920                 .put = snd_ac97_ad1888_lohpsel_put
921         },
922         AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
923         {
924                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
925                 .name = "Downmix",
926                 .info = snd_ac97_ad1888_downmix_info,
927                 .get = snd_ac97_ad1888_downmix_get,
928                 .put = snd_ac97_ad1888_downmix_put
929         },
930         AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC, 12, 1, 0),
931         AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC, 11, 1, 0),
932 };
933
934 static int patch_ad1888_specific(ac97_t *ac97)
935 {
936         /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
937         snd_ac97_rename_ctl(ac97, "Master Playback Switch", "Master Surround Playback Switch");
938         snd_ac97_rename_ctl(ac97, "Master Playback Volume", "Master Surround Playback Volume");
939         snd_ac97_rename_ctl(ac97, "Headphone Playback Switch", "Master Playback Switch");
940         snd_ac97_rename_ctl(ac97, "Headphone Playback Volume", "Master Playback Volume");
941         return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
942 }
943
944 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
945         .build_post_spdif = patch_ad198x_post_spdif,
946         .build_specific = patch_ad1888_specific
947 };
948
949 int patch_ad1888(ac97_t * ac97)
950 {
951         unsigned short misc;
952         
953         patch_ad1881(ac97);
954         ac97->build_ops = &patch_ad1888_build_ops;
955         /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
956         /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
957         /* AD-compatible mode */
958         /* Stereo mutes enabled */
959         misc = snd_ac97_read(ac97, AC97_AD_MISC);
960         snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
961                              AC97_AD198X_LOSEL |
962                              AC97_AD198X_HPSEL |
963                              AC97_AD198X_MSPLT |
964                              AC97_AD198X_AC97NC);
965         ac97->flags |= AC97_STEREO_MUTES;
966         return 0;
967 }
968
969 static int patch_ad1980_specific(ac97_t *ac97)
970 {
971         int err;
972
973         if ((err = patch_ad1888_specific(ac97)) < 0)
974                 return err;
975         return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
976 }
977
978 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
979         .build_post_spdif = patch_ad198x_post_spdif,
980         .build_specific = patch_ad1980_specific
981 };
982
983 int patch_ad1980(ac97_t * ac97)
984 {
985         patch_ad1888(ac97);
986         ac97->build_ops = &patch_ad1980_build_ops;
987         return 0;
988 }
989
990 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
991         AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG, 9, 1, 0),
992         AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
993 };
994
995 static int patch_ad1985_specific(ac97_t *ac97)
996 {
997         int err;
998
999         if ((err = patch_ad1980_specific(ac97)) < 0)
1000                 return err;
1001         return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1002 }
1003
1004 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1005         .build_post_spdif = patch_ad198x_post_spdif,
1006         .build_specific = patch_ad1985_specific
1007 };
1008
1009 int patch_ad1985(ac97_t * ac97)
1010 {
1011         unsigned short misc;
1012         
1013         patch_ad1881(ac97);
1014         ac97->build_ops = &patch_ad1985_build_ops;
1015         misc = snd_ac97_read(ac97, AC97_AD_MISC);
1016         /* switch front/surround line-out/hp-out */
1017         /* center/LFE, mic in 3.75V mode */
1018         /* AD-compatible mode */
1019         /* Stereo mutes enabled */
1020         /* in accordance with ADI driver: misc | 0x5c28 */
1021         snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1022                              AC97_AD198X_VREFH |
1023                              AC97_AD198X_LOSEL |
1024                              AC97_AD198X_HPSEL |
1025                              AC97_AD198X_CLDIS |
1026                              AC97_AD198X_LODIS |
1027                              AC97_AD198X_MSPLT |
1028                              AC97_AD198X_AC97NC);
1029         ac97->flags |= AC97_STEREO_MUTES;
1030         return 0;
1031 }
1032
1033 /*
1034  * realtek ALC65x codecs
1035  */
1036 static int snd_ac97_alc650_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1037 {
1038         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1039         ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1040         return 0;
1041 }
1042
1043 static int snd_ac97_alc650_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1044 {
1045         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1046         int change, val;
1047         val = !!(snd_ac97_read(ac97, AC97_ALC650_MULTICH) & (1 << 10));
1048         change = (ucontrol->value.integer.value[0] != val);
1049         if (change) {
1050                 /* disable/enable vref */
1051                 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1052                                      ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1053                 /* turn on/off center-on-mic */
1054                 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1055                                      ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1056                 /* GPIO0 high for mic */
1057                 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1058                                      ucontrol->value.integer.value[0] ? 0 : 0x100);
1059         }
1060         return change;
1061 }
1062
1063 static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1064         AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1065         AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1066         AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1067         AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1068         /* 4: Analog Input To Surround */
1069         /* 5: Analog Input To Center/LFE */
1070         /* 6: Independent Master Volume Right */
1071         /* 7: Independent Master Volume Left */
1072         /* 8: reserved */
1073         AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1074         /* 10: mic, see below */
1075         /* 11-13: in IEC958 controls */
1076         AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1077 #if 0 /* always set in patch_alc650 */
1078         AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1079         AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1080         AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1081         AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1082         AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1083         AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1084 #endif
1085         {
1086                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1087                 .name = "Mic As Center/LFE",
1088                 .info = snd_ac97_info_single,
1089                 .get = snd_ac97_alc650_mic_get,
1090                 .put = snd_ac97_alc650_mic_put,
1091         },
1092 };
1093
1094 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1095         AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1096         AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1097         AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0),
1098 };
1099
1100 static int patch_alc650_specific(ac97_t * ac97)
1101 {
1102         int err;
1103
1104         if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1105                 return err;
1106         if (ac97->ext_id & AC97_EI_SPDIF) {
1107                 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1108                         return err;
1109         }
1110         return 0;
1111 }
1112
1113 static struct snd_ac97_build_ops patch_alc650_ops = {
1114         .build_specific = patch_alc650_specific
1115 };
1116
1117 int patch_alc650(ac97_t * ac97)
1118 {
1119         unsigned short val;
1120
1121         ac97->build_ops = &patch_alc650_ops;
1122
1123         /* revision E or F */
1124         /* FIXME: what about revision D ? */
1125         ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
1126                                 ac97->id == 0x414c4723);
1127
1128         /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1129         snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS, 
1130                 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
1131
1132         /* Enable SPDIF-IN only on Rev.E and above */
1133         val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
1134         /* SPDIF IN with pin 47 */
1135         if (ac97->spec.dev_flags)
1136                 val |= 0x03; /* enable */
1137         else
1138                 val &= ~0x03; /* disable */
1139         snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
1140
1141         /* set default: slot 3,4,7,8,6,9
1142            spdif-in monitor off, analog-spdif off, spdif-in off
1143            center on mic off, surround on line-in off
1144            downmix off, duplicate front off
1145         */
1146         snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
1147
1148         /* set GPIO0 for mic bias */
1149         /* GPIO0 pin output, no interrupt, high */
1150         snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
1151                              snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
1152         snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1153                              (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
1154
1155         /* full DAC volume */
1156         snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1157         snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1158         return 0;
1159 }
1160
1161 static int snd_ac97_alc655_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1162 {
1163         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1164         ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1165         return 0;
1166 }
1167
1168 static int snd_ac97_alc655_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1169 {
1170         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1171         int change;
1172
1173         /* misc control; vrefout disable */
1174         snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1175                              ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1176         change = snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1177                                       ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1178         return change;
1179 }
1180
1181
1182 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
1183         AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1184         AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1185         {
1186                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1187                 .name = "Mic As Center/LFE",
1188                 .info = snd_ac97_info_single,
1189                 .get = snd_ac97_alc655_mic_get,
1190                 .put = snd_ac97_alc655_mic_put,
1191         },
1192 };
1193
1194 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1195 {
1196         static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
1197         static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1198         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1199
1200         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1201         uinfo->count = 1;
1202         uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
1203         if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1204                 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1205         strcpy(uinfo->value.enumerated.name,
1206                ac97->spec.dev_flags ?
1207                texts_658[uinfo->value.enumerated.item] :
1208                texts_655[uinfo->value.enumerated.item]);
1209         return 0;
1210
1211 }
1212
1213 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1214 {
1215         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1216         unsigned short val;
1217
1218         val = ac97->regs[AC97_ALC650_MULTICH];
1219         val = (val >> 12) & 3;
1220         if (ac97->spec.dev_flags && val == 3)
1221                 val = 0;
1222         ucontrol->value.enumerated.item[0] = val;
1223         return 0;
1224 }
1225
1226 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1227 {
1228         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1229         return snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 3 << 12,
1230                                     (unsigned short)ucontrol->value.enumerated.item[0]);
1231 }
1232
1233 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
1234         AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1235         AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0),
1236         {
1237                 .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
1238                 .name   = "IEC958 Playback Route",
1239                 .info   = alc655_iec958_route_info,
1240                 .get    = alc655_iec958_route_get,
1241                 .put    = alc655_iec958_route_put,
1242         },
1243 };
1244
1245 static int patch_alc655_specific(ac97_t * ac97)
1246 {
1247         int err;
1248
1249         if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
1250                 return err;
1251         if (ac97->ext_id & AC97_EI_SPDIF) {
1252                 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1253                         return err;
1254         }
1255         return 0;
1256 }
1257
1258 static struct snd_ac97_build_ops patch_alc655_ops = {
1259         .build_specific = patch_alc655_specific
1260 };
1261
1262 int patch_alc655(ac97_t * ac97)
1263 {
1264         unsigned int val;
1265
1266         ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
1267
1268         ac97->build_ops = &patch_alc655_ops;
1269
1270         /* adjust default values */
1271         val = snd_ac97_read(ac97, 0x7a); /* misc control */
1272         val |= (1 << 1); /* spdif input pin */
1273         val &= ~(1 << 12); /* vref enable */
1274         snd_ac97_write_cache(ac97, 0x7a, val);
1275         /* set default: spdif-in enabled,
1276            spdif-in monitor off, spdif-in PCM off
1277            center on mic off, surround on line-in off
1278            duplicate front off
1279         */
1280         snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1281
1282         /* full DAC volume */
1283         snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1284         snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1285         return 0;
1286 }
1287
1288 /*
1289  * C-Media CM97xx codecs
1290  */
1291 static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
1292         AC97_SINGLE("Line-In As Surround", AC97_CM9738_VENDOR_CTRL, 10, 1, 0),
1293         AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
1294 };
1295
1296 static int patch_cm9738_specific(ac97_t * ac97)
1297 {
1298         return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
1299 }
1300
1301 static struct snd_ac97_build_ops patch_cm9738_ops = {
1302         .build_specific = patch_cm9738_specific
1303 };
1304
1305 int patch_cm9738(ac97_t * ac97)
1306 {
1307         ac97->build_ops = &patch_cm9738_ops;
1308         return 0;
1309 }
1310
1311 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1312 {
1313         static char *texts[] = { "Analog", "Digital" };
1314
1315         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1316         uinfo->count = 1;
1317         uinfo->value.enumerated.items = 2;
1318         if (uinfo->value.enumerated.item > 1)
1319                 uinfo->value.enumerated.item = 1;
1320         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1321         return 0;
1322 }
1323
1324 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1325 {
1326         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1327         unsigned short val;
1328
1329         val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
1330         ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
1331         return 0;
1332 }
1333
1334 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1335 {
1336         ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1337
1338         return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
1339                                     0x01 << 1, 
1340                                     (ucontrol->value.enumerated.item[0] & 0x01) << 1);
1341 }
1342
1343 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
1344         /* BIT 0: SPDI_EN - always true */
1345         { /* BIT 1: SPDIFS */
1346                 .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
1347                 .name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1348                 .info   = snd_ac97_cmedia_spdif_playback_source_info,
1349                 .get    = snd_ac97_cmedia_spdif_playback_source_get,
1350                 .put    = snd_ac97_cmedia_spdif_playback_source_put,
1351         },
1352         /* BIT 2: IG_SPIV */
1353         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
1354         /* BIT 3: SPI2F */
1355         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0), 
1356         /* BIT 4: SPI2SDI */
1357         AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
1358         /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
1359 };
1360
1361 static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
1362         AC97_SINGLE("Line-In As Surround", AC97_CM9739_MULTI_CHAN, 10, 1, 0),
1363 };
1364
1365 static int patch_cm9739_specific(ac97_t * ac97)
1366 {
1367         return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
1368 }
1369
1370 static int patch_cm9739_post_spdif(ac97_t * ac97)
1371 {
1372         return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
1373 }
1374
1375 static struct snd_ac97_build_ops patch_cm9739_ops = {
1376         .build_specific = patch_cm9739_specific,
1377         .build_post_spdif = patch_cm9739_post_spdif
1378 };
1379
1380 int patch_cm9739(ac97_t * ac97)
1381 {
1382         unsigned short val;
1383
1384         ac97->build_ops = &patch_cm9739_ops;
1385
1386         /* check spdif */
1387         val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
1388         if (val & AC97_EA_SPCV) {
1389                 /* enable spdif in */
1390                 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
1391                                      snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
1392         } else {
1393                 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
1394         }
1395
1396         /* set-up multi channel */
1397         /* bit 13: enable internal vref output for mic */
1398         /* bit 12: enable center/lfe */
1399         /* bit 14: 0 = SPDIF, 1 = EAPD */
1400         val = (1 << 12) | (1 << 13);
1401         if (! (ac97->ext_id & AC97_EI_SPDIF))
1402                 val |= (1 << 14);
1403         snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
1404
1405         /* FIXME: set up GPIO */
1406         snd_ac97_write_cache(ac97, 0x70, 0x0100);
1407         snd_ac97_write_cache(ac97, 0x72, 0x0020);
1408
1409         return 0;
1410 }
1411
1412 /*
1413  * VIA VT1616 codec
1414  */
1415 static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
1416 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
1417 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
1418 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
1419 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
1420 };
1421
1422 static int patch_vt1616_specific(ac97_t * ac97)
1423 {
1424         int err;
1425
1426         if (snd_ac97_try_bit(ac97, 0x5a, 9))
1427                 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
1428                         return err;
1429         if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
1430                 return err;
1431         return 0;
1432 }
1433
1434 static struct snd_ac97_build_ops patch_vt1616_ops = {
1435         .build_specific = patch_vt1616_specific
1436 };
1437
1438 int patch_vt1616(ac97_t * ac97)
1439 {
1440         ac97->build_ops = &patch_vt1616_ops;
1441         return 0;
1442 }
1443
1444 static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
1445         AC97_SINGLE("Line-In As Surround", 0x76, 9, 1, 0),
1446         AC97_SINGLE("Mic As Center/LFE", 0x76, 10, 1, 0),
1447 };
1448
1449 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
1450         AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
1451         AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
1452         AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
1453 };
1454
1455 static int patch_it2646_specific(ac97_t * ac97)
1456 {
1457         int err;
1458         if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
1459                 return err;
1460         if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
1461                 return err;
1462         return 0;
1463 }
1464
1465 static struct snd_ac97_build_ops patch_it2646_ops = {
1466         .build_specific = patch_it2646_specific
1467 };
1468
1469 int patch_it2646(ac97_t * ac97)
1470 {
1471         ac97->build_ops = &patch_it2646_ops;
1472         /* full DAC volume */
1473         snd_ac97_write_cache(ac97, 0x5E, 0x0808);
1474         snd_ac97_write_cache(ac97, 0x7A, 0x0808);
1475         return 0;
1476 }
1477
1478 /* Si3036/8 specific registers */
1479 #define AC97_SI3036_CHIP_ID     0x5a
1480
1481 int mpatch_si3036(ac97_t * ac97)
1482 {
1483         //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
1484         snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
1485         snd_ac97_write_cache(ac97, 0x68, 0);
1486         return 0;
1487 }