2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Universal interface for Audio Codec '97
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com) and to datasheets
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.
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.
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
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"
36 #include "ac97_local.h"
39 * Chip specific initialization
42 static int patch_build_controls(ac97_t
* ac97
, const snd_kcontrol_new_t
*controls
, int count
)
46 for (idx
= 0; idx
< count
; idx
++)
47 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&controls
[idx
], ac97
))) < 0)
52 /* set to the page, update bits and restore the page */
53 static int ac97_update_bits_page(ac97_t
*ac97
, unsigned short reg
, unsigned short mask
, unsigned short value
, unsigned short page
)
55 unsigned short page_save
;
58 down(&ac97
->page_mutex
);
59 page_save
= snd_ac97_read(ac97
, AC97_INT_PAGING
) & AC97_PAGE_MASK
;
60 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page
);
61 ret
= snd_ac97_update_bits(ac97
, reg
, mask
, value
);
62 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page_save
);
63 up(&ac97
->page_mutex
); /* unlock paging */
67 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
69 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
70 static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
72 static char *texts
[3] = {
73 "Standard", "Small", "Smaller"
76 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
78 uinfo
->value
.enumerated
.items
= 3;
79 if (uinfo
->value
.enumerated
.item
> 2)
80 uinfo
->value
.enumerated
.item
= 2;
81 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
85 static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
87 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
90 val
= ac97
->regs
[AC97_YMF753_3D_MODE_SEL
];
91 val
= (val
>> 10) & 3;
92 if (val
> 0) /* 0 = invalid */
94 ucontrol
->value
.enumerated
.item
[0] = val
;
98 static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
100 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
103 if (ucontrol
->value
.enumerated
.item
[0] > 2)
105 val
= (ucontrol
->value
.enumerated
.item
[0] + 1) << 10;
106 return snd_ac97_update(ac97
, AC97_YMF753_3D_MODE_SEL
, val
);
109 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker
=
111 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
112 .name
= "3D Control - Speaker",
113 .info
= snd_ac97_ymf753_info_speaker
,
114 .get
= snd_ac97_ymf753_get_speaker
,
115 .put
= snd_ac97_ymf753_put_speaker
,
118 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
119 static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
121 static char *texts
[2] = { "AC-Link", "A/D Converter" };
123 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
125 uinfo
->value
.enumerated
.items
= 2;
126 if (uinfo
->value
.enumerated
.item
> 1)
127 uinfo
->value
.enumerated
.item
= 1;
128 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
132 static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
134 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
137 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
138 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 1;
142 static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
144 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
147 if (ucontrol
->value
.enumerated
.item
[0] > 1)
149 val
= ucontrol
->value
.enumerated
.item
[0] << 1;
150 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0002, val
);
153 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
154 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
155 By default, no output pin is selected, and the S/PDIF signal is not output.
156 There is also a bit to mute S/PDIF output in a vendor-specific register. */
157 static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
159 static char *texts
[3] = { "Disabled", "Pin 43", "Pin 48" };
161 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
163 uinfo
->value
.enumerated
.items
= 3;
164 if (uinfo
->value
.enumerated
.item
> 2)
165 uinfo
->value
.enumerated
.item
= 2;
166 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
170 static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
172 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
175 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
176 ucontrol
->value
.enumerated
.item
[0] = (val
& 0x0008) ? 2 : (val
& 0x0020) ? 1 : 0;
180 static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
182 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
185 if (ucontrol
->value
.enumerated
.item
[0] > 2)
187 val
= (ucontrol
->value
.enumerated
.item
[0] == 2) ? 0x0008 :
188 (ucontrol
->value
.enumerated
.item
[0] == 1) ? 0x0020 : 0;
189 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0028, val
);
190 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
191 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
194 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif
[3] = {
196 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
197 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
198 .info
= snd_ac97_ymf753_spdif_source_info
,
199 .get
= snd_ac97_ymf753_spdif_source_get
,
200 .put
= snd_ac97_ymf753_spdif_source_put
,
203 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
204 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Output Pin",
205 .info
= snd_ac97_ymf753_spdif_output_pin_info
,
206 .get
= snd_ac97_ymf753_spdif_output_pin_get
,
207 .put
= snd_ac97_ymf753_spdif_output_pin_put
,
209 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE
,NONE
) "Mute", AC97_YMF753_DIT_CTRL2
, 2, 1, 1)
212 static int patch_yamaha_ymf753_3d(ac97_t
* ac97
)
214 snd_kcontrol_t
*kctl
;
217 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
219 strcpy(kctl
->id
.name
, "3D Control - Wide");
220 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 9, 7, 0);
221 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
222 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker
, ac97
))) < 0)
224 snd_ac97_write_cache(ac97
, AC97_YMF753_3D_MODE_SEL
, 0x0c00);
228 static int patch_yamaha_ymf753_post_spdif(ac97_t
* ac97
)
232 if ((err
= patch_build_controls(ac97
, snd_ac97_ymf753_controls_spdif
, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif
))) < 0)
237 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops
= {
238 .build_3d
= patch_yamaha_ymf753_3d
,
239 .build_post_spdif
= patch_yamaha_ymf753_post_spdif
242 int patch_yamaha_ymf753(ac97_t
* ac97
)
244 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
245 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
246 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
247 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
248 By default, no output pin is selected, and the S/PDIF signal is not output.
249 There is also a bit to mute S/PDIF output in a vendor-specific register.
251 ac97
->build_ops
= &patch_yamaha_ymf753_ops
;
252 ac97
->caps
|= AC97_BC_BASS_TREBLE
;
253 ac97
->caps
|= 0x04 << 10; /* Yamaha 3D enhancement */
258 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
259 * removed broken wolfson00 patch.
260 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
263 int patch_wolfson03(ac97_t
* ac97
)
265 /* This is known to work for the ViewSonic ViewPad 1000
266 Randolph Bentson <bentson@holmsjoen.com> */
268 // WM9703/9707/9708/9717
269 snd_ac97_write_cache(ac97
, AC97_WM97XX_FMIXER_VOL
, 0x0808);
270 snd_ac97_write_cache(ac97
, AC97_GENERAL_PURPOSE
, 0x8000);
274 int patch_wolfson04(ac97_t
* ac97
)
277 // set front and rear mixer volume
278 snd_ac97_write_cache(ac97
, AC97_WM97XX_FMIXER_VOL
, 0x0808);
279 snd_ac97_write_cache(ac97
, AC97_WM9704_RMIXER_VOL
, 0x0808);
281 // patch for DVD noise
282 snd_ac97_write_cache(ac97
, AC97_WM9704_TEST
, 0x0200);
285 snd_ac97_write_cache(ac97
, AC97_WM9704_RPCM_VOL
, 0x0808);
287 // set rear surround volume
288 snd_ac97_write_cache(ac97
, AC97_SURROUND_MASTER
, 0x0000);
292 int patch_wolfson05(ac97_t
* ac97
)
295 // set front mixer volume
296 snd_ac97_write_cache(ac97
, AC97_WM97XX_FMIXER_VOL
, 0x0808);
300 int patch_wolfson11(ac97_t
* ac97
)
304 snd_ac97_write_cache(ac97
, AC97_WM9711_OUT3VOL
, 0x0808);
308 static const char* wm9713_mic_mixer
[] = {"Stereo", "Mic1", "Mic2", "Mute"};
309 static const char* wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
310 static const char* wm9713_rec_src_l
[] = {"Mic1", "Mic2", "Line L", "Mono In", "HP Mix L", "Spk Mix", "Mono Mix", "Zh"};
311 static const char* wm9713_rec_src_r
[] = {"Mic1", "Mic2", "Line R", "Mono In", "HP Mix R", "Spk Mix", "Mono Mix", "Zh"};
313 static const struct ac97_enum wm9713_enum
[] = {
314 AC97_ENUM_SINGLE(AC97_LINE
, 3, 4, wm9713_mic_mixer
),
315 AC97_ENUM_SINGLE(AC97_VIDEO
, 14, 4, wm9713_rec_mux
),
316 AC97_ENUM_SINGLE(AC97_VIDEO
, 9, 4, wm9713_rec_mux
),
317 AC97_ENUM_SINGLE(AC97_VIDEO
, 3, 8, wm9713_rec_src_l
),
318 AC97_ENUM_SINGLE(AC97_VIDEO
, 0, 8, wm9713_rec_src_r
),
321 static const snd_kcontrol_new_t wm13_snd_ac97_controls_line_in
[] = {
322 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP
, 8, 0, 31, 1),
323 AC97_SINGLE("Line In to Headphone Mute", AC97_PC_BEEP
, 15, 1, 1),
324 AC97_SINGLE("Line In to Speaker Mute", AC97_PC_BEEP
, 14, 1, 1),
325 AC97_SINGLE("Line In to Mono Mute", AC97_PC_BEEP
, 13, 1, 1),
328 static const snd_kcontrol_new_t wm13_snd_ac97_controls_dac
[] = {
329 AC97_DOUBLE("DAC Volume", AC97_PHONE
, 8, 0, 31, 1),
330 AC97_SINGLE("DAC to Headphone Mute", AC97_PHONE
, 15, 1, 1),
331 AC97_SINGLE("DAC to Speaker Mute", AC97_PHONE
, 14, 1, 1),
332 AC97_SINGLE("DAC to Mono Mute", AC97_PHONE
, 13, 1, 1),
335 static const snd_kcontrol_new_t wm13_snd_ac97_controls_mic
[] = {
336 AC97_SINGLE("MICA Volume", AC97_MIC
, 8, 31, 1),
337 AC97_SINGLE("MICB Volume", AC97_MIC
, 0, 31, 1),
338 AC97_SINGLE("MICA to Mono Mute", AC97_LINE
, 7, 1, 1),
339 AC97_SINGLE("MICB to Mono Mute", AC97_LINE
, 6, 1, 1),
340 AC97_SINGLE("MIC Boost (+20dB)", AC97_LINE
, 5, 1, 1),
341 AC97_ENUM("MIC Headphone Routing", wm9713_enum
[0]),
342 AC97_SINGLE("MIC Headphone Mixer Volume", AC97_LINE
, 0, 7, 1)
345 static const snd_kcontrol_new_t wm13_snd_ac97_controls_adc
[] = {
346 AC97_SINGLE("ADC Mute", AC97_CD
, 15, 1, 1),
347 AC97_DOUBLE("Gain Step Size (1.5dB/0.75dB)", AC97_CD
, 14, 6, 1, 1),
348 AC97_DOUBLE("ADC Volume",AC97_CD
, 8, 0, 15, 0),
349 AC97_SINGLE("ADC Zero Cross", AC97_CD
, 7, 1, 1),
352 static const snd_kcontrol_new_t wm13_snd_ac97_controls_recsel
[] = {
353 AC97_ENUM("Record to Headphone Path", wm9713_enum
[1]),
354 AC97_SINGLE("Record to Headphone Volume", AC97_VIDEO
, 11, 7, 0),
355 AC97_ENUM("Record to Mono Path", wm9713_enum
[2]),
356 AC97_SINGLE("Record to Mono Boost (+20dB)", AC97_VIDEO
, 8, 1, 0),
357 AC97_SINGLE("Record ADC Boost (+20dB)", AC97_VIDEO
, 6, 1, 0),
358 AC97_ENUM("Record Select Left", wm9713_enum
[3]),
359 AC97_ENUM("Record Select Right", wm9713_enum
[4]),
362 static int patch_wolfson_wm9713_specific(ac97_t
* ac97
)
366 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_line_in
); i
++) {
367 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_line_in
[i
], ac97
))) < 0)
370 snd_ac97_write_cache(ac97
, AC97_PC_BEEP
, 0x0808);
372 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_dac
); i
++) {
373 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_dac
[i
], ac97
))) < 0)
376 snd_ac97_write_cache(ac97
, AC97_PHONE
, 0x0808);
378 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_mic
); i
++) {
379 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_mic
[i
], ac97
))) < 0)
382 snd_ac97_write_cache(ac97
, AC97_MIC
, 0x0808);
383 snd_ac97_write_cache(ac97
, AC97_LINE
, 0x00da);
385 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_adc
); i
++) {
386 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_adc
[i
], ac97
))) < 0)
389 snd_ac97_write_cache(ac97
, AC97_CD
, 0x0808);
391 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_recsel
); i
++) {
392 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_recsel
[i
], ac97
))) < 0)
395 snd_ac97_write_cache(ac97
, AC97_VIDEO
, 0xd612);
396 snd_ac97_write_cache(ac97
, AC97_REC_GAIN
, 0x1ba0);
402 static void patch_wolfson_wm9713_suspend (ac97_t
* ac97
)
404 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xfeff);
405 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0xffff);
408 static void patch_wolfson_wm9713_resume (ac97_t
* ac97
)
410 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
411 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
412 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
416 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops
= {
417 .build_specific
= patch_wolfson_wm9713_specific
,
419 .suspend
= patch_wolfson_wm9713_suspend
,
420 .resume
= patch_wolfson_wm9713_resume
424 int patch_wolfson13(ac97_t
* ac97
)
426 ac97
->build_ops
= &patch_wolfson_wm9713_ops
;
428 ac97
->flags
|= AC97_HAS_NO_REC_GAIN
| AC97_STEREO_MUTES
| AC97_HAS_NO_PHONE
|
429 AC97_HAS_NO_PC_BEEP
| AC97_HAS_NO_VIDEO
| AC97_HAS_NO_CD
;
431 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
432 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
433 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
441 int patch_tritech_tr28028(ac97_t
* ac97
)
443 snd_ac97_write_cache(ac97
, 0x26, 0x0300);
444 snd_ac97_write_cache(ac97
, 0x26, 0x0000);
445 snd_ac97_write_cache(ac97
, AC97_SURROUND_MASTER
, 0x0000);
446 snd_ac97_write_cache(ac97
, AC97_SPDIF
, 0x0000);
451 * Sigmatel STAC97xx codecs
453 static int patch_sigmatel_stac9700_3d(ac97_t
* ac97
)
455 snd_kcontrol_t
*kctl
;
458 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
460 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
461 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
462 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
466 static int patch_sigmatel_stac9708_3d(ac97_t
* ac97
)
468 snd_kcontrol_t
*kctl
;
471 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
473 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
474 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 0, 3, 0);
475 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
477 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Rear Depth");
478 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
479 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
483 static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker
=
484 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 2, 1, 0);
486 static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert
=
487 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 3, 1, 0);
489 static const snd_kcontrol_new_t snd_ac97_sigmatel_controls
[] = {
490 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 1, 1, 0),
491 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 0, 1, 0)
494 static int patch_sigmatel_stac97xx_specific(ac97_t
* ac97
)
498 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_ANALOG
, snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) & ~0x0003);
499 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 1))
500 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[0], 1)) < 0)
502 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 0))
503 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[1], 1)) < 0)
505 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 2))
506 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_4speaker
, 1)) < 0)
508 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 3))
509 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_phaseinvert
, 1)) < 0)
514 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops
= {
515 .build_3d
= patch_sigmatel_stac9700_3d
,
516 .build_specific
= patch_sigmatel_stac97xx_specific
519 int patch_sigmatel_stac9700(ac97_t
* ac97
)
521 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
525 static int snd_ac97_stac9708_put_bias(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
527 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
530 down(&ac97
->page_mutex
);
531 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
532 err
= snd_ac97_update_bits(ac97
, AC97_SIGMATEL_BIAS2
, 0x0010,
533 (ucontrol
->value
.integer
.value
[0] & 1) << 4);
534 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0);
535 up(&ac97
->page_mutex
);
539 static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control
= {
540 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
541 .name
= "Sigmatel Output Bias Switch",
542 .info
= snd_ac97_info_volsw
,
543 .get
= snd_ac97_get_volsw
,
544 .put
= snd_ac97_stac9708_put_bias
,
545 .private_value
= AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2
, 4, 1, 0),
548 static int patch_sigmatel_stac9708_specific(ac97_t
*ac97
)
552 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Sigmatel Surround Playback");
553 if ((err
= patch_build_controls(ac97
, &snd_ac97_stac9708_bias_control
, 1)) < 0)
555 return patch_sigmatel_stac97xx_specific(ac97
);
558 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops
= {
559 .build_3d
= patch_sigmatel_stac9708_3d
,
560 .build_specific
= patch_sigmatel_stac9708_specific
563 int patch_sigmatel_stac9708(ac97_t
* ac97
)
565 unsigned int codec72
, codec6c
;
567 ac97
->build_ops
= &patch_sigmatel_stac9708_ops
;
568 ac97
->caps
|= 0x10; /* HP (sigmatel surround) support */
570 codec72
= snd_ac97_read(ac97
, AC97_SIGMATEL_BIAS2
) & 0x8000;
571 codec6c
= snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
);
573 if ((codec72
==0) && (codec6c
==0)) {
574 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
575 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1000);
576 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
577 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0007);
578 } else if ((codec72
==0x8000) && (codec6c
==0)) {
579 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
580 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1001);
581 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_DAC2INVERT
, 0x0008);
582 } else if ((codec72
==0x8000) && (codec6c
==0x0080)) {
585 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
589 int patch_sigmatel_stac9721(ac97_t
* ac97
)
591 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
592 if (snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) == 0) {
593 // patch for SigmaTel
594 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
595 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x4000);
596 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
597 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
599 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
603 int patch_sigmatel_stac9744(ac97_t
* ac97
)
605 // patch for SigmaTel
606 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
607 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
608 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
609 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
610 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
611 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
615 int patch_sigmatel_stac9756(ac97_t
* ac97
)
617 // patch for SigmaTel
618 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
619 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
620 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
621 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
622 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
623 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
627 static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
629 static char *texts
[5] = { "Input/Disabled", "Front Output",
630 "Rear Output", "Center/LFE Output", "Mixer Output" };
632 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
634 uinfo
->value
.enumerated
.items
= 5;
635 if (uinfo
->value
.enumerated
.item
> 4)
636 uinfo
->value
.enumerated
.item
= 4;
637 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
641 static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
643 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
644 int shift
= kcontrol
->private_value
;
647 val
= ac97
->regs
[AC97_SIGMATEL_OUTSEL
] >> shift
;
649 ucontrol
->value
.enumerated
.item
[0] = 0;
651 ucontrol
->value
.enumerated
.item
[0] = 1 + (val
& 3);
655 static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
657 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
658 int shift
= kcontrol
->private_value
;
661 if (ucontrol
->value
.enumerated
.item
[0] > 4)
663 if (ucontrol
->value
.enumerated
.item
[0] == 0)
666 val
= 4 | (ucontrol
->value
.enumerated
.item
[0] - 1);
667 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_OUTSEL
,
668 7 << shift
, val
<< shift
, 0);
671 static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
673 static char *texts
[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
674 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
676 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
678 uinfo
->value
.enumerated
.items
= 7;
679 if (uinfo
->value
.enumerated
.item
> 6)
680 uinfo
->value
.enumerated
.item
= 6;
681 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
685 static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
687 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
688 int shift
= kcontrol
->private_value
;
691 val
= ac97
->regs
[AC97_SIGMATEL_INSEL
];
692 ucontrol
->value
.enumerated
.item
[0] = (val
>> shift
) & 7;
696 static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
698 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
699 int shift
= kcontrol
->private_value
;
701 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_INSEL
, 7 << shift
,
702 ucontrol
->value
.enumerated
.item
[0] << shift
, 0);
705 static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
707 static char *texts
[3] = { "None", "Front Jack", "Rear Jack" };
709 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
711 uinfo
->value
.enumerated
.items
= 3;
712 if (uinfo
->value
.enumerated
.item
> 2)
713 uinfo
->value
.enumerated
.item
= 2;
714 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
718 static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
720 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
722 ucontrol
->value
.enumerated
.item
[0] = ac97
->regs
[AC97_SIGMATEL_IOMISC
] & 3;
726 static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
728 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
730 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_IOMISC
, 3,
731 ucontrol
->value
.enumerated
.item
[0], 0);
734 #define STAC9758_OUTPUT_JACK(xname, shift) \
735 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
736 .info = snd_ac97_stac9758_output_jack_info, \
737 .get = snd_ac97_stac9758_output_jack_get, \
738 .put = snd_ac97_stac9758_output_jack_put, \
739 .private_value = shift }
740 #define STAC9758_INPUT_JACK(xname, shift) \
741 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
742 .info = snd_ac97_stac9758_input_jack_info, \
743 .get = snd_ac97_stac9758_input_jack_get, \
744 .put = snd_ac97_stac9758_input_jack_put, \
745 .private_value = shift }
746 static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls
[] = {
747 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
748 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
749 STAC9758_OUTPUT_JACK("Front Jack", 7),
750 STAC9758_OUTPUT_JACK("Rear Jack", 10),
751 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
752 STAC9758_INPUT_JACK("Mic Input Source", 0),
753 STAC9758_INPUT_JACK("Line Input Source", 8),
755 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
756 .name
= "Headphone Amp",
757 .info
= snd_ac97_stac9758_phonesel_info
,
758 .get
= snd_ac97_stac9758_phonesel_get
,
759 .put
= snd_ac97_stac9758_phonesel_put
761 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC
, 4, 1, 0),
762 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC
, 8, 1, 0)
765 static int patch_sigmatel_stac9758_specific(ac97_t
*ac97
)
769 err
= patch_sigmatel_stac97xx_specific(ac97
);
772 err
= patch_build_controls(ac97
, snd_ac97_sigmatel_stac9758_controls
,
773 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls
));
777 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Front Playback");
778 /* DAC-A to Mix = PCM */
779 /* DAC-B direct = Surround */
781 snd_ac97_rename_vol_ctl(ac97
, "Video Playback", "Surround Mix Playback");
782 /* DAC-C direct = Center/LFE */
787 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops
= {
788 .build_3d
= patch_sigmatel_stac9700_3d
,
789 .build_specific
= patch_sigmatel_stac9758_specific
792 int patch_sigmatel_stac9758(ac97_t
* ac97
)
794 static unsigned short regs
[4] = {
795 AC97_SIGMATEL_OUTSEL
,
796 AC97_SIGMATEL_IOMISC
,
798 AC97_SIGMATEL_VARIOUS
800 static unsigned short def_regs
[4] = {
801 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
803 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
806 static unsigned short m675_regs
[4] = {
807 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
808 /* IOMISC */ 0x2102, /* HP amp on */
809 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
810 /* VARIOUS */ 0x0041 /* stereo mic */
812 unsigned short *pregs
= def_regs
;
815 /* Gateway M675 notebook */
817 ac97
->subsystem_vendor
== 0x107b &&
818 ac97
->subsystem_device
== 0x0601)
821 // patch for SigmaTel
822 ac97
->build_ops
= &patch_sigmatel_stac9758_ops
;
823 /* FIXME: assume only page 0 for writing cache */
824 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
825 for (i
= 0; i
< 4; i
++)
826 snd_ac97_write_cache(ac97
, regs
[i
], pregs
[i
]);
828 ac97
->flags
|= AC97_STEREO_MUTES
;
833 * Cirrus Logic CS42xx codecs
835 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif
[2] = {
836 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CSR_SPDIF
, 15, 1, 0),
837 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "AC97-SPSA", AC97_CSR_ACMODE
, 0, 3, 0)
840 static int patch_cirrus_build_spdif(ac97_t
* ac97
)
844 /* con mask, pro mask, default */
845 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
848 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[0], 1)) < 0)
850 switch (ac97
->id
& AC97_ID_CS_MASK
) {
852 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[1], 1)) < 0)
856 /* set default PCM S/PDIF params */
857 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
858 snd_ac97_write_cache(ac97
, AC97_CSR_SPDIF
, 0x0a20);
862 static struct snd_ac97_build_ops patch_cirrus_ops
= {
863 .build_spdif
= patch_cirrus_build_spdif
866 int patch_cirrus_spdif(ac97_t
* ac97
)
868 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
869 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
870 - sp/dif EA ID is not set, but sp/dif is always present.
871 - enable/disable is spdif register bit 15.
872 - sp/dif control register is 0x68. differs from AC97:
873 - valid is bit 14 (vs 15)
875 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
876 - sp/dif ssource select is in 0x5e bits 0,1.
879 ac97
->build_ops
= &patch_cirrus_ops
;
880 ac97
->flags
|= AC97_CS_SPDIF
;
881 ac97
->rates
[AC97_RATES_SPDIF
] &= ~SNDRV_PCM_RATE_32000
;
882 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
883 snd_ac97_write_cache(ac97
, AC97_CSR_ACMODE
, 0x0080);
887 int patch_cirrus_cs4299(ac97_t
* ac97
)
889 /* force the detection of PC Beep */
890 ac97
->flags
|= AC97_HAS_PC_BEEP
;
892 return patch_cirrus_spdif(ac97
);
898 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif
[1] = {
899 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CXR_AUDIO_MISC
, 3, 1, 0),
902 static int patch_conexant_build_spdif(ac97_t
* ac97
)
906 /* con mask, pro mask, default */
907 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
910 if ((err
= patch_build_controls(ac97
, &snd_ac97_conexant_controls_spdif
[0], 1)) < 0)
912 /* set default PCM S/PDIF params */
913 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
914 snd_ac97_write_cache(ac97
, AC97_CXR_AUDIO_MISC
,
915 snd_ac97_read(ac97
, AC97_CXR_AUDIO_MISC
) & ~(AC97_CXR_SPDIFEN
|AC97_CXR_COPYRGT
|AC97_CXR_SPDIF_MASK
));
919 static struct snd_ac97_build_ops patch_conexant_ops
= {
920 .build_spdif
= patch_conexant_build_spdif
923 int patch_conexant(ac97_t
* ac97
)
925 ac97
->build_ops
= &patch_conexant_ops
;
926 ac97
->flags
|= AC97_CX_SPDIF
;
927 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
928 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
933 * Analog Device AD18xx, AD19xx codecs
936 static void ad18xx_resume(ac97_t
*ac97
)
938 static unsigned short setup_regs
[] = {
939 AC97_AD_MISC
, AC97_AD_SERIAL_CFG
, AC97_AD_JACK_SPDIF
,
943 for (i
= 0; i
< (int)ARRAY_SIZE(setup_regs
); i
++) {
944 unsigned short reg
= setup_regs
[i
];
945 if (test_bit(reg
, ac97
->reg_accessed
)) {
946 snd_ac97_write(ac97
, reg
, ac97
->regs
[reg
]);
947 snd_ac97_read(ac97
, reg
);
951 if (! (ac97
->flags
& AC97_AD_MULTI
))
953 snd_ac97_restore_status(ac97
);
955 /* restore the AD18xx codec configurations */
956 for (codec
= 0; codec
< 3; codec
++) {
957 if (! ac97
->spec
.ad18xx
.id
[codec
])
959 /* select single codec */
960 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
961 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
962 ac97
->bus
->ops
->write(ac97
, AC97_AD_CODEC_CFG
, ac97
->spec
.ad18xx
.codec_cfg
[codec
]);
964 /* select all codecs */
965 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
968 for (i
= 2; i
< 0x7c ; i
+= 2) {
969 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_ID
)
971 if (test_bit(i
, ac97
->reg_accessed
)) {
972 /* handle multi codecs for AD18xx */
974 for (codec
= 0; codec
< 3; codec
++) {
975 if (! ac97
->spec
.ad18xx
.id
[codec
])
977 /* select single codec */
978 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
979 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
980 /* update PCM bits */
981 ac97
->bus
->ops
->write(ac97
, AC97_PCM
, ac97
->spec
.ad18xx
.pcmreg
[codec
]);
983 /* select all codecs */
984 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
986 } else if (i
== AC97_AD_TEST
||
987 i
== AC97_AD_CODEC_CFG
||
988 i
== AC97_AD_SERIAL_CFG
)
989 continue; /* ignore */
991 snd_ac97_write(ac97
, i
, ac97
->regs
[i
]);
992 snd_ac97_read(ac97
, i
);
996 snd_ac97_restore_iec958(ac97
);
1000 int patch_ad1819(ac97_t
* ac97
)
1002 unsigned short scfg
;
1004 // patch for Analog Devices
1005 scfg
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1006 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, scfg
| 0x7000); /* select all codecs */
1010 static unsigned short patch_ad1881_unchained(ac97_t
* ac97
, int idx
, unsigned short mask
)
1014 // test for unchained codec
1015 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, mask
);
1016 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000); /* ID0C, ID1C, SDIE = off */
1017 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1018 if ((val
& 0xff40) != 0x5340)
1020 ac97
->spec
.ad18xx
.unchained
[idx
] = mask
;
1021 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1022 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = 0x0000;
1026 static int patch_ad1881_chained1(ac97_t
* ac97
, int idx
, unsigned short codec_bits
)
1028 static int cfg_bits
[3] = { 1<<12, 1<<14, 1<<13 };
1031 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, cfg_bits
[idx
]);
1032 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0004); // SDIE
1033 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1034 if ((val
& 0xff40) != 0x5340)
1037 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, codec_bits
);
1038 ac97
->spec
.ad18xx
.chained
[idx
] = cfg_bits
[idx
];
1039 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1040 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = codec_bits
? codec_bits
: 0x0004;
1044 static void patch_ad1881_chained(ac97_t
* ac97
, int unchained_idx
, int cidx1
, int cidx2
)
1046 // already detected?
1047 if (ac97
->spec
.ad18xx
.unchained
[cidx1
] || ac97
->spec
.ad18xx
.chained
[cidx1
])
1049 if (ac97
->spec
.ad18xx
.unchained
[cidx2
] || ac97
->spec
.ad18xx
.chained
[cidx2
])
1051 if (cidx1
< 0 && cidx2
< 0)
1053 // test for chained codecs
1054 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1055 ac97
->spec
.ad18xx
.unchained
[unchained_idx
]);
1056 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0002); // ID1C
1057 ac97
->spec
.ad18xx
.codec_cfg
[unchained_idx
] = 0x0002;
1059 if (patch_ad1881_chained1(ac97
, cidx1
, 0x0006)) // SDIE | ID1C
1060 patch_ad1881_chained1(ac97
, cidx2
, 0);
1061 else if (patch_ad1881_chained1(ac97
, cidx2
, 0x0006)) // SDIE | ID1C
1062 patch_ad1881_chained1(ac97
, cidx1
, 0);
1063 } else if (cidx2
>= 0) {
1064 patch_ad1881_chained1(ac97
, cidx2
, 0);
1068 static struct snd_ac97_build_ops patch_ad1881_build_ops
= {
1070 .resume
= ad18xx_resume
1074 int patch_ad1881(ac97_t
* ac97
)
1076 static const char cfg_idxs
[3][2] = {
1082 // patch for Analog Devices
1083 unsigned short codecs
[3];
1087 val
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1088 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, val
);
1089 codecs
[0] = patch_ad1881_unchained(ac97
, 0, (1<<12));
1090 codecs
[1] = patch_ad1881_unchained(ac97
, 1, (1<<14));
1091 codecs
[2] = patch_ad1881_unchained(ac97
, 2, (1<<13));
1093 snd_runtime_check(codecs
[0] | codecs
[1] | codecs
[2], goto __end
);
1095 for (idx
= 0; idx
< 3; idx
++)
1096 if (ac97
->spec
.ad18xx
.unchained
[idx
])
1097 patch_ad1881_chained(ac97
, idx
, cfg_idxs
[idx
][0], cfg_idxs
[idx
][1]);
1099 if (ac97
->spec
.ad18xx
.id
[1]) {
1100 ac97
->flags
|= AC97_AD_MULTI
;
1101 ac97
->scaps
|= AC97_SCAP_SURROUND_DAC
;
1103 if (ac97
->spec
.ad18xx
.id
[2]) {
1104 ac97
->flags
|= AC97_AD_MULTI
;
1105 ac97
->scaps
|= AC97_SCAP_CENTER_LFE_DAC
;
1109 /* select all codecs */
1110 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1111 /* check if only one codec is present */
1112 for (idx
= num
= 0; idx
< 3; idx
++)
1113 if (ac97
->spec
.ad18xx
.id
[idx
])
1116 /* ok, deselect all ID bits */
1117 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000);
1118 ac97
->spec
.ad18xx
.codec_cfg
[0] =
1119 ac97
->spec
.ad18xx
.codec_cfg
[1] =
1120 ac97
->spec
.ad18xx
.codec_cfg
[2] = 0x0000;
1122 /* required for AD1886/AD1885 combination */
1123 ac97
->ext_id
= snd_ac97_read(ac97
, AC97_EXTENDED_ID
);
1124 if (ac97
->spec
.ad18xx
.id
[0]) {
1125 ac97
->id
&= 0xffff0000;
1126 ac97
->id
|= ac97
->spec
.ad18xx
.id
[0];
1128 ac97
->build_ops
= &patch_ad1881_build_ops
;
1132 static const snd_kcontrol_new_t snd_ac97_controls_ad1885
[] = {
1133 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC
, 11, 1, 0),
1134 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1135 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC
, 14, 1, 0),
1136 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC
, 15, 1, 0),
1137 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 9, 1, 1), /* inverted */
1138 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 8, 1, 1), /* inverted */
1141 static int patch_ad1885_specific(ac97_t
* ac97
)
1145 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_ad1885
, ARRAY_SIZE(snd_ac97_controls_ad1885
))) < 0)
1150 static struct snd_ac97_build_ops patch_ad1885_build_ops
= {
1151 .build_specific
= &patch_ad1885_specific
,
1153 .resume
= ad18xx_resume
1157 int patch_ad1885(ac97_t
* ac97
)
1160 /* This is required to deal with the Intel D815EEAL2 */
1161 /* i.e. Line out is actually headphone out from codec */
1164 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, 0x0404);
1166 ac97
->build_ops
= &patch_ad1885_build_ops
;
1170 int patch_ad1886(ac97_t
* ac97
)
1173 /* Presario700 workaround */
1174 /* for Jack Sense/SPDIF Register misetting causing */
1175 snd_ac97_write_cache(ac97
, AC97_AD_JACK_SPDIF
, 0x0010);
1180 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1181 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1182 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1183 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1184 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1185 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1186 #define AC97_AD198X_VREF_0 0x000c /* 0V */
1187 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1188 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1189 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1190 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1191 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1192 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1193 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1194 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1195 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1196 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1197 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1198 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1201 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1203 static char *texts
[2] = { "AC-Link", "A/D Converter" };
1205 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1207 uinfo
->value
.enumerated
.items
= 2;
1208 if (uinfo
->value
.enumerated
.item
> 1)
1209 uinfo
->value
.enumerated
.item
= 1;
1210 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1214 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1216 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1219 val
= ac97
->regs
[AC97_AD_SERIAL_CFG
];
1220 ucontrol
->value
.enumerated
.item
[0] = (val
>> 2) & 1;
1224 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1226 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1229 if (ucontrol
->value
.enumerated
.item
[0] > 1)
1231 val
= ucontrol
->value
.enumerated
.item
[0] << 2;
1232 return snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x0004, val
);
1235 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source
= {
1236 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1237 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
1238 .info
= snd_ac97_ad198x_spdif_source_info
,
1239 .get
= snd_ac97_ad198x_spdif_source_get
,
1240 .put
= snd_ac97_ad198x_spdif_source_put
,
1243 static int patch_ad198x_post_spdif(ac97_t
* ac97
)
1245 return patch_build_controls(ac97
, &snd_ac97_ad198x_spdif_source
, 1);
1248 static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense
[] = {
1249 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 11, 1, 0),
1250 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
1253 static int patch_ad1981a_specific(ac97_t
* ac97
)
1255 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1256 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1259 static struct snd_ac97_build_ops patch_ad1981a_build_ops
= {
1260 .build_post_spdif
= patch_ad198x_post_spdif
,
1261 .build_specific
= patch_ad1981a_specific
,
1263 .resume
= ad18xx_resume
1267 static void check_ad1981_hp_jack_sense(ac97_t
*ac97
)
1269 u32 subid
= ((u32
)ac97
->subsystem_vendor
<< 16) | ac97
->subsystem_device
;
1271 case 0x103c0890: /* HP nc6000 */
1272 case 0x103c006d: /* HP nx9105 */
1273 case 0x17340088: /* FSC Scenic-W */
1274 /* enable headphone jack sense */
1275 snd_ac97_update_bits(ac97
, AC97_AD_JACK_SPDIF
, 1<<11, 1<<11);
1280 int patch_ad1981a(ac97_t
*ac97
)
1283 ac97
->build_ops
= &patch_ad1981a_build_ops
;
1284 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1285 ac97
->flags
|= AC97_STEREO_MUTES
;
1286 check_ad1981_hp_jack_sense(ac97
);
1290 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic
=
1291 AC97_SINGLE("Stereo Mic", AC97_AD_MISC
, 6, 1, 0);
1293 static int patch_ad1981b_specific(ac97_t
*ac97
)
1297 if ((err
= patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1)) < 0)
1299 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1300 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1303 static struct snd_ac97_build_ops patch_ad1981b_build_ops
= {
1304 .build_post_spdif
= patch_ad198x_post_spdif
,
1305 .build_specific
= patch_ad1981b_specific
,
1307 .resume
= ad18xx_resume
1311 int patch_ad1981b(ac97_t
*ac97
)
1314 ac97
->build_ops
= &patch_ad1981b_build_ops
;
1315 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1316 ac97
->flags
|= AC97_STEREO_MUTES
;
1317 check_ad1981_hp_jack_sense(ac97
);
1321 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1323 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1325 uinfo
->value
.integer
.min
= 0;
1326 uinfo
->value
.integer
.max
= 1;
1330 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1332 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1335 val
= ac97
->regs
[AC97_AD_MISC
];
1336 ucontrol
->value
.integer
.value
[0] = !(val
& AC97_AD198X_LOSEL
);
1340 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1342 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1345 val
= !ucontrol
->value
.integer
.value
[0]
1346 ? (AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
) : 0;
1347 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1348 AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
, val
);
1351 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1353 static char *texts
[3] = {"Off", "6 -> 4", "6 -> 2"};
1355 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1357 uinfo
->value
.enumerated
.items
= 3;
1358 if (uinfo
->value
.enumerated
.item
> 2)
1359 uinfo
->value
.enumerated
.item
= 2;
1360 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1364 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1366 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1369 val
= ac97
->regs
[AC97_AD_MISC
];
1370 if (!(val
& AC97_AD198X_DMIX1
))
1371 ucontrol
->value
.enumerated
.item
[0] = 0;
1373 ucontrol
->value
.enumerated
.item
[0] = 1 + ((val
>> 8) & 1);
1377 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1379 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1382 if (ucontrol
->value
.enumerated
.item
[0] > 2)
1384 if (ucontrol
->value
.enumerated
.item
[0] == 0)
1387 val
= AC97_AD198X_DMIX1
|
1388 ((ucontrol
->value
.enumerated
.item
[0] - 1) << 8);
1389 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1390 AC97_AD198X_DMIX0
| AC97_AD198X_DMIX1
, val
);
1393 static const snd_kcontrol_new_t snd_ac97_ad1888_controls
[] = {
1395 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1396 .name
= "Exchange Front/Surround",
1397 .info
= snd_ac97_ad1888_lohpsel_info
,
1398 .get
= snd_ac97_ad1888_lohpsel_get
,
1399 .put
= snd_ac97_ad1888_lohpsel_put
1401 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC
, 7, 1, 0),
1403 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1405 .info
= snd_ac97_ad1888_downmix_info
,
1406 .get
= snd_ac97_ad1888_downmix_get
,
1407 .put
= snd_ac97_ad1888_downmix_put
1409 AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC
, 12, 1, 0),
1410 AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC
, 11, 1, 0),
1413 static int patch_ad1888_specific(ac97_t
*ac97
)
1415 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1416 snd_ac97_rename_vol_ctl(ac97
, "Master Playback", "Master Surround Playback");
1417 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Master Playback");
1418 return patch_build_controls(ac97
, snd_ac97_ad1888_controls
, ARRAY_SIZE(snd_ac97_ad1888_controls
));
1421 static struct snd_ac97_build_ops patch_ad1888_build_ops
= {
1422 .build_post_spdif
= patch_ad198x_post_spdif
,
1423 .build_specific
= patch_ad1888_specific
,
1425 .resume
= ad18xx_resume
1429 int patch_ad1888(ac97_t
* ac97
)
1431 unsigned short misc
;
1434 ac97
->build_ops
= &patch_ad1888_build_ops
;
1435 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1436 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1437 /* AD-compatible mode */
1438 /* Stereo mutes enabled */
1439 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
1440 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
1444 AC97_AD198X_AC97NC
);
1445 ac97
->flags
|= AC97_STEREO_MUTES
;
1449 static int patch_ad1980_specific(ac97_t
*ac97
)
1453 if ((err
= patch_ad1888_specific(ac97
)) < 0)
1455 return patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1);
1458 static struct snd_ac97_build_ops patch_ad1980_build_ops
= {
1459 .build_post_spdif
= patch_ad198x_post_spdif
,
1460 .build_specific
= patch_ad1980_specific
,
1462 .resume
= ad18xx_resume
1466 int patch_ad1980(ac97_t
* ac97
)
1469 ac97
->build_ops
= &patch_ad1980_build_ops
;
1473 static const snd_kcontrol_new_t snd_ac97_ad1985_controls
[] = {
1474 AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG
, 9, 1, 0),
1475 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG
, 3, 1, 0)
1478 static int patch_ad1985_specific(ac97_t
*ac97
)
1482 if ((err
= patch_ad1980_specific(ac97
)) < 0)
1484 return patch_build_controls(ac97
, snd_ac97_ad1985_controls
, ARRAY_SIZE(snd_ac97_ad1985_controls
));
1487 static struct snd_ac97_build_ops patch_ad1985_build_ops
= {
1488 .build_post_spdif
= patch_ad198x_post_spdif
,
1489 .build_specific
= patch_ad1985_specific
,
1491 .resume
= ad18xx_resume
1495 int patch_ad1985(ac97_t
* ac97
)
1497 unsigned short misc
;
1500 ac97
->build_ops
= &patch_ad1985_build_ops
;
1501 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
1502 /* switch front/surround line-out/hp-out */
1503 /* center/LFE, mic in 3.75V mode */
1504 /* AD-compatible mode */
1505 /* Stereo mutes enabled */
1506 /* in accordance with ADI driver: misc | 0x5c28 */
1507 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
1514 AC97_AD198X_AC97NC
);
1515 ac97
->flags
|= AC97_STEREO_MUTES
;
1516 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1517 ac97
->ext_id
= (ac97
->ext_id
& ~AC97_EI_REV_MASK
) | AC97_EI_REV_23
;
1522 * realtek ALC65x/850 codecs
1524 static int snd_ac97_alc650_mic_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1526 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1527 ucontrol
->value
.integer
.value
[0] = (ac97
->regs
[AC97_ALC650_MULTICH
] >> 10) & 1;
1531 static int snd_ac97_alc650_mic_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1533 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1535 val
= !!(snd_ac97_read(ac97
, AC97_ALC650_MULTICH
) & (1 << 10));
1536 change
= (ucontrol
->value
.integer
.value
[0] != val
);
1538 /* disable/enable vref */
1539 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
1540 ucontrol
->value
.integer
.value
[0] ? (1 << 12) : 0);
1541 /* turn on/off center-on-mic */
1542 snd_ac97_update_bits(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
1543 ucontrol
->value
.integer
.value
[0] ? (1 << 10) : 0);
1544 /* GPIO0 high for mic */
1545 snd_ac97_update_bits(ac97
, AC97_ALC650_GPIO_STATUS
, 0x100,
1546 ucontrol
->value
.integer
.value
[0] ? 0 : 0x100);
1551 static const snd_kcontrol_new_t snd_ac97_controls_alc650
[] = {
1552 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0),
1553 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH
, 1, 1, 0),
1554 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH
, 2, 1, 0),
1555 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH
, 3, 1, 0),
1556 /* 4: Analog Input To Surround */
1557 /* 5: Analog Input To Center/LFE */
1558 /* 6: Independent Master Volume Right */
1559 /* 7: Independent Master Volume Left */
1561 AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH
, 9, 1, 0),
1562 /* 10: mic, see below */
1563 /* 11-13: in IEC958 controls */
1564 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH
, 14, 1, 0),
1565 #if 0 /* always set in patch_alc650 */
1566 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK
, 0, 1, 0),
1567 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK
, 1, 1, 0),
1568 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL
, 15, 1, 1),
1569 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL
, 8, 0, 31, 1),
1570 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL
, 15, 1, 1),
1571 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL
, 8, 0, 31, 1),
1574 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1575 .name
= "Mic As Center/LFE",
1576 .info
= snd_ac97_info_volsw
,
1577 .get
= snd_ac97_alc650_mic_get
,
1578 .put
= snd_ac97_alc650_mic_put
,
1579 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1583 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650
[] = {
1584 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH
, 11, 1, 0),
1585 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH
, 12, 1, 0),
1586 /* disable this controls since it doesn't work as expected */
1587 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
1590 static int patch_alc650_specific(ac97_t
* ac97
)
1594 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc650
, ARRAY_SIZE(snd_ac97_controls_alc650
))) < 0)
1596 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
1597 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc650
, ARRAY_SIZE(snd_ac97_spdif_controls_alc650
))) < 0)
1603 static struct snd_ac97_build_ops patch_alc650_ops
= {
1604 .build_specific
= patch_alc650_specific
1607 int patch_alc650(ac97_t
* ac97
)
1611 ac97
->build_ops
= &patch_alc650_ops
;
1613 /* determine the revision */
1614 val
= snd_ac97_read(ac97
, AC97_ALC650_REVISION
) & 0x3f;
1616 ac97
->id
= 0x414c4720; /* Old version */
1617 else if (val
< 0x10)
1618 ac97
->id
= 0x414c4721; /* D version */
1619 else if (val
< 0x20)
1620 ac97
->id
= 0x414c4722; /* E version */
1621 else if (val
< 0x30)
1622 ac97
->id
= 0x414c4723; /* F version */
1624 /* revision E or F */
1625 /* FIXME: what about revision D ? */
1626 ac97
->spec
.dev_flags
= (ac97
->id
== 0x414c4722 ||
1627 ac97
->id
== 0x414c4723);
1629 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1630 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
1631 snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x8000);
1633 /* Enable SPDIF-IN only on Rev.E and above */
1634 val
= snd_ac97_read(ac97
, AC97_ALC650_CLOCK
);
1635 /* SPDIF IN with pin 47 */
1636 if (ac97
->spec
.dev_flags
)
1637 val
|= 0x03; /* enable */
1639 val
&= ~0x03; /* disable */
1640 snd_ac97_write_cache(ac97
, AC97_ALC650_CLOCK
, val
);
1642 /* set default: slot 3,4,7,8,6,9
1643 spdif-in monitor off, analog-spdif off, spdif-in off
1644 center on mic off, surround on line-in off
1645 downmix off, duplicate front off
1647 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 0);
1649 /* set GPIO0 for mic bias */
1650 /* GPIO0 pin output, no interrupt, high */
1651 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_SETUP
,
1652 snd_ac97_read(ac97
, AC97_ALC650_GPIO_SETUP
) | 0x01);
1653 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
1654 (snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x100) & ~0x10);
1656 /* full DAC volume */
1657 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
1658 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
1662 static int snd_ac97_alc655_mic_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1664 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1665 ucontrol
->value
.integer
.value
[0] = (ac97
->regs
[AC97_ALC650_MULTICH
] >> 10) & 1;
1669 static int snd_ac97_alc655_mic_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1671 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1673 /* misc control; vrefout disable */
1674 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
1675 ucontrol
->value
.integer
.value
[0] ? (1 << 12) : 0);
1676 return ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
1677 ucontrol
->value
.integer
.value
[0] ? (1 << 10) : 0,
1682 static const snd_kcontrol_new_t snd_ac97_controls_alc655
[] = {
1683 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
1684 AC97_PAGE_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH
, 9, 1, 0, 0),
1686 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1687 .name
= "Mic As Center/LFE",
1688 .info
= snd_ac97_info_volsw
,
1689 .get
= snd_ac97_alc655_mic_get
,
1690 .put
= snd_ac97_alc655_mic_put
,
1691 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1695 static int alc655_iec958_route_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
*uinfo
)
1697 static char *texts_655
[3] = { "PCM", "Analog In", "IEC958 In" };
1698 static char *texts_658
[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1699 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1701 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1703 uinfo
->value
.enumerated
.items
= ac97
->spec
.dev_flags
? 4 : 3;
1704 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1705 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1706 strcpy(uinfo
->value
.enumerated
.name
,
1707 ac97
->spec
.dev_flags
?
1708 texts_658
[uinfo
->value
.enumerated
.item
] :
1709 texts_655
[uinfo
->value
.enumerated
.item
]);
1713 static int alc655_iec958_route_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1715 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1718 val
= ac97
->regs
[AC97_ALC650_MULTICH
];
1719 val
= (val
>> 12) & 3;
1720 if (ac97
->spec
.dev_flags
&& val
== 3)
1722 ucontrol
->value
.enumerated
.item
[0] = val
;
1726 static int alc655_iec958_route_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
*ucontrol
)
1728 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1730 return ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 3 << 12,
1731 (unsigned short)ucontrol
->value
.enumerated
.item
[0] << 12,
1735 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655
[] = {
1736 AC97_PAGE_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH
, 11, 1, 0, 0),
1737 /* disable this controls since it doesn't work as expected */
1738 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
1740 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1741 .name
= "IEC958 Playback Route",
1742 .info
= alc655_iec958_route_info
,
1743 .get
= alc655_iec958_route_get
,
1744 .put
= alc655_iec958_route_put
,
1748 static int patch_alc655_specific(ac97_t
* ac97
)
1752 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc655
, ARRAY_SIZE(snd_ac97_controls_alc655
))) < 0)
1754 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
1755 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
1761 static struct snd_ac97_build_ops patch_alc655_ops
= {
1762 .build_specific
= patch_alc655_specific
1765 int patch_alc655(ac97_t
* ac97
)
1769 ac97
->spec
.dev_flags
= (ac97
->id
== 0x414c4780); /* ALC658 */
1771 ac97
->build_ops
= &patch_alc655_ops
;
1773 /* assume only page 0 for writing cache */
1774 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
1776 /* adjust default values */
1777 val
= snd_ac97_read(ac97
, 0x7a); /* misc control */
1778 if (ac97
->id
== 0x414c4780) /* ALC658 */
1779 val
&= ~(1 << 1); /* Pin 47 is spdif input pin */
1781 val
|= (1 << 1); /* Pin 47 is spdif input pin */
1782 val
&= ~(1 << 12); /* vref enable */
1783 snd_ac97_write_cache(ac97
, 0x7a, val
);
1784 /* set default: spdif-in enabled,
1785 spdif-in monitor off, spdif-in PCM off
1786 center on mic off, surround on line-in off
1789 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
1791 /* full DAC volume */
1792 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
1793 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
1798 #define AC97_ALC850_JACK_SELECT 0x76
1799 #define AC97_ALC850_MISC1 0x7a
1801 static int ac97_alc850_surround_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1803 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1804 ucontrol
->value
.integer
.value
[0] = ((ac97
->regs
[AC97_ALC850_JACK_SELECT
] >> 12) & 7) == 2;
1808 static int ac97_alc850_surround_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1810 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1812 /* SURR 1kOhm (bit4), Amp (bit5) */
1813 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<4)|(1<<5),
1814 ucontrol
->value
.integer
.value
[0] ? (1<<5) : (1<<4));
1815 /* LINE-IN = 0, SURROUND = 2 */
1816 return snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 12,
1817 ucontrol
->value
.integer
.value
[0] ? (2<<12) : (0<<12));
1820 static int ac97_alc850_mic_get(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1822 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1823 ucontrol
->value
.integer
.value
[0] = ((ac97
->regs
[AC97_ALC850_JACK_SELECT
] >> 4) & 7) == 2;
1827 static int ac97_alc850_mic_put(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1829 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1831 /* Vref disable (bit12), 1kOhm (bit13) */
1832 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<12)|(1<<13),
1833 ucontrol
->value
.integer
.value
[0] ? (1<<12) : (1<<13));
1834 /* MIC-IN = 1, CENTER-LFE = 2 */
1835 return snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 4,
1836 ucontrol
->value
.integer
.value
[0] ? (2<<4) : (1<<4));
1839 static const snd_kcontrol_new_t snd_ac97_controls_alc850
[] = {
1840 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
1842 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1843 .name
= "Line-In As Surround",
1844 .info
= snd_ac97_info_volsw
,
1845 .get
= ac97_alc850_surround_get
,
1846 .put
= ac97_alc850_surround_put
,
1847 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1850 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1851 .name
= "Mic As Center/LFE",
1852 .info
= snd_ac97_info_volsw
,
1853 .get
= ac97_alc850_mic_get
,
1854 .put
= ac97_alc850_mic_put
,
1855 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1860 static int patch_alc850_specific(ac97_t
*ac97
)
1864 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc850
, ARRAY_SIZE(snd_ac97_controls_alc850
))) < 0)
1866 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
1867 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
1873 static struct snd_ac97_build_ops patch_alc850_ops
= {
1874 .build_specific
= patch_alc850_specific
1877 int patch_alc850(ac97_t
*ac97
)
1879 ac97
->build_ops
= &patch_alc850_ops
;
1881 ac97
->spec
.dev_flags
= 0; /* for IEC958 playback route - ALC655 compatible */
1883 /* assume only page 0 for writing cache */
1884 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
1886 /* adjust default values */
1887 /* set default: spdif-in enabled,
1888 spdif-in monitor off, spdif-in PCM off
1889 center on mic off, surround on line-in off
1892 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
1893 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
1894 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
1896 snd_ac97_write_cache(ac97
, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
1897 (1<<7)|(0<<12)|(1<<13)|(0<<14));
1898 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
1899 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
1901 snd_ac97_write_cache(ac97
, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
1902 (1<<11)|(0<<12)|(1<<15));
1904 /* full DAC volume */
1905 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
1906 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
1912 * C-Media CM97xx codecs
1914 static const snd_kcontrol_new_t snd_ac97_cm9738_controls
[] = {
1915 AC97_SINGLE("Line-In As Surround", AC97_CM9738_VENDOR_CTRL
, 10, 1, 0),
1916 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL
, 13, 1, 0),
1919 static int patch_cm9738_specific(ac97_t
* ac97
)
1921 return patch_build_controls(ac97
, snd_ac97_cm9738_controls
, ARRAY_SIZE(snd_ac97_cm9738_controls
));
1924 static struct snd_ac97_build_ops patch_cm9738_ops
= {
1925 .build_specific
= patch_cm9738_specific
1928 int patch_cm9738(ac97_t
* ac97
)
1930 ac97
->build_ops
= &patch_cm9738_ops
;
1931 /* FIXME: can anyone confirm below? */
1932 /* CM9738 has no PCM volume although the register reacts */
1933 ac97
->flags
|= AC97_HAS_NO_PCM_VOL
;
1934 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
1939 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t
*kcontrol
, snd_ctl_elem_info_t
* uinfo
)
1941 static char *texts
[] = { "Analog", "Digital" };
1943 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1945 uinfo
->value
.enumerated
.items
= 2;
1946 if (uinfo
->value
.enumerated
.item
> 1)
1947 uinfo
->value
.enumerated
.item
= 1;
1948 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1952 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1954 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1957 val
= ac97
->regs
[AC97_CM9739_SPDIF_CTRL
];
1958 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 0x01;
1962 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1964 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1966 return snd_ac97_update_bits(ac97
, AC97_CM9739_SPDIF_CTRL
,
1968 (ucontrol
->value
.enumerated
.item
[0] & 0x01) << 1);
1971 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif
[] = {
1972 /* BIT 0: SPDI_EN - always true */
1973 { /* BIT 1: SPDIFS */
1974 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1975 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
1976 .info
= snd_ac97_cmedia_spdif_playback_source_info
,
1977 .get
= snd_ac97_cmedia_spdif_playback_source_get
,
1978 .put
= snd_ac97_cmedia_spdif_playback_source_put
,
1980 /* BIT 2: IG_SPIV */
1981 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Valid Switch", AC97_CM9739_SPDIF_CTRL
, 2, 1, 0),
1983 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Monitor", AC97_CM9739_SPDIF_CTRL
, 3, 1, 0),
1984 /* BIT 4: SPI2SDI */
1985 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_CM9739_SPDIF_CTRL
, 4, 1, 0),
1986 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
1989 static int snd_ac97_cm9739_center_mic_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
1991 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
1992 if (ac97
->regs
[AC97_CM9739_MULTI_CHAN
] & 0x1000)
1993 ucontrol
->value
.integer
.value
[0] = 1;
1995 ucontrol
->value
.integer
.value
[0] = 0;
1999 static int snd_ac97_cm9739_center_mic_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
2001 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
2002 return snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 0x3000,
2003 ucontrol
->value
.integer
.value
[0] ?
2007 static const snd_kcontrol_new_t snd_ac97_cm9739_controls
[] = {
2008 AC97_SINGLE("Line-In As Surround", AC97_CM9739_MULTI_CHAN
, 10, 1, 0),
2010 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2011 .name
= "Mic As Center/LFE",
2012 .info
= snd_ac97_info_volsw
,
2013 .get
= snd_ac97_cm9739_center_mic_get
,
2014 .put
= snd_ac97_cm9739_center_mic_put
,
2015 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
2019 static int patch_cm9739_specific(ac97_t
* ac97
)
2021 return patch_build_controls(ac97
, snd_ac97_cm9739_controls
, ARRAY_SIZE(snd_ac97_cm9739_controls
));
2024 static int patch_cm9739_post_spdif(ac97_t
* ac97
)
2026 return patch_build_controls(ac97
, snd_ac97_cm9739_controls_spdif
, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif
));
2029 static struct snd_ac97_build_ops patch_cm9739_ops
= {
2030 .build_specific
= patch_cm9739_specific
,
2031 .build_post_spdif
= patch_cm9739_post_spdif
2034 int patch_cm9739(ac97_t
* ac97
)
2038 ac97
->build_ops
= &patch_cm9739_ops
;
2040 /* CM9739/A has no Master and PCM volume although the register reacts */
2041 ac97
->flags
|= AC97_HAS_NO_MASTER_VOL
| AC97_HAS_NO_PCM_VOL
;
2042 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8000);
2043 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
2046 val
= snd_ac97_read(ac97
, AC97_EXTENDED_STATUS
);
2047 if (val
& AC97_EA_SPCV
) {
2048 /* enable spdif in */
2049 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
2050 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) | 0x01);
2051 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2053 ac97
->ext_id
&= ~AC97_EI_SPDIF
; /* disable extended-id */
2054 ac97
->rates
[AC97_RATES_SPDIF
] = 0;
2057 /* set-up multi channel */
2058 /* bit 14: 0 = SPDIF, 1 = EAPD */
2059 /* bit 13: enable internal vref output for mic */
2060 /* bit 12: disable center/lfe (swithable) */
2061 /* bit 10: disable surround/line (switchable) */
2062 /* bit 9: mix 2 surround off */
2063 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2064 /* bit 3: undocumented; surround? */
2066 val
= snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) & (1 << 4);
2069 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
2071 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
, val
);
2073 /* FIXME: set up GPIO */
2074 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
2075 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
2076 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2078 ac97
->subsystem_vendor
== 0x1043 &&
2079 ac97
->subsystem_device
== 0x1843) {
2080 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
2081 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) & ~0x01);
2082 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
,
2083 snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) | (1 << 14));
2089 #define AC97_CM9761_MULTI_CHAN 0x64
2090 #define AC97_CM9761_SPDIF_CTRL 0x6c
2092 static int snd_ac97_cm9761_linein_rear_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
2094 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
2095 if (ac97
->regs
[AC97_CM9739_MULTI_CHAN
] & 0x0400)
2096 ucontrol
->value
.integer
.value
[0] = 1;
2098 ucontrol
->value
.integer
.value
[0] = 0;
2102 static int snd_ac97_cm9761_linein_rear_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
2104 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
2105 unsigned short vals
[2][2] = {
2106 { 0x0008, 0x0400 }, /* off, on */
2107 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */
2109 return snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 0x0408,
2110 vals
[ac97
->spec
.dev_flags
][!!ucontrol
->value
.integer
.value
[0]]);
2113 static int snd_ac97_cm9761_center_mic_get(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
2115 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
2116 if (ac97
->regs
[AC97_CM9739_MULTI_CHAN
] & 0x1000)
2117 ucontrol
->value
.integer
.value
[0] = 1;
2119 ucontrol
->value
.integer
.value
[0] = 0;
2120 if (ac97
->spec
.dev_flags
) /* 9761-82 rev.B */
2121 ucontrol
->value
.integer
.value
[0] = !ucontrol
->value
.integer
.value
[0];
2125 static int snd_ac97_cm9761_center_mic_put(snd_kcontrol_t
* kcontrol
, snd_ctl_elem_value_t
* ucontrol
)
2127 ac97_t
*ac97
= snd_kcontrol_chip(kcontrol
);
2128 unsigned short vals
[2][2] = {
2129 { 0x2000, 0x1880 }, /* off, on */
2130 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */
2132 return snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 0x3880,
2133 vals
[ac97
->spec
.dev_flags
][!!ucontrol
->value
.integer
.value
[0]]);
2136 static const snd_kcontrol_new_t snd_ac97_cm9761_controls
[] = {
2138 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2139 .name
= "Line-In As Surround",
2140 .info
= snd_ac97_info_volsw
,
2141 .get
= snd_ac97_cm9761_linein_rear_get
,
2142 .put
= snd_ac97_cm9761_linein_rear_put
,
2143 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
2146 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2147 .name
= "Mic As Center/LFE",
2148 .info
= snd_ac97_info_volsw
,
2149 .get
= snd_ac97_cm9761_center_mic_get
,
2150 .put
= snd_ac97_cm9761_center_mic_put
,
2151 .private_value
= AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
2155 static int patch_cm9761_specific(ac97_t
* ac97
)
2157 return patch_build_controls(ac97
, snd_ac97_cm9761_controls
, ARRAY_SIZE(snd_ac97_cm9761_controls
));
2160 static struct snd_ac97_build_ops patch_cm9761_ops
= {
2161 .build_specific
= patch_cm9761_specific
,
2162 .build_post_spdif
= patch_cm9739_post_spdif
/* hope it's identical... */
2165 int patch_cm9761(ac97_t
*ac97
)
2169 /* CM9761 has no PCM volume although the register reacts */
2170 /* Master volume seems to have _some_ influence on the analog
2173 ac97
->flags
|= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL
;
2174 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8808);
2175 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8808);
2177 ac97
->spec
.dev_flags
= 0; /* 1 = model 82 revision B */
2178 if (ac97
->id
== AC97_ID_CM9761_82
) {
2180 /* check page 1, reg 0x60 */
2181 val
= snd_ac97_read(ac97
, AC97_INT_PAGING
);
2182 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, (val
& ~0x0f) | 0x01);
2183 tmp
= snd_ac97_read(ac97
, 0x60);
2184 ac97
->spec
.dev_flags
= tmp
& 1; /* revision B? */
2185 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, val
);
2188 ac97
->build_ops
= &patch_cm9761_ops
;
2191 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2192 ac97
->ext_id
|= AC97_EI_SPDIF
;
2193 /* to be sure: we overwrite the ext status bits */
2194 snd_ac97_write_cache(ac97
, AC97_EXTENDED_STATUS
, 0x05c0);
2195 /* Don't set 0x0200 here. This results in the silent analog output */
2196 snd_ac97_write_cache(ac97
, AC97_CM9761_SPDIF_CTRL
, 0x0009);
2197 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2199 /* set-up multi channel */
2200 /* bit 15: pc master beep off
2202 * bit 13: vref ctl [= cm9739]
2203 * bit 12: center/mic [= cm9739] (reverted on rev B)
2204 * bit 11: ?? (mic/center/lfe) (reverted on rev B)
2205 * bit 10: suddound/line [= cm9739]
2206 * bit 9: mix 2 surround
2208 * bit 7: ?? (mic/center/lfe)
2210 * bit 3: ?? (line-in/rear share) (revereted with rev B)
2211 * bit 2: ?? (surround)
2217 if (ac97
->spec
.dev_flags
)
2222 val
= snd_ac97_read(ac97
, AC97_CM9761_MULTI_CHAN
);
2223 val
|= (1 << 4); /* front on */
2224 snd_ac97_write_cache(ac97
, AC97_CM9761_MULTI_CHAN
, val
);
2226 /* FIXME: set up GPIO */
2227 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
2228 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
2237 static const snd_kcontrol_new_t snd_ac97_controls_vt1616
[] = {
2238 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2239 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2240 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2241 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2244 static int patch_vt1616_specific(ac97_t
* ac97
)
2248 if (snd_ac97_try_bit(ac97
, 0x5a, 9))
2249 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[0], 1)) < 0)
2251 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[1], ARRAY_SIZE(snd_ac97_controls_vt1616
) - 1)) < 0)
2256 static struct snd_ac97_build_ops patch_vt1616_ops
= {
2257 .build_specific
= patch_vt1616_specific
2260 int patch_vt1616(ac97_t
* ac97
)
2262 ac97
->build_ops
= &patch_vt1616_ops
;
2266 static const snd_kcontrol_new_t snd_ac97_controls_it2646
[] = {
2267 AC97_SINGLE("Line-In As Surround", 0x76, 9, 1, 0),
2268 AC97_SINGLE("Mic As Center/LFE", 0x76, 10, 1, 0),
2271 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646
[] = {
2272 AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
2273 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2274 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2277 static int patch_it2646_specific(ac97_t
* ac97
)
2280 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_it2646
, ARRAY_SIZE(snd_ac97_controls_it2646
))) < 0)
2282 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_it2646
, ARRAY_SIZE(snd_ac97_spdif_controls_it2646
))) < 0)
2287 static struct snd_ac97_build_ops patch_it2646_ops
= {
2288 .build_specific
= patch_it2646_specific
2291 int patch_it2646(ac97_t
* ac97
)
2293 ac97
->build_ops
= &patch_it2646_ops
;
2294 /* full DAC volume */
2295 snd_ac97_write_cache(ac97
, 0x5E, 0x0808);
2296 snd_ac97_write_cache(ac97
, 0x7A, 0x0808);
2300 /* Si3036/8 specific registers */
2301 #define AC97_SI3036_CHIP_ID 0x5a
2303 int mpatch_si3036(ac97_t
* ac97
)
2305 //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
2306 snd_ac97_write_cache(ac97
, 0x5c, 0xf210 );
2307 snd_ac97_write_cache(ac97
, 0x68, 0);