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 <linux/mutex.h>
32 #include <sound/core.h>
33 #include <sound/pcm.h>
34 #include <sound/control.h>
35 #include <sound/ac97_codec.h>
36 #include "ac97_patch.h"
38 #include "ac97_local.h"
41 * Chip specific initialization
44 static int patch_build_controls(struct snd_ac97
* ac97
, const struct snd_kcontrol_new
*controls
, int count
)
48 for (idx
= 0; idx
< count
; idx
++)
49 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&controls
[idx
], ac97
))) < 0)
54 /* set to the page, update bits and restore the page */
55 static int ac97_update_bits_page(struct snd_ac97
*ac97
, unsigned short reg
, unsigned short mask
, unsigned short value
, unsigned short page
)
57 unsigned short page_save
;
60 mutex_lock(&ac97
->page_mutex
);
61 page_save
= snd_ac97_read(ac97
, AC97_INT_PAGING
) & AC97_PAGE_MASK
;
62 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page
);
63 ret
= snd_ac97_update_bits(ac97
, reg
, mask
, value
);
64 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page_save
);
65 mutex_unlock(&ac97
->page_mutex
); /* unlock paging */
70 * shared line-in/mic controls
72 static int ac97_enum_text_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
,
73 const char **texts
, unsigned int nums
)
75 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
77 uinfo
->value
.enumerated
.items
= nums
;
78 if (uinfo
->value
.enumerated
.item
> nums
- 1)
79 uinfo
->value
.enumerated
.item
= nums
- 1;
80 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
84 static int ac97_surround_jack_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
86 static const char *texts
[] = { "Shared", "Independent" };
87 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 2);
90 static int ac97_surround_jack_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
92 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
94 ucontrol
->value
.enumerated
.item
[0] = ac97
->indep_surround
;
98 static int ac97_surround_jack_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
100 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
101 unsigned char indep
= !!ucontrol
->value
.enumerated
.item
[0];
103 if (indep
!= ac97
->indep_surround
) {
104 ac97
->indep_surround
= indep
;
105 if (ac97
->build_ops
->update_jacks
)
106 ac97
->build_ops
->update_jacks(ac97
);
112 static int ac97_channel_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
114 static const char *texts
[] = { "2ch", "4ch", "6ch" };
115 if (kcontrol
->private_value
)
116 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 2); /* 4ch only */
117 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 3);
120 static int ac97_channel_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
122 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
124 ucontrol
->value
.enumerated
.item
[0] = ac97
->channel_mode
;
128 static int ac97_channel_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
130 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
131 unsigned char mode
= ucontrol
->value
.enumerated
.item
[0];
133 if (mode
!= ac97
->channel_mode
) {
134 ac97
->channel_mode
= mode
;
135 if (ac97
->build_ops
->update_jacks
)
136 ac97
->build_ops
->update_jacks(ac97
);
142 #define AC97_SURROUND_JACK_MODE_CTL \
144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
145 .name = "Surround Jack Mode", \
146 .info = ac97_surround_jack_mode_info, \
147 .get = ac97_surround_jack_mode_get, \
148 .put = ac97_surround_jack_mode_put, \
150 #define AC97_CHANNEL_MODE_CTL \
152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
153 .name = "Channel Mode", \
154 .info = ac97_channel_mode_info, \
155 .get = ac97_channel_mode_get, \
156 .put = ac97_channel_mode_put, \
158 #define AC97_CHANNEL_MODE_4CH_CTL \
160 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
161 .name = "Channel Mode", \
162 .info = ac97_channel_mode_info, \
163 .get = ac97_channel_mode_get, \
164 .put = ac97_channel_mode_put, \
165 .private_value = 1, \
168 static inline int is_surround_on(struct snd_ac97
*ac97
)
170 return ac97
->channel_mode
>= 1;
173 static inline int is_clfe_on(struct snd_ac97
*ac97
)
175 return ac97
->channel_mode
>= 2;
178 static inline int is_shared_linein(struct snd_ac97
*ac97
)
180 return ! ac97
->indep_surround
&& is_surround_on(ac97
);
183 static inline int is_shared_micin(struct snd_ac97
*ac97
)
185 return ! ac97
->indep_surround
&& is_clfe_on(ac97
);
189 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
191 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
192 static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
194 static char *texts
[3] = {
195 "Standard", "Small", "Smaller"
198 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
200 uinfo
->value
.enumerated
.items
= 3;
201 if (uinfo
->value
.enumerated
.item
> 2)
202 uinfo
->value
.enumerated
.item
= 2;
203 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
207 static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
209 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
212 val
= ac97
->regs
[AC97_YMF753_3D_MODE_SEL
];
213 val
= (val
>> 10) & 3;
214 if (val
> 0) /* 0 = invalid */
216 ucontrol
->value
.enumerated
.item
[0] = val
;
220 static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
222 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
225 if (ucontrol
->value
.enumerated
.item
[0] > 2)
227 val
= (ucontrol
->value
.enumerated
.item
[0] + 1) << 10;
228 return snd_ac97_update(ac97
, AC97_YMF753_3D_MODE_SEL
, val
);
231 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker
=
233 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
234 .name
= "3D Control - Speaker",
235 .info
= snd_ac97_ymf753_info_speaker
,
236 .get
= snd_ac97_ymf753_get_speaker
,
237 .put
= snd_ac97_ymf753_put_speaker
,
240 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
241 static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
243 static char *texts
[2] = { "AC-Link", "A/D Converter" };
245 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
247 uinfo
->value
.enumerated
.items
= 2;
248 if (uinfo
->value
.enumerated
.item
> 1)
249 uinfo
->value
.enumerated
.item
= 1;
250 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
254 static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
256 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
259 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
260 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 1;
264 static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
266 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
269 if (ucontrol
->value
.enumerated
.item
[0] > 1)
271 val
= ucontrol
->value
.enumerated
.item
[0] << 1;
272 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0002, val
);
275 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
276 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
277 By default, no output pin is selected, and the S/PDIF signal is not output.
278 There is also a bit to mute S/PDIF output in a vendor-specific register. */
279 static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
281 static char *texts
[3] = { "Disabled", "Pin 43", "Pin 48" };
283 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
285 uinfo
->value
.enumerated
.items
= 3;
286 if (uinfo
->value
.enumerated
.item
> 2)
287 uinfo
->value
.enumerated
.item
= 2;
288 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
292 static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
294 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
297 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
298 ucontrol
->value
.enumerated
.item
[0] = (val
& 0x0008) ? 2 : (val
& 0x0020) ? 1 : 0;
302 static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
304 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
307 if (ucontrol
->value
.enumerated
.item
[0] > 2)
309 val
= (ucontrol
->value
.enumerated
.item
[0] == 2) ? 0x0008 :
310 (ucontrol
->value
.enumerated
.item
[0] == 1) ? 0x0020 : 0;
311 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0028, val
);
312 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
313 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
316 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif
[3] = {
318 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
319 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
320 .info
= snd_ac97_ymf753_spdif_source_info
,
321 .get
= snd_ac97_ymf753_spdif_source_get
,
322 .put
= snd_ac97_ymf753_spdif_source_put
,
325 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
326 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Output Pin",
327 .info
= snd_ac97_ymf753_spdif_output_pin_info
,
328 .get
= snd_ac97_ymf753_spdif_output_pin_get
,
329 .put
= snd_ac97_ymf753_spdif_output_pin_put
,
331 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE
,NONE
) "Mute", AC97_YMF753_DIT_CTRL2
, 2, 1, 1)
334 static int patch_yamaha_ymf753_3d(struct snd_ac97
* ac97
)
336 struct snd_kcontrol
*kctl
;
339 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
341 strcpy(kctl
->id
.name
, "3D Control - Wide");
342 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 9, 7, 0);
343 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
344 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker
, ac97
))) < 0)
346 snd_ac97_write_cache(ac97
, AC97_YMF753_3D_MODE_SEL
, 0x0c00);
350 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97
* ac97
)
354 if ((err
= patch_build_controls(ac97
, snd_ac97_ymf753_controls_spdif
, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif
))) < 0)
359 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops
= {
360 .build_3d
= patch_yamaha_ymf753_3d
,
361 .build_post_spdif
= patch_yamaha_ymf753_post_spdif
364 int patch_yamaha_ymf753(struct snd_ac97
* ac97
)
366 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
367 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
368 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
369 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
370 By default, no output pin is selected, and the S/PDIF signal is not output.
371 There is also a bit to mute S/PDIF output in a vendor-specific register.
373 ac97
->build_ops
= &patch_yamaha_ymf753_ops
;
374 ac97
->caps
|= AC97_BC_BASS_TREBLE
;
375 ac97
->caps
|= 0x04 << 10; /* Yamaha 3D enhancement */
380 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
381 * removed broken wolfson00 patch.
382 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
385 static const struct snd_kcontrol_new wm97xx_snd_ac97_controls
[] = {
386 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL
, 8, 0, 31, 1),
387 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL
, 15, 1, 1),
390 static int patch_wolfson_wm9703_specific(struct snd_ac97
* ac97
)
392 /* This is known to work for the ViewSonic ViewPad 1000
393 * Randolph Bentson <bentson@holmsjoen.com>
394 * WM9703/9707/9708/9717
398 for (i
= 0; i
< ARRAY_SIZE(wm97xx_snd_ac97_controls
); i
++) {
399 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm97xx_snd_ac97_controls
[i
], ac97
))) < 0)
402 snd_ac97_write_cache(ac97
, AC97_WM97XX_FMIXER_VOL
, 0x0808);
406 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops
= {
407 .build_specific
= patch_wolfson_wm9703_specific
,
410 int patch_wolfson03(struct snd_ac97
* ac97
)
412 ac97
->build_ops
= &patch_wolfson_wm9703_ops
;
416 static const struct snd_kcontrol_new wm9704_snd_ac97_controls
[] = {
417 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL
, 8, 0, 31, 1),
418 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL
, 15, 1, 1),
419 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL
, 8, 0, 31, 1),
420 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL
, 15, 1, 1),
421 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL
, 8, 0, 31, 1),
422 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER
, 8, 0, 31, 1),
425 static int patch_wolfson_wm9704_specific(struct snd_ac97
* ac97
)
428 for (i
= 0; i
< ARRAY_SIZE(wm9704_snd_ac97_controls
); i
++) {
429 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm9704_snd_ac97_controls
[i
], ac97
))) < 0)
432 /* patch for DVD noise */
433 snd_ac97_write_cache(ac97
, AC97_WM9704_TEST
, 0x0200);
437 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops
= {
438 .build_specific
= patch_wolfson_wm9704_specific
,
441 int patch_wolfson04(struct snd_ac97
* ac97
)
444 ac97
->build_ops
= &patch_wolfson_wm9704_ops
;
448 static int patch_wolfson_wm9705_specific(struct snd_ac97
* ac97
)
451 for (i
= 0; i
< ARRAY_SIZE(wm97xx_snd_ac97_controls
); i
++) {
452 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm97xx_snd_ac97_controls
[i
], ac97
))) < 0)
455 snd_ac97_write_cache(ac97
, 0x72, 0x0808);
459 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops
= {
460 .build_specific
= patch_wolfson_wm9705_specific
,
463 int patch_wolfson05(struct snd_ac97
* ac97
)
466 ac97
->build_ops
= &patch_wolfson_wm9705_ops
;
470 static const char* wm9711_alc_select
[] = {"None", "Left", "Right", "Stereo"};
471 static const char* wm9711_alc_mix
[] = {"Stereo", "Right", "Left", "None"};
472 static const char* wm9711_out3_src
[] = {"Left", "VREF", "Left + Right", "Mono"};
473 static const char* wm9711_out3_lrsrc
[] = {"Master Mix", "Headphone Mix"};
474 static const char* wm9711_rec_adc
[] = {"Stereo", "Left", "Right", "Mute"};
475 static const char* wm9711_base
[] = {"Linear Control", "Adaptive Boost"};
476 static const char* wm9711_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
477 static const char* wm9711_mic
[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
478 static const char* wm9711_rec_sel
[] =
479 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
480 static const char* wm9711_ng_type
[] = {"Constant Gain", "Mute"};
482 static const struct ac97_enum wm9711_enum
[] = {
483 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9711_alc_select
),
484 AC97_ENUM_SINGLE(AC97_VIDEO
, 10, 4, wm9711_alc_mix
),
485 AC97_ENUM_SINGLE(AC97_AUX
, 9, 4, wm9711_out3_src
),
486 AC97_ENUM_SINGLE(AC97_AUX
, 8, 2, wm9711_out3_lrsrc
),
487 AC97_ENUM_SINGLE(AC97_REC_SEL
, 12, 4, wm9711_rec_adc
),
488 AC97_ENUM_SINGLE(AC97_MASTER_TONE
, 15, 2, wm9711_base
),
489 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 14, 6, 2, wm9711_rec_gain
),
490 AC97_ENUM_SINGLE(AC97_MIC
, 5, 4, wm9711_mic
),
491 AC97_ENUM_DOUBLE(AC97_REC_SEL
, 8, 0, 8, wm9711_rec_sel
),
492 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9711_ng_type
),
495 static const struct snd_kcontrol_new wm9711_snd_ac97_controls
[] = {
496 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
497 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
498 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV
, 4, 15, 0),
499 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
500 AC97_ENUM("ALC Function", wm9711_enum
[0]),
501 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 1),
502 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 1),
503 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
504 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
505 AC97_ENUM("ALC NG Type", wm9711_enum
[9]),
506 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 1),
508 AC97_SINGLE("Side Tone Switch", AC97_VIDEO
, 15, 1, 1),
509 AC97_SINGLE("Side Tone Volume", AC97_VIDEO
, 12, 7, 1),
510 AC97_ENUM("ALC Headphone Mux", wm9711_enum
[1]),
511 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO
, 7, 7, 1),
513 AC97_SINGLE("Out3 Switch", AC97_AUX
, 15, 1, 1),
514 AC97_SINGLE("Out3 ZC Switch", AC97_AUX
, 7, 1, 1),
515 AC97_ENUM("Out3 Mux", wm9711_enum
[2]),
516 AC97_ENUM("Out3 LR Mux", wm9711_enum
[3]),
517 AC97_SINGLE("Out3 Volume", AC97_AUX
, 0, 31, 1),
519 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP
, 15, 1, 1),
520 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP
, 12, 7, 1),
521 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP
, 11, 1, 1),
522 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP
, 8, 7, 1),
523 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP
, 7, 1, 1),
524 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP
, 4, 7, 1),
526 AC97_SINGLE("Aux to Headphone Switch", AC97_CD
, 15, 1, 1),
527 AC97_SINGLE("Aux to Headphone Volume", AC97_CD
, 12, 7, 1),
528 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD
, 11, 1, 1),
529 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD
, 8, 7, 1),
530 AC97_SINGLE("Aux to Phone Switch", AC97_CD
, 7, 1, 1),
531 AC97_SINGLE("Aux to Phone Volume", AC97_CD
, 4, 7, 1),
533 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE
, 15, 1, 1),
534 AC97_SINGLE("Phone to Master Switch", AC97_PHONE
, 14, 1, 1),
536 AC97_SINGLE("Line to Headphone Switch", AC97_LINE
, 15, 1, 1),
537 AC97_SINGLE("Line to Master Switch", AC97_LINE
, 14, 1, 1),
538 AC97_SINGLE("Line to Phone Switch", AC97_LINE
, 13, 1, 1),
540 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM
, 15, 1, 1),
541 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM
, 14, 1, 1),
542 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM
, 13, 1, 1),
544 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL
, 14, 1, 0),
545 AC97_ENUM("Capture to Phone Mux", wm9711_enum
[4]),
546 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL
, 11, 1, 1),
547 AC97_ENUM("Capture Select", wm9711_enum
[8]),
549 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL
, 5, 1, 1),
550 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL
, 4, 1, 1),
552 AC97_ENUM("Bass Control", wm9711_enum
[5]),
553 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE
, 12, 1, 1),
554 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE
, 4, 1, 1),
555 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE
, 6, 1, 0),
557 AC97_SINGLE("ADC Switch", AC97_REC_GAIN
, 15, 1, 1),
558 AC97_ENUM("Capture Volume Steps", wm9711_enum
[6]),
559 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN
, 8, 0, 15, 1),
560 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN
, 7, 1, 0),
562 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC
, 14, 1, 1),
563 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC
, 13, 1, 1),
564 AC97_ENUM("Mic Select Source", wm9711_enum
[7]),
565 AC97_SINGLE("Mic 1 Volume", AC97_MIC
, 8, 32, 1),
566 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC
, 7, 1, 0),
568 AC97_SINGLE("Master ZC Switch", AC97_MASTER
, 7, 1, 0),
569 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE
, 7, 1, 0),
570 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO
, 7, 1, 0),
573 static int patch_wolfson_wm9711_specific(struct snd_ac97
* ac97
)
577 for (i
= 0; i
< ARRAY_SIZE(wm9711_snd_ac97_controls
); i
++) {
578 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm9711_snd_ac97_controls
[i
], ac97
))) < 0)
581 snd_ac97_write_cache(ac97
, AC97_CODEC_CLASS_REV
, 0x0808);
582 snd_ac97_write_cache(ac97
, AC97_PCI_SVID
, 0x0808);
583 snd_ac97_write_cache(ac97
, AC97_VIDEO
, 0x0808);
584 snd_ac97_write_cache(ac97
, AC97_AUX
, 0x0808);
585 snd_ac97_write_cache(ac97
, AC97_PC_BEEP
, 0x0808);
586 snd_ac97_write_cache(ac97
, AC97_CD
, 0x0000);
590 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops
= {
591 .build_specific
= patch_wolfson_wm9711_specific
,
594 int patch_wolfson11(struct snd_ac97
* ac97
)
597 ac97
->build_ops
= &patch_wolfson_wm9711_ops
;
599 ac97
->flags
|= AC97_HAS_NO_REC_GAIN
| AC97_STEREO_MUTES
| AC97_HAS_NO_MIC
|
600 AC97_HAS_NO_PC_BEEP
| AC97_HAS_NO_VIDEO
| AC97_HAS_NO_CD
;
605 static const char* wm9713_mic_mixer
[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
606 static const char* wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
607 static const char* wm9713_rec_src
[] =
608 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
610 static const char* wm9713_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
611 static const char* wm9713_alc_select
[] = {"None", "Left", "Right", "Stereo"};
612 static const char* wm9713_mono_pga
[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
613 static const char* wm9713_spk_pga
[] =
614 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
615 static const char* wm9713_hp_pga
[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
616 static const char* wm9713_out3_pga
[] = {"Vmid", "Zh", "Inv 1", "NC"};
617 static const char* wm9713_out4_pga
[] = {"Vmid", "Zh", "Inv 2", "NC"};
618 static const char* wm9713_dac_inv
[] =
619 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
620 "Headphone Mix Mono", "NC", "Vmid"};
621 static const char* wm9713_base
[] = {"Linear Control", "Adaptive Boost"};
622 static const char* wm9713_ng_type
[] = {"Constant Gain", "Mute"};
624 static const struct ac97_enum wm9713_enum
[] = {
625 AC97_ENUM_SINGLE(AC97_LINE
, 3, 4, wm9713_mic_mixer
),
626 AC97_ENUM_SINGLE(AC97_VIDEO
, 14, 4, wm9713_rec_mux
),
627 AC97_ENUM_SINGLE(AC97_VIDEO
, 9, 4, wm9713_rec_mux
),
628 AC97_ENUM_DOUBLE(AC97_VIDEO
, 3, 0, 8, wm9713_rec_src
),
629 AC97_ENUM_DOUBLE(AC97_CD
, 14, 6, 2, wm9713_rec_gain
),
630 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9713_alc_select
),
631 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 14, 4, wm9713_mono_pga
),
632 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 11, 8, 8, wm9713_spk_pga
),
633 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 6, 4, 4, wm9713_hp_pga
),
634 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 2, 4, wm9713_out3_pga
),
635 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 0, 4, wm9713_out4_pga
),
636 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC
, 13, 10, 8, wm9713_dac_inv
),
637 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE
, 15, 2, wm9713_base
),
638 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9713_ng_type
),
641 static const struct snd_kcontrol_new wm13_snd_ac97_controls
[] = {
642 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP
, 8, 0, 31, 1),
643 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP
, 15, 1, 1),
644 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP
, 14, 1, 1),
645 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP
, 13, 1, 1),
647 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE
, 8, 0, 31, 1),
648 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE
, 15, 1, 1),
649 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE
, 14, 1, 1),
650 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE
, 13, 1, 1),
652 AC97_SINGLE("Mic 1 Volume", AC97_MIC
, 8, 31, 1),
653 AC97_SINGLE("Mic 2 Volume", AC97_MIC
, 0, 31, 1),
654 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE
, 7, 1, 1),
655 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE
, 6, 1, 1),
656 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE
, 5, 1, 0),
657 AC97_ENUM("Mic to Headphone Mux", wm9713_enum
[0]),
658 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE
, 0, 7, 1),
660 AC97_SINGLE("Capture Switch", AC97_CD
, 15, 1, 1),
661 AC97_ENUM("Capture Volume Steps", wm9713_enum
[4]),
662 AC97_DOUBLE("Capture Volume", AC97_CD
, 8, 0, 15, 0),
663 AC97_SINGLE("Capture ZC Switch", AC97_CD
, 7, 1, 0),
665 AC97_ENUM("Capture to Headphone Mux", wm9713_enum
[1]),
666 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO
, 11, 7, 1),
667 AC97_ENUM("Capture to Mono Mux", wm9713_enum
[2]),
668 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO
, 8, 1, 0),
669 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO
, 6, 1, 0),
670 AC97_ENUM("Capture Select", wm9713_enum
[3]),
672 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
673 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
674 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV
, 4, 15, 0),
675 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
676 AC97_ENUM("ALC Function", wm9713_enum
[5]),
677 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 0),
678 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 0),
679 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
680 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
681 AC97_ENUM("ALC NG Type", wm9713_enum
[13]),
682 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 0),
684 AC97_DOUBLE("Master ZC Switch", AC97_MASTER
, 14, 6, 1, 0),
685 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE
, 14, 6, 1, 0),
686 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO
, 14, 6, 1, 0),
687 AC97_SINGLE("Master Right Switch", AC97_MASTER
, 7, 1, 1),
688 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE
, 7, 1, 1),
689 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO
, 7, 1, 1),
691 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE
, 15, 1, 1),
692 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE
, 14, 1, 1),
693 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE
, 8, 31, 1),
694 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE
, 7, 1, 1),
695 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE
, 6, 1, 0),
696 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE
, 0, 31, 1),
698 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX
, 15, 1, 1),
699 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX
, 12, 7, 1),
700 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX
, 11, 1, 1),
701 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX
, 8, 7, 1),
702 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX
, 7, 1, 1),
703 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX
, 4, 7, 1),
705 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM
, 15, 1, 1),
706 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM
, 12, 7, 1),
707 AC97_SINGLE("Voice to Master Switch", AC97_PCM
, 11, 1, 1),
708 AC97_SINGLE("Voice to Master Volume", AC97_PCM
, 8, 7, 1),
709 AC97_SINGLE("Voice to Mono Switch", AC97_PCM
, 7, 1, 1),
710 AC97_SINGLE("Voice to Mono Volume", AC97_PCM
, 4, 7, 1),
712 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL
, 15, 1, 1),
713 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL
, 12, 7, 1),
714 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL
, 11, 1, 1),
715 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL
, 8, 7, 1),
716 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL
, 7, 1, 1),
717 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL
, 4, 7, 1),
719 AC97_ENUM("Mono Input Mux", wm9713_enum
[6]),
720 AC97_ENUM("Master Input Mux", wm9713_enum
[7]),
721 AC97_ENUM("Headphone Input Mux", wm9713_enum
[8]),
722 AC97_ENUM("Out 3 Input Mux", wm9713_enum
[9]),
723 AC97_ENUM("Out 4 Input Mux", wm9713_enum
[10]),
725 AC97_ENUM("Bass Control", wm9713_enum
[12]),
726 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE
, 12, 1, 1),
727 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE
, 4, 1, 1),
728 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE
, 6, 1, 0),
729 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE
, 8, 15, 1),
730 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE
, 0, 15, 1),
733 static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d
[] = {
734 AC97_ENUM("Inv Input Mux", wm9713_enum
[11]),
735 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC
, 5, 1, 0),
736 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC
, 4, 1, 0),
737 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC
, 0, 15, 1),
740 static int patch_wolfson_wm9713_3d (struct snd_ac97
* ac97
)
744 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_3d
); i
++) {
745 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_3d
[i
], ac97
))) < 0)
751 static int patch_wolfson_wm9713_specific(struct snd_ac97
* ac97
)
755 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls
); i
++) {
756 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls
[i
], ac97
))) < 0)
759 snd_ac97_write_cache(ac97
, AC97_PC_BEEP
, 0x0808);
760 snd_ac97_write_cache(ac97
, AC97_PHONE
, 0x0808);
761 snd_ac97_write_cache(ac97
, AC97_MIC
, 0x0808);
762 snd_ac97_write_cache(ac97
, AC97_LINE
, 0x00da);
763 snd_ac97_write_cache(ac97
, AC97_CD
, 0x0808);
764 snd_ac97_write_cache(ac97
, AC97_VIDEO
, 0xd612);
765 snd_ac97_write_cache(ac97
, AC97_REC_GAIN
, 0x1ba0);
770 static void patch_wolfson_wm9713_suspend (struct snd_ac97
* ac97
)
772 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xfeff);
773 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0xffff);
776 static void patch_wolfson_wm9713_resume (struct snd_ac97
* ac97
)
778 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
779 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
780 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
784 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops
= {
785 .build_specific
= patch_wolfson_wm9713_specific
,
786 .build_3d
= patch_wolfson_wm9713_3d
,
788 .suspend
= patch_wolfson_wm9713_suspend
,
789 .resume
= patch_wolfson_wm9713_resume
793 int patch_wolfson13(struct snd_ac97
* ac97
)
796 ac97
->build_ops
= &patch_wolfson_wm9713_ops
;
798 ac97
->flags
|= AC97_HAS_NO_REC_GAIN
| AC97_STEREO_MUTES
| AC97_HAS_NO_PHONE
|
799 AC97_HAS_NO_PC_BEEP
| AC97_HAS_NO_VIDEO
| AC97_HAS_NO_CD
| AC97_HAS_NO_TONE
|
801 ac97
->scaps
&= ~AC97_SCAP_MODEM
;
803 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
804 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
805 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
813 int patch_tritech_tr28028(struct snd_ac97
* ac97
)
815 snd_ac97_write_cache(ac97
, 0x26, 0x0300);
816 snd_ac97_write_cache(ac97
, 0x26, 0x0000);
817 snd_ac97_write_cache(ac97
, AC97_SURROUND_MASTER
, 0x0000);
818 snd_ac97_write_cache(ac97
, AC97_SPDIF
, 0x0000);
823 * Sigmatel STAC97xx codecs
825 static int patch_sigmatel_stac9700_3d(struct snd_ac97
* ac97
)
827 struct snd_kcontrol
*kctl
;
830 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
832 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
833 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
834 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
838 static int patch_sigmatel_stac9708_3d(struct snd_ac97
* ac97
)
840 struct snd_kcontrol
*kctl
;
843 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
845 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
846 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 0, 3, 0);
847 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
849 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Rear Depth");
850 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
851 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
855 static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker
=
856 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 2, 1, 0);
858 static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert
=
859 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 3, 1, 0);
861 static const struct snd_kcontrol_new snd_ac97_sigmatel_controls
[] = {
862 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 1, 1, 0),
863 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 0, 1, 0)
866 static int patch_sigmatel_stac97xx_specific(struct snd_ac97
* ac97
)
870 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_ANALOG
, snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) & ~0x0003);
871 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 1))
872 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[0], 1)) < 0)
874 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 0))
875 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[1], 1)) < 0)
877 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 2))
878 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_4speaker
, 1)) < 0)
880 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 3))
881 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_phaseinvert
, 1)) < 0)
886 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops
= {
887 .build_3d
= patch_sigmatel_stac9700_3d
,
888 .build_specific
= patch_sigmatel_stac97xx_specific
891 int patch_sigmatel_stac9700(struct snd_ac97
* ac97
)
893 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
897 static int snd_ac97_stac9708_put_bias(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
899 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
902 mutex_lock(&ac97
->page_mutex
);
903 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
904 err
= snd_ac97_update_bits(ac97
, AC97_SIGMATEL_BIAS2
, 0x0010,
905 (ucontrol
->value
.integer
.value
[0] & 1) << 4);
906 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0);
907 mutex_unlock(&ac97
->page_mutex
);
911 static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control
= {
912 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
913 .name
= "Sigmatel Output Bias Switch",
914 .info
= snd_ac97_info_volsw
,
915 .get
= snd_ac97_get_volsw
,
916 .put
= snd_ac97_stac9708_put_bias
,
917 .private_value
= AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2
, 4, 1, 0),
920 static int patch_sigmatel_stac9708_specific(struct snd_ac97
*ac97
)
924 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Sigmatel Surround Playback");
925 if ((err
= patch_build_controls(ac97
, &snd_ac97_stac9708_bias_control
, 1)) < 0)
927 return patch_sigmatel_stac97xx_specific(ac97
);
930 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops
= {
931 .build_3d
= patch_sigmatel_stac9708_3d
,
932 .build_specific
= patch_sigmatel_stac9708_specific
935 int patch_sigmatel_stac9708(struct snd_ac97
* ac97
)
937 unsigned int codec72
, codec6c
;
939 ac97
->build_ops
= &patch_sigmatel_stac9708_ops
;
940 ac97
->caps
|= 0x10; /* HP (sigmatel surround) support */
942 codec72
= snd_ac97_read(ac97
, AC97_SIGMATEL_BIAS2
) & 0x8000;
943 codec6c
= snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
);
945 if ((codec72
==0) && (codec6c
==0)) {
946 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
947 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1000);
948 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
949 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0007);
950 } else if ((codec72
==0x8000) && (codec6c
==0)) {
951 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
952 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1001);
953 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_DAC2INVERT
, 0x0008);
954 } else if ((codec72
==0x8000) && (codec6c
==0x0080)) {
957 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
961 int patch_sigmatel_stac9721(struct snd_ac97
* ac97
)
963 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
964 if (snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) == 0) {
965 // patch for SigmaTel
966 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
967 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x4000);
968 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
969 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
971 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
975 int patch_sigmatel_stac9744(struct snd_ac97
* ac97
)
977 // patch for SigmaTel
978 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
979 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
980 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
981 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
982 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
983 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
987 int patch_sigmatel_stac9756(struct snd_ac97
* ac97
)
989 // patch for SigmaTel
990 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
991 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
992 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
993 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
994 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
995 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
999 static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1001 static char *texts
[5] = { "Input/Disabled", "Front Output",
1002 "Rear Output", "Center/LFE Output", "Mixer Output" };
1004 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1006 uinfo
->value
.enumerated
.items
= 5;
1007 if (uinfo
->value
.enumerated
.item
> 4)
1008 uinfo
->value
.enumerated
.item
= 4;
1009 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1013 static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1015 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1016 int shift
= kcontrol
->private_value
;
1019 val
= ac97
->regs
[AC97_SIGMATEL_OUTSEL
] >> shift
;
1021 ucontrol
->value
.enumerated
.item
[0] = 0;
1023 ucontrol
->value
.enumerated
.item
[0] = 1 + (val
& 3);
1027 static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1029 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1030 int shift
= kcontrol
->private_value
;
1033 if (ucontrol
->value
.enumerated
.item
[0] > 4)
1035 if (ucontrol
->value
.enumerated
.item
[0] == 0)
1038 val
= 4 | (ucontrol
->value
.enumerated
.item
[0] - 1);
1039 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_OUTSEL
,
1040 7 << shift
, val
<< shift
, 0);
1043 static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1045 static char *texts
[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1046 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1048 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1050 uinfo
->value
.enumerated
.items
= 7;
1051 if (uinfo
->value
.enumerated
.item
> 6)
1052 uinfo
->value
.enumerated
.item
= 6;
1053 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1057 static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1059 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1060 int shift
= kcontrol
->private_value
;
1063 val
= ac97
->regs
[AC97_SIGMATEL_INSEL
];
1064 ucontrol
->value
.enumerated
.item
[0] = (val
>> shift
) & 7;
1068 static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1070 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1071 int shift
= kcontrol
->private_value
;
1073 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_INSEL
, 7 << shift
,
1074 ucontrol
->value
.enumerated
.item
[0] << shift
, 0);
1077 static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1079 static char *texts
[3] = { "None", "Front Jack", "Rear Jack" };
1081 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1083 uinfo
->value
.enumerated
.items
= 3;
1084 if (uinfo
->value
.enumerated
.item
> 2)
1085 uinfo
->value
.enumerated
.item
= 2;
1086 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1090 static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1092 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1094 ucontrol
->value
.enumerated
.item
[0] = ac97
->regs
[AC97_SIGMATEL_IOMISC
] & 3;
1098 static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1100 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1102 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_IOMISC
, 3,
1103 ucontrol
->value
.enumerated
.item
[0], 0);
1106 #define STAC9758_OUTPUT_JACK(xname, shift) \
1107 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1108 .info = snd_ac97_stac9758_output_jack_info, \
1109 .get = snd_ac97_stac9758_output_jack_get, \
1110 .put = snd_ac97_stac9758_output_jack_put, \
1111 .private_value = shift }
1112 #define STAC9758_INPUT_JACK(xname, shift) \
1113 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1114 .info = snd_ac97_stac9758_input_jack_info, \
1115 .get = snd_ac97_stac9758_input_jack_get, \
1116 .put = snd_ac97_stac9758_input_jack_put, \
1117 .private_value = shift }
1118 static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls
[] = {
1119 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1120 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1121 STAC9758_OUTPUT_JACK("Front Jack", 7),
1122 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1123 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1124 STAC9758_INPUT_JACK("Mic Input Source", 0),
1125 STAC9758_INPUT_JACK("Line Input Source", 8),
1127 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1128 .name
= "Headphone Amp",
1129 .info
= snd_ac97_stac9758_phonesel_info
,
1130 .get
= snd_ac97_stac9758_phonesel_get
,
1131 .put
= snd_ac97_stac9758_phonesel_put
1133 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC
, 4, 1, 0),
1134 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC
, 8, 1, 0)
1137 static int patch_sigmatel_stac9758_specific(struct snd_ac97
*ac97
)
1141 err
= patch_sigmatel_stac97xx_specific(ac97
);
1144 err
= patch_build_controls(ac97
, snd_ac97_sigmatel_stac9758_controls
,
1145 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls
));
1149 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Front Playback");
1150 /* DAC-A to Mix = PCM */
1151 /* DAC-B direct = Surround */
1153 snd_ac97_rename_vol_ctl(ac97
, "Video Playback", "Surround Mix Playback");
1154 /* DAC-C direct = Center/LFE */
1159 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops
= {
1160 .build_3d
= patch_sigmatel_stac9700_3d
,
1161 .build_specific
= patch_sigmatel_stac9758_specific
1164 int patch_sigmatel_stac9758(struct snd_ac97
* ac97
)
1166 static unsigned short regs
[4] = {
1167 AC97_SIGMATEL_OUTSEL
,
1168 AC97_SIGMATEL_IOMISC
,
1169 AC97_SIGMATEL_INSEL
,
1170 AC97_SIGMATEL_VARIOUS
1172 static unsigned short def_regs
[4] = {
1173 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1174 /* IOMISC */ 0x2001,
1175 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1176 /* VARIOUS */ 0x0040
1178 static unsigned short m675_regs
[4] = {
1179 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1180 /* IOMISC */ 0x2102, /* HP amp on */
1181 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1182 /* VARIOUS */ 0x0041 /* stereo mic */
1184 unsigned short *pregs
= def_regs
;
1187 /* Gateway M675 notebook */
1189 ac97
->subsystem_vendor
== 0x107b &&
1190 ac97
->subsystem_device
== 0x0601)
1193 // patch for SigmaTel
1194 ac97
->build_ops
= &patch_sigmatel_stac9758_ops
;
1195 /* FIXME: assume only page 0 for writing cache */
1196 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
1197 for (i
= 0; i
< 4; i
++)
1198 snd_ac97_write_cache(ac97
, regs
[i
], pregs
[i
]);
1200 ac97
->flags
|= AC97_STEREO_MUTES
;
1205 * Cirrus Logic CS42xx codecs
1207 static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif
[2] = {
1208 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CSR_SPDIF
, 15, 1, 0),
1209 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "AC97-SPSA", AC97_CSR_ACMODE
, 0, 3, 0)
1212 static int patch_cirrus_build_spdif(struct snd_ac97
* ac97
)
1216 /* con mask, pro mask, default */
1217 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
1220 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[0], 1)) < 0)
1222 switch (ac97
->id
& AC97_ID_CS_MASK
) {
1223 case AC97_ID_CS4205
:
1224 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[1], 1)) < 0)
1228 /* set default PCM S/PDIF params */
1229 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1230 snd_ac97_write_cache(ac97
, AC97_CSR_SPDIF
, 0x0a20);
1234 static struct snd_ac97_build_ops patch_cirrus_ops
= {
1235 .build_spdif
= patch_cirrus_build_spdif
1238 int patch_cirrus_spdif(struct snd_ac97
* ac97
)
1240 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1241 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1242 - sp/dif EA ID is not set, but sp/dif is always present.
1243 - enable/disable is spdif register bit 15.
1244 - sp/dif control register is 0x68. differs from AC97:
1245 - valid is bit 14 (vs 15)
1247 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1248 - sp/dif ssource select is in 0x5e bits 0,1.
1251 ac97
->build_ops
= &patch_cirrus_ops
;
1252 ac97
->flags
|= AC97_CS_SPDIF
;
1253 ac97
->rates
[AC97_RATES_SPDIF
] &= ~SNDRV_PCM_RATE_32000
;
1254 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
1255 snd_ac97_write_cache(ac97
, AC97_CSR_ACMODE
, 0x0080);
1259 int patch_cirrus_cs4299(struct snd_ac97
* ac97
)
1261 /* force the detection of PC Beep */
1262 ac97
->flags
|= AC97_HAS_PC_BEEP
;
1264 return patch_cirrus_spdif(ac97
);
1270 static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif
[1] = {
1271 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CXR_AUDIO_MISC
, 3, 1, 0),
1274 static int patch_conexant_build_spdif(struct snd_ac97
* ac97
)
1278 /* con mask, pro mask, default */
1279 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
1282 if ((err
= patch_build_controls(ac97
, &snd_ac97_conexant_controls_spdif
[0], 1)) < 0)
1284 /* set default PCM S/PDIF params */
1285 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1286 snd_ac97_write_cache(ac97
, AC97_CXR_AUDIO_MISC
,
1287 snd_ac97_read(ac97
, AC97_CXR_AUDIO_MISC
) & ~(AC97_CXR_SPDIFEN
|AC97_CXR_COPYRGT
|AC97_CXR_SPDIF_MASK
));
1291 static struct snd_ac97_build_ops patch_conexant_ops
= {
1292 .build_spdif
= patch_conexant_build_spdif
1295 int patch_conexant(struct snd_ac97
* ac97
)
1297 ac97
->build_ops
= &patch_conexant_ops
;
1298 ac97
->flags
|= AC97_CX_SPDIF
;
1299 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
1300 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
1305 * Analog Device AD18xx, AD19xx codecs
1308 static void ad18xx_resume(struct snd_ac97
*ac97
)
1310 static unsigned short setup_regs
[] = {
1311 AC97_AD_MISC
, AC97_AD_SERIAL_CFG
, AC97_AD_JACK_SPDIF
,
1315 for (i
= 0; i
< (int)ARRAY_SIZE(setup_regs
); i
++) {
1316 unsigned short reg
= setup_regs
[i
];
1317 if (test_bit(reg
, ac97
->reg_accessed
)) {
1318 snd_ac97_write(ac97
, reg
, ac97
->regs
[reg
]);
1319 snd_ac97_read(ac97
, reg
);
1323 if (! (ac97
->flags
& AC97_AD_MULTI
))
1324 /* normal restore */
1325 snd_ac97_restore_status(ac97
);
1327 /* restore the AD18xx codec configurations */
1328 for (codec
= 0; codec
< 3; codec
++) {
1329 if (! ac97
->spec
.ad18xx
.id
[codec
])
1331 /* select single codec */
1332 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1333 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
1334 ac97
->bus
->ops
->write(ac97
, AC97_AD_CODEC_CFG
, ac97
->spec
.ad18xx
.codec_cfg
[codec
]);
1336 /* select all codecs */
1337 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1339 /* restore status */
1340 for (i
= 2; i
< 0x7c ; i
+= 2) {
1341 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_ID
)
1343 if (test_bit(i
, ac97
->reg_accessed
)) {
1344 /* handle multi codecs for AD18xx */
1345 if (i
== AC97_PCM
) {
1346 for (codec
= 0; codec
< 3; codec
++) {
1347 if (! ac97
->spec
.ad18xx
.id
[codec
])
1349 /* select single codec */
1350 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1351 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
1352 /* update PCM bits */
1353 ac97
->bus
->ops
->write(ac97
, AC97_PCM
, ac97
->spec
.ad18xx
.pcmreg
[codec
]);
1355 /* select all codecs */
1356 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1358 } else if (i
== AC97_AD_TEST
||
1359 i
== AC97_AD_CODEC_CFG
||
1360 i
== AC97_AD_SERIAL_CFG
)
1361 continue; /* ignore */
1363 snd_ac97_write(ac97
, i
, ac97
->regs
[i
]);
1364 snd_ac97_read(ac97
, i
);
1368 snd_ac97_restore_iec958(ac97
);
1372 int patch_ad1819(struct snd_ac97
* ac97
)
1374 unsigned short scfg
;
1376 // patch for Analog Devices
1377 scfg
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1378 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, scfg
| 0x7000); /* select all codecs */
1382 static unsigned short patch_ad1881_unchained(struct snd_ac97
* ac97
, int idx
, unsigned short mask
)
1386 // test for unchained codec
1387 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, mask
);
1388 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000); /* ID0C, ID1C, SDIE = off */
1389 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1390 if ((val
& 0xff40) != 0x5340)
1392 ac97
->spec
.ad18xx
.unchained
[idx
] = mask
;
1393 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1394 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = 0x0000;
1398 static int patch_ad1881_chained1(struct snd_ac97
* ac97
, int idx
, unsigned short codec_bits
)
1400 static int cfg_bits
[3] = { 1<<12, 1<<14, 1<<13 };
1403 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, cfg_bits
[idx
]);
1404 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0004); // SDIE
1405 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1406 if ((val
& 0xff40) != 0x5340)
1409 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, codec_bits
);
1410 ac97
->spec
.ad18xx
.chained
[idx
] = cfg_bits
[idx
];
1411 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1412 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = codec_bits
? codec_bits
: 0x0004;
1416 static void patch_ad1881_chained(struct snd_ac97
* ac97
, int unchained_idx
, int cidx1
, int cidx2
)
1418 // already detected?
1419 if (ac97
->spec
.ad18xx
.unchained
[cidx1
] || ac97
->spec
.ad18xx
.chained
[cidx1
])
1421 if (ac97
->spec
.ad18xx
.unchained
[cidx2
] || ac97
->spec
.ad18xx
.chained
[cidx2
])
1423 if (cidx1
< 0 && cidx2
< 0)
1425 // test for chained codecs
1426 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1427 ac97
->spec
.ad18xx
.unchained
[unchained_idx
]);
1428 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0002); // ID1C
1429 ac97
->spec
.ad18xx
.codec_cfg
[unchained_idx
] = 0x0002;
1431 if (patch_ad1881_chained1(ac97
, cidx1
, 0x0006)) // SDIE | ID1C
1432 patch_ad1881_chained1(ac97
, cidx2
, 0);
1433 else if (patch_ad1881_chained1(ac97
, cidx2
, 0x0006)) // SDIE | ID1C
1434 patch_ad1881_chained1(ac97
, cidx1
, 0);
1435 } else if (cidx2
>= 0) {
1436 patch_ad1881_chained1(ac97
, cidx2
, 0);
1440 static struct snd_ac97_build_ops patch_ad1881_build_ops
= {
1442 .resume
= ad18xx_resume
1446 int patch_ad1881(struct snd_ac97
* ac97
)
1448 static const char cfg_idxs
[3][2] = {
1454 // patch for Analog Devices
1455 unsigned short codecs
[3];
1459 val
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1460 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, val
);
1461 codecs
[0] = patch_ad1881_unchained(ac97
, 0, (1<<12));
1462 codecs
[1] = patch_ad1881_unchained(ac97
, 1, (1<<14));
1463 codecs
[2] = patch_ad1881_unchained(ac97
, 2, (1<<13));
1465 if (! (codecs
[0] || codecs
[1] || codecs
[2]))
1468 for (idx
= 0; idx
< 3; idx
++)
1469 if (ac97
->spec
.ad18xx
.unchained
[idx
])
1470 patch_ad1881_chained(ac97
, idx
, cfg_idxs
[idx
][0], cfg_idxs
[idx
][1]);
1472 if (ac97
->spec
.ad18xx
.id
[1]) {
1473 ac97
->flags
|= AC97_AD_MULTI
;
1474 ac97
->scaps
|= AC97_SCAP_SURROUND_DAC
;
1476 if (ac97
->spec
.ad18xx
.id
[2]) {
1477 ac97
->flags
|= AC97_AD_MULTI
;
1478 ac97
->scaps
|= AC97_SCAP_CENTER_LFE_DAC
;
1482 /* select all codecs */
1483 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1484 /* check if only one codec is present */
1485 for (idx
= num
= 0; idx
< 3; idx
++)
1486 if (ac97
->spec
.ad18xx
.id
[idx
])
1489 /* ok, deselect all ID bits */
1490 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000);
1491 ac97
->spec
.ad18xx
.codec_cfg
[0] =
1492 ac97
->spec
.ad18xx
.codec_cfg
[1] =
1493 ac97
->spec
.ad18xx
.codec_cfg
[2] = 0x0000;
1495 /* required for AD1886/AD1885 combination */
1496 ac97
->ext_id
= snd_ac97_read(ac97
, AC97_EXTENDED_ID
);
1497 if (ac97
->spec
.ad18xx
.id
[0]) {
1498 ac97
->id
&= 0xffff0000;
1499 ac97
->id
|= ac97
->spec
.ad18xx
.id
[0];
1501 ac97
->build_ops
= &patch_ad1881_build_ops
;
1505 static const struct snd_kcontrol_new snd_ac97_controls_ad1885
[] = {
1506 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC
, 11, 1, 0),
1507 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1508 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC
, 14, 1, 0),
1509 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC
, 15, 1, 0),
1510 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 9, 1, 1), /* inverted */
1511 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 8, 1, 1), /* inverted */
1514 static int patch_ad1885_specific(struct snd_ac97
* ac97
)
1518 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_ad1885
, ARRAY_SIZE(snd_ac97_controls_ad1885
))) < 0)
1523 static struct snd_ac97_build_ops patch_ad1885_build_ops
= {
1524 .build_specific
= &patch_ad1885_specific
,
1526 .resume
= ad18xx_resume
1530 int patch_ad1885(struct snd_ac97
* ac97
)
1533 /* This is required to deal with the Intel D815EEAL2 */
1534 /* i.e. Line out is actually headphone out from codec */
1537 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, 0x0404);
1539 ac97
->build_ops
= &patch_ad1885_build_ops
;
1543 int patch_ad1886(struct snd_ac97
* ac97
)
1546 /* Presario700 workaround */
1547 /* for Jack Sense/SPDIF Register misetting causing */
1548 snd_ac97_write_cache(ac97
, AC97_AD_JACK_SPDIF
, 0x0010);
1553 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1554 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1555 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1556 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1557 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1558 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1559 #define AC97_AD198X_VREF_0 0x000c /* 0V */
1560 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1561 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1562 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1563 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1564 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1565 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1566 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1567 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1568 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1569 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1570 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1571 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1574 static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1576 static char *texts
[2] = { "AC-Link", "A/D Converter" };
1578 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1580 uinfo
->value
.enumerated
.items
= 2;
1581 if (uinfo
->value
.enumerated
.item
> 1)
1582 uinfo
->value
.enumerated
.item
= 1;
1583 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1587 static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1589 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1592 val
= ac97
->regs
[AC97_AD_SERIAL_CFG
];
1593 ucontrol
->value
.enumerated
.item
[0] = (val
>> 2) & 1;
1597 static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1599 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1602 if (ucontrol
->value
.enumerated
.item
[0] > 1)
1604 val
= ucontrol
->value
.enumerated
.item
[0] << 2;
1605 return snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x0004, val
);
1608 static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source
= {
1609 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1610 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
1611 .info
= snd_ac97_ad198x_spdif_source_info
,
1612 .get
= snd_ac97_ad198x_spdif_source_get
,
1613 .put
= snd_ac97_ad198x_spdif_source_put
,
1616 static int patch_ad198x_post_spdif(struct snd_ac97
* ac97
)
1618 return patch_build_controls(ac97
, &snd_ac97_ad198x_spdif_source
, 1);
1621 static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense
[] = {
1622 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 11, 1, 0),
1623 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
1626 /* black list to avoid HP/Line jack-sense controls
1627 * (SS vendor << 16 | device)
1629 static unsigned int ad1981_jacks_blacklist
[] = {
1630 0x10140554, /* Thinkpad T42p/R50p */
1634 static int check_list(struct snd_ac97
*ac97
, const unsigned int *list
)
1636 u32 subid
= ((u32
)ac97
->subsystem_vendor
<< 16) | ac97
->subsystem_device
;
1637 for (; *list
; list
++)
1643 static int patch_ad1981a_specific(struct snd_ac97
* ac97
)
1645 if (check_list(ac97
, ad1981_jacks_blacklist
))
1647 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1648 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1651 static struct snd_ac97_build_ops patch_ad1981a_build_ops
= {
1652 .build_post_spdif
= patch_ad198x_post_spdif
,
1653 .build_specific
= patch_ad1981a_specific
,
1655 .resume
= ad18xx_resume
1659 /* white list to enable HP jack-sense bits
1660 * (SS vendor << 16 | device)
1662 static unsigned int ad1981_jacks_whitelist
[] = {
1663 0x0e11005a, /* HP nc4000/4010 */
1664 0x103c0890, /* HP nc6000 */
1665 0x103c0938, /* HP nc4220 */
1666 0x103c099c, /* HP nx6110 */
1667 0x103c0944, /* HP nc6220 */
1668 0x103c0934, /* HP nc8220 */
1669 0x103c006d, /* HP nx9105 */
1670 0x17340088, /* FSC Scenic-W */
1674 static void check_ad1981_hp_jack_sense(struct snd_ac97
*ac97
)
1676 if (check_list(ac97
, ad1981_jacks_whitelist
))
1677 /* enable headphone jack sense */
1678 snd_ac97_update_bits(ac97
, AC97_AD_JACK_SPDIF
, 1<<11, 1<<11);
1681 int patch_ad1981a(struct snd_ac97
*ac97
)
1684 ac97
->build_ops
= &patch_ad1981a_build_ops
;
1685 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1686 ac97
->flags
|= AC97_STEREO_MUTES
;
1687 check_ad1981_hp_jack_sense(ac97
);
1691 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic
=
1692 AC97_SINGLE("Stereo Mic", AC97_AD_MISC
, 6, 1, 0);
1694 static int patch_ad1981b_specific(struct snd_ac97
*ac97
)
1698 if ((err
= patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1)) < 0)
1700 if (check_list(ac97
, ad1981_jacks_blacklist
))
1702 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1703 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1706 static struct snd_ac97_build_ops patch_ad1981b_build_ops
= {
1707 .build_post_spdif
= patch_ad198x_post_spdif
,
1708 .build_specific
= patch_ad1981b_specific
,
1710 .resume
= ad18xx_resume
1714 int patch_ad1981b(struct snd_ac97
*ac97
)
1717 ac97
->build_ops
= &patch_ad1981b_build_ops
;
1718 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1719 ac97
->flags
|= AC97_STEREO_MUTES
;
1720 check_ad1981_hp_jack_sense(ac97
);
1724 static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1726 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1728 uinfo
->value
.integer
.min
= 0;
1729 uinfo
->value
.integer
.max
= 1;
1733 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1735 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1738 val
= ac97
->regs
[AC97_AD_MISC
];
1739 ucontrol
->value
.integer
.value
[0] = !(val
& AC97_AD198X_LOSEL
);
1743 static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1745 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1748 val
= !ucontrol
->value
.integer
.value
[0]
1749 ? (AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
) : 0;
1750 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1751 AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
, val
);
1754 static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1756 static char *texts
[3] = {"Off", "6 -> 4", "6 -> 2"};
1758 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1760 uinfo
->value
.enumerated
.items
= 3;
1761 if (uinfo
->value
.enumerated
.item
> 2)
1762 uinfo
->value
.enumerated
.item
= 2;
1763 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1767 static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1769 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1772 val
= ac97
->regs
[AC97_AD_MISC
];
1773 if (!(val
& AC97_AD198X_DMIX1
))
1774 ucontrol
->value
.enumerated
.item
[0] = 0;
1776 ucontrol
->value
.enumerated
.item
[0] = 1 + ((val
>> 8) & 1);
1780 static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1782 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1785 if (ucontrol
->value
.enumerated
.item
[0] > 2)
1787 if (ucontrol
->value
.enumerated
.item
[0] == 0)
1790 val
= AC97_AD198X_DMIX1
|
1791 ((ucontrol
->value
.enumerated
.item
[0] - 1) << 8);
1792 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1793 AC97_AD198X_DMIX0
| AC97_AD198X_DMIX1
, val
);
1796 static void ad1888_update_jacks(struct snd_ac97
*ac97
)
1798 unsigned short val
= 0;
1799 if (! is_shared_linein(ac97
))
1801 if (! is_shared_micin(ac97
))
1803 /* shared Line-In */
1804 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, (1 << 11) | (1 << 12), val
);
1807 static const struct snd_kcontrol_new snd_ac97_ad1888_controls
[] = {
1809 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1810 .name
= "Exchange Front/Surround",
1811 .info
= snd_ac97_ad1888_lohpsel_info
,
1812 .get
= snd_ac97_ad1888_lohpsel_get
,
1813 .put
= snd_ac97_ad1888_lohpsel_put
1815 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC
, 7, 1, 0),
1817 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1819 .info
= snd_ac97_ad1888_downmix_info
,
1820 .get
= snd_ac97_ad1888_downmix_get
,
1821 .put
= snd_ac97_ad1888_downmix_put
1823 AC97_SURROUND_JACK_MODE_CTL
,
1824 AC97_CHANNEL_MODE_CTL
,
1826 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 10, 1, 0),
1827 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
1830 static int patch_ad1888_specific(struct snd_ac97
*ac97
)
1832 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1833 snd_ac97_rename_vol_ctl(ac97
, "Master Playback", "Master Surround Playback");
1834 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Master Playback");
1835 return patch_build_controls(ac97
, snd_ac97_ad1888_controls
, ARRAY_SIZE(snd_ac97_ad1888_controls
));
1838 static struct snd_ac97_build_ops patch_ad1888_build_ops
= {
1839 .build_post_spdif
= patch_ad198x_post_spdif
,
1840 .build_specific
= patch_ad1888_specific
,
1842 .resume
= ad18xx_resume
,
1844 .update_jacks
= ad1888_update_jacks
,
1847 int patch_ad1888(struct snd_ac97
* ac97
)
1849 unsigned short misc
;
1852 ac97
->build_ops
= &patch_ad1888_build_ops
;
1853 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1854 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1855 /* AD-compatible mode */
1856 /* Stereo mutes enabled */
1857 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
1858 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
1862 AC97_AD198X_AC97NC
);
1863 ac97
->flags
|= AC97_STEREO_MUTES
;
1867 static int patch_ad1980_specific(struct snd_ac97
*ac97
)
1871 if ((err
= patch_ad1888_specific(ac97
)) < 0)
1873 return patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1);
1876 static struct snd_ac97_build_ops patch_ad1980_build_ops
= {
1877 .build_post_spdif
= patch_ad198x_post_spdif
,
1878 .build_specific
= patch_ad1980_specific
,
1880 .resume
= ad18xx_resume
,
1882 .update_jacks
= ad1888_update_jacks
,
1885 int patch_ad1980(struct snd_ac97
* ac97
)
1888 ac97
->build_ops
= &patch_ad1980_build_ops
;
1892 static const struct snd_kcontrol_new snd_ac97_ad1985_controls
[] = {
1893 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG
, 3, 1, 0)
1896 static void ad1985_update_jacks(struct snd_ac97
*ac97
)
1898 ad1888_update_jacks(ac97
);
1899 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 1 << 9,
1900 is_shared_micin(ac97
) ? 0 : 1 << 9);
1903 static int patch_ad1985_specific(struct snd_ac97
*ac97
)
1907 if ((err
= patch_ad1980_specific(ac97
)) < 0)
1909 return patch_build_controls(ac97
, snd_ac97_ad1985_controls
, ARRAY_SIZE(snd_ac97_ad1985_controls
));
1912 static struct snd_ac97_build_ops patch_ad1985_build_ops
= {
1913 .build_post_spdif
= patch_ad198x_post_spdif
,
1914 .build_specific
= patch_ad1985_specific
,
1916 .resume
= ad18xx_resume
,
1918 .update_jacks
= ad1985_update_jacks
,
1921 int patch_ad1985(struct snd_ac97
* ac97
)
1923 unsigned short misc
;
1926 ac97
->build_ops
= &patch_ad1985_build_ops
;
1927 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
1928 /* switch front/surround line-out/hp-out */
1929 /* center/LFE, mic in 3.75V mode */
1930 /* AD-compatible mode */
1931 /* Stereo mutes enabled */
1932 /* in accordance with ADI driver: misc | 0x5c28 */
1933 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
1940 AC97_AD198X_AC97NC
);
1941 ac97
->flags
|= AC97_STEREO_MUTES
;
1942 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1943 ac97
->ext_id
= (ac97
->ext_id
& ~AC97_EI_REV_MASK
) | AC97_EI_REV_23
;
1948 * realtek ALC65x/850 codecs
1950 static void alc650_update_jacks(struct snd_ac97
*ac97
)
1954 /* shared Line-In */
1955 shared
= is_shared_linein(ac97
);
1956 snd_ac97_update_bits(ac97
, AC97_ALC650_MULTICH
, 1 << 9,
1957 shared
? (1 << 9) : 0);
1958 /* update shared Mic */
1959 shared
= is_shared_micin(ac97
);
1960 /* disable/enable vref */
1961 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
1962 shared
? (1 << 12) : 0);
1963 /* turn on/off center-on-mic */
1964 snd_ac97_update_bits(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
1965 shared
? (1 << 10) : 0);
1966 /* GPIO0 high for mic */
1967 snd_ac97_update_bits(ac97
, AC97_ALC650_GPIO_STATUS
, 0x100,
1968 shared
? 0 : 0x100);
1971 static const struct snd_kcontrol_new snd_ac97_controls_alc650
[] = {
1972 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0),
1973 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH
, 1, 1, 0),
1974 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH
, 2, 1, 0),
1975 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH
, 3, 1, 0),
1976 /* 4: Analog Input To Surround */
1977 /* 5: Analog Input To Center/LFE */
1978 /* 6: Independent Master Volume Right */
1979 /* 7: Independent Master Volume Left */
1981 /* 9: Line-In/Surround share */
1982 /* 10: Mic/CLFE share */
1983 /* 11-13: in IEC958 controls */
1984 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH
, 14, 1, 0),
1985 #if 0 /* always set in patch_alc650 */
1986 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK
, 0, 1, 0),
1987 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK
, 1, 1, 0),
1988 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL
, 15, 1, 1),
1989 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL
, 8, 0, 31, 1),
1990 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL
, 15, 1, 1),
1991 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL
, 8, 0, 31, 1),
1993 AC97_SURROUND_JACK_MODE_CTL
,
1994 AC97_CHANNEL_MODE_CTL
,
1997 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650
[] = {
1998 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_ALC650_MULTICH
, 11, 1, 0),
1999 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH
, 12, 1, 0),
2000 /* disable this controls since it doesn't work as expected */
2001 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2004 static int patch_alc650_specific(struct snd_ac97
* ac97
)
2008 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc650
, ARRAY_SIZE(snd_ac97_controls_alc650
))) < 0)
2010 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2011 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc650
, ARRAY_SIZE(snd_ac97_spdif_controls_alc650
))) < 0)
2017 static struct snd_ac97_build_ops patch_alc650_ops
= {
2018 .build_specific
= patch_alc650_specific
,
2019 .update_jacks
= alc650_update_jacks
2022 int patch_alc650(struct snd_ac97
* ac97
)
2026 ac97
->build_ops
= &patch_alc650_ops
;
2028 /* determine the revision */
2029 val
= snd_ac97_read(ac97
, AC97_ALC650_REVISION
) & 0x3f;
2031 ac97
->id
= 0x414c4720; /* Old version */
2032 else if (val
< 0x10)
2033 ac97
->id
= 0x414c4721; /* D version */
2034 else if (val
< 0x20)
2035 ac97
->id
= 0x414c4722; /* E version */
2036 else if (val
< 0x30)
2037 ac97
->id
= 0x414c4723; /* F version */
2039 /* revision E or F */
2040 /* FIXME: what about revision D ? */
2041 ac97
->spec
.dev_flags
= (ac97
->id
== 0x414c4722 ||
2042 ac97
->id
== 0x414c4723);
2044 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2045 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
2046 snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x8000);
2048 /* Enable SPDIF-IN only on Rev.E and above */
2049 val
= snd_ac97_read(ac97
, AC97_ALC650_CLOCK
);
2050 /* SPDIF IN with pin 47 */
2051 if (ac97
->spec
.dev_flags
)
2052 val
|= 0x03; /* enable */
2054 val
&= ~0x03; /* disable */
2055 snd_ac97_write_cache(ac97
, AC97_ALC650_CLOCK
, val
);
2057 /* set default: slot 3,4,7,8,6,9
2058 spdif-in monitor off, analog-spdif off, spdif-in off
2059 center on mic off, surround on line-in off
2060 downmix off, duplicate front off
2062 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 0);
2064 /* set GPIO0 for mic bias */
2065 /* GPIO0 pin output, no interrupt, high */
2066 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_SETUP
,
2067 snd_ac97_read(ac97
, AC97_ALC650_GPIO_SETUP
) | 0x01);
2068 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
2069 (snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x100) & ~0x10);
2071 /* full DAC volume */
2072 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2073 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2077 static void alc655_update_jacks(struct snd_ac97
*ac97
)
2081 /* shared Line-In */
2082 shared
= is_shared_linein(ac97
);
2083 ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 1 << 9,
2084 shared
? (1 << 9) : 0, 0);
2085 /* update shared mic */
2086 shared
= is_shared_micin(ac97
);
2087 /* misc control; vrefout disable */
2088 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
2089 shared
? (1 << 12) : 0);
2090 ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
2091 shared
? (1 << 10) : 0, 0);
2094 static const struct snd_kcontrol_new snd_ac97_controls_alc655
[] = {
2095 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
2096 AC97_SURROUND_JACK_MODE_CTL
,
2097 AC97_CHANNEL_MODE_CTL
,
2100 static int alc655_iec958_route_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2102 static char *texts_655
[3] = { "PCM", "Analog In", "IEC958 In" };
2103 static char *texts_658
[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2104 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2106 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2108 uinfo
->value
.enumerated
.items
= ac97
->spec
.dev_flags
? 4 : 3;
2109 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2110 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2111 strcpy(uinfo
->value
.enumerated
.name
,
2112 ac97
->spec
.dev_flags
?
2113 texts_658
[uinfo
->value
.enumerated
.item
] :
2114 texts_655
[uinfo
->value
.enumerated
.item
]);
2118 static int alc655_iec958_route_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2120 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2123 val
= ac97
->regs
[AC97_ALC650_MULTICH
];
2124 val
= (val
>> 12) & 3;
2125 if (ac97
->spec
.dev_flags
&& val
== 3)
2127 ucontrol
->value
.enumerated
.item
[0] = val
;
2131 static int alc655_iec958_route_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2133 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2135 return ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 3 << 12,
2136 (unsigned short)ucontrol
->value
.enumerated
.item
[0] << 12,
2140 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655
[] = {
2141 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_ALC650_MULTICH
, 11, 1, 0, 0),
2142 /* disable this controls since it doesn't work as expected */
2143 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2145 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2146 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
2147 .info
= alc655_iec958_route_info
,
2148 .get
= alc655_iec958_route_get
,
2149 .put
= alc655_iec958_route_put
,
2153 static int patch_alc655_specific(struct snd_ac97
* ac97
)
2157 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc655
, ARRAY_SIZE(snd_ac97_controls_alc655
))) < 0)
2159 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2160 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
2166 static struct snd_ac97_build_ops patch_alc655_ops
= {
2167 .build_specific
= patch_alc655_specific
,
2168 .update_jacks
= alc655_update_jacks
2171 int patch_alc655(struct snd_ac97
* ac97
)
2175 if (ac97
->id
== AC97_ID_ALC658
) {
2176 ac97
->spec
.dev_flags
= 1; /* ALC658 */
2177 if ((snd_ac97_read(ac97
, AC97_ALC650_REVISION
) & 0x3f) == 2) {
2178 ac97
->id
= AC97_ID_ALC658D
;
2179 ac97
->spec
.dev_flags
= 2;
2183 ac97
->build_ops
= &patch_alc655_ops
;
2185 /* assume only page 0 for writing cache */
2186 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
2188 /* adjust default values */
2189 val
= snd_ac97_read(ac97
, 0x7a); /* misc control */
2190 if (ac97
->spec
.dev_flags
) /* ALC658 */
2191 val
&= ~(1 << 1); /* Pin 47 is spdif input pin */
2193 if (ac97
->subsystem_vendor
== 0x1462 &&
2194 ac97
->subsystem_device
== 0x0131) /* MSI S270 laptop */
2195 val
&= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2197 val
|= (1 << 1); /* Pin 47 is spdif input pin */
2199 val
&= ~(1 << 12); /* vref enable */
2200 snd_ac97_write_cache(ac97
, 0x7a, val
);
2201 /* set default: spdif-in enabled,
2202 spdif-in monitor off, spdif-in PCM off
2203 center on mic off, surround on line-in off
2206 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
2208 /* full DAC volume */
2209 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2210 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2212 /* update undocumented bit... */
2213 if (ac97
->id
== AC97_ID_ALC658D
)
2214 snd_ac97_update_bits(ac97
, 0x74, 0x0800, 0x0800);
2220 #define AC97_ALC850_JACK_SELECT 0x76
2221 #define AC97_ALC850_MISC1 0x7a
2223 static void alc850_update_jacks(struct snd_ac97
*ac97
)
2227 /* shared Line-In */
2228 shared
= is_shared_linein(ac97
);
2229 /* SURR 1kOhm (bit4), Amp (bit5) */
2230 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<4)|(1<<5),
2231 shared
? (1<<5) : (1<<4));
2232 /* LINE-IN = 0, SURROUND = 2 */
2233 snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 12,
2234 shared
? (2<<12) : (0<<12));
2235 /* update shared mic */
2236 shared
= is_shared_micin(ac97
);
2237 /* Vref disable (bit12), 1kOhm (bit13) */
2238 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<12)|(1<<13),
2239 shared
? (1<<12) : (1<<13));
2240 /* MIC-IN = 1, CENTER-LFE = 5 */
2241 snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 4,
2242 shared
? (5<<4) : (1<<4));
2245 static const struct snd_kcontrol_new snd_ac97_controls_alc850
[] = {
2246 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
2247 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT
, 15, 1, 1),
2248 AC97_SURROUND_JACK_MODE_CTL
,
2249 AC97_CHANNEL_MODE_CTL
,
2252 static int patch_alc850_specific(struct snd_ac97
*ac97
)
2256 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc850
, ARRAY_SIZE(snd_ac97_controls_alc850
))) < 0)
2258 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2259 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
2265 static struct snd_ac97_build_ops patch_alc850_ops
= {
2266 .build_specific
= patch_alc850_specific
,
2267 .update_jacks
= alc850_update_jacks
2270 int patch_alc850(struct snd_ac97
*ac97
)
2272 ac97
->build_ops
= &patch_alc850_ops
;
2274 ac97
->spec
.dev_flags
= 0; /* for IEC958 playback route - ALC655 compatible */
2276 /* assume only page 0 for writing cache */
2277 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
2279 /* adjust default values */
2280 /* set default: spdif-in enabled,
2281 spdif-in monitor off, spdif-in PCM off
2282 center on mic off, surround on line-in off
2285 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
2286 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2287 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2289 snd_ac97_write_cache(ac97
, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2290 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2291 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2292 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2294 snd_ac97_write_cache(ac97
, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2295 (1<<11)|(0<<12)|(1<<15));
2297 /* full DAC volume */
2298 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2299 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2305 * C-Media CM97xx codecs
2307 static void cm9738_update_jacks(struct snd_ac97
*ac97
)
2309 /* shared Line-In */
2310 snd_ac97_update_bits(ac97
, AC97_CM9738_VENDOR_CTRL
, 1 << 10,
2311 is_shared_linein(ac97
) ? (1 << 10) : 0);
2314 static const struct snd_kcontrol_new snd_ac97_cm9738_controls
[] = {
2315 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL
, 13, 1, 0),
2316 AC97_SURROUND_JACK_MODE_CTL
,
2317 AC97_CHANNEL_MODE_4CH_CTL
,
2320 static int patch_cm9738_specific(struct snd_ac97
* ac97
)
2322 return patch_build_controls(ac97
, snd_ac97_cm9738_controls
, ARRAY_SIZE(snd_ac97_cm9738_controls
));
2325 static struct snd_ac97_build_ops patch_cm9738_ops
= {
2326 .build_specific
= patch_cm9738_specific
,
2327 .update_jacks
= cm9738_update_jacks
2330 int patch_cm9738(struct snd_ac97
* ac97
)
2332 ac97
->build_ops
= &patch_cm9738_ops
;
2333 /* FIXME: can anyone confirm below? */
2334 /* CM9738 has no PCM volume although the register reacts */
2335 ac97
->flags
|= AC97_HAS_NO_PCM_VOL
;
2336 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
2341 static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2343 static char *texts
[] = { "Analog", "Digital" };
2345 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2347 uinfo
->value
.enumerated
.items
= 2;
2348 if (uinfo
->value
.enumerated
.item
> 1)
2349 uinfo
->value
.enumerated
.item
= 1;
2350 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2354 static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2356 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2359 val
= ac97
->regs
[AC97_CM9739_SPDIF_CTRL
];
2360 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 0x01;
2364 static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2366 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2368 return snd_ac97_update_bits(ac97
, AC97_CM9739_SPDIF_CTRL
,
2370 (ucontrol
->value
.enumerated
.item
[0] & 0x01) << 1);
2373 static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif
[] = {
2374 /* BIT 0: SPDI_EN - always true */
2375 { /* BIT 1: SPDIFS */
2376 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2377 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
2378 .info
= snd_ac97_cmedia_spdif_playback_source_info
,
2379 .get
= snd_ac97_cmedia_spdif_playback_source_get
,
2380 .put
= snd_ac97_cmedia_spdif_playback_source_put
,
2382 /* BIT 2: IG_SPIV */
2383 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Valid Switch", AC97_CM9739_SPDIF_CTRL
, 2, 1, 0),
2385 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Monitor", AC97_CM9739_SPDIF_CTRL
, 3, 1, 0),
2386 /* BIT 4: SPI2SDI */
2387 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_CM9739_SPDIF_CTRL
, 4, 1, 0),
2388 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2391 static void cm9739_update_jacks(struct snd_ac97
*ac97
)
2393 /* shared Line-In */
2394 snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 1 << 10,
2395 is_shared_linein(ac97
) ? (1 << 10) : 0);
2397 snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 0x3000,
2398 is_shared_micin(ac97
) ? 0x1000 : 0x2000);
2401 static const struct snd_kcontrol_new snd_ac97_cm9739_controls
[] = {
2402 AC97_SURROUND_JACK_MODE_CTL
,
2403 AC97_CHANNEL_MODE_CTL
,
2406 static int patch_cm9739_specific(struct snd_ac97
* ac97
)
2408 return patch_build_controls(ac97
, snd_ac97_cm9739_controls
, ARRAY_SIZE(snd_ac97_cm9739_controls
));
2411 static int patch_cm9739_post_spdif(struct snd_ac97
* ac97
)
2413 return patch_build_controls(ac97
, snd_ac97_cm9739_controls_spdif
, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif
));
2416 static struct snd_ac97_build_ops patch_cm9739_ops
= {
2417 .build_specific
= patch_cm9739_specific
,
2418 .build_post_spdif
= patch_cm9739_post_spdif
,
2419 .update_jacks
= cm9739_update_jacks
2422 int patch_cm9739(struct snd_ac97
* ac97
)
2426 ac97
->build_ops
= &patch_cm9739_ops
;
2428 /* CM9739/A has no Master and PCM volume although the register reacts */
2429 ac97
->flags
|= AC97_HAS_NO_MASTER_VOL
| AC97_HAS_NO_PCM_VOL
;
2430 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8000);
2431 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
2434 val
= snd_ac97_read(ac97
, AC97_EXTENDED_STATUS
);
2435 if (val
& AC97_EA_SPCV
) {
2436 /* enable spdif in */
2437 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
2438 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) | 0x01);
2439 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2441 ac97
->ext_id
&= ~AC97_EI_SPDIF
; /* disable extended-id */
2442 ac97
->rates
[AC97_RATES_SPDIF
] = 0;
2445 /* set-up multi channel */
2446 /* bit 14: 0 = SPDIF, 1 = EAPD */
2447 /* bit 13: enable internal vref output for mic */
2448 /* bit 12: disable center/lfe (swithable) */
2449 /* bit 10: disable surround/line (switchable) */
2450 /* bit 9: mix 2 surround off */
2451 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2452 /* bit 3: undocumented; surround? */
2454 val
= snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) & (1 << 4);
2457 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
2459 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
, val
);
2461 /* FIXME: set up GPIO */
2462 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
2463 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
2464 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2466 ac97
->subsystem_vendor
== 0x1043 &&
2467 ac97
->subsystem_device
== 0x1843) {
2468 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
2469 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) & ~0x01);
2470 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
,
2471 snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) | (1 << 14));
2477 #define AC97_CM9761_MULTI_CHAN 0x64
2478 #define AC97_CM9761_FUNC 0x66
2479 #define AC97_CM9761_SPDIF_CTRL 0x6c
2481 static void cm9761_update_jacks(struct snd_ac97
*ac97
)
2483 /* FIXME: check the bits for each model
2484 * model 83 is confirmed to work
2486 static unsigned short surr_on
[3][2] = {
2487 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2488 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2489 { 0x0000, 0x0008 }, /* 9761-83 */
2491 static unsigned short clfe_on
[3][2] = {
2492 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2493 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2494 { 0x0000, 0x1000 }, /* 9761-83 */
2496 static unsigned short surr_shared
[3][2] = {
2497 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2498 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2499 { 0x0000, 0x0400 }, /* 9761-83 */
2501 static unsigned short clfe_shared
[3][2] = {
2502 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2503 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2504 { 0x2000, 0x0800 }, /* 9761-83 */
2506 unsigned short val
= 0;
2508 val
|= surr_on
[ac97
->spec
.dev_flags
][is_surround_on(ac97
)];
2509 val
|= clfe_on
[ac97
->spec
.dev_flags
][is_clfe_on(ac97
)];
2510 val
|= surr_shared
[ac97
->spec
.dev_flags
][is_shared_linein(ac97
)];
2511 val
|= clfe_shared
[ac97
->spec
.dev_flags
][is_shared_micin(ac97
)];
2513 snd_ac97_update_bits(ac97
, AC97_CM9761_MULTI_CHAN
, 0x3c88, val
);
2516 static const struct snd_kcontrol_new snd_ac97_cm9761_controls
[] = {
2517 AC97_SURROUND_JACK_MODE_CTL
,
2518 AC97_CHANNEL_MODE_CTL
,
2521 static int cm9761_spdif_out_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2523 static char *texts
[] = { "AC-Link", "ADC", "SPDIF-In" };
2525 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2527 uinfo
->value
.enumerated
.items
= 3;
2528 if (uinfo
->value
.enumerated
.item
> 2)
2529 uinfo
->value
.enumerated
.item
= 2;
2530 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2534 static int cm9761_spdif_out_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2536 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2538 if (ac97
->regs
[AC97_CM9761_FUNC
] & 0x1)
2539 ucontrol
->value
.enumerated
.item
[0] = 2; /* SPDIF-loopback */
2540 else if (ac97
->regs
[AC97_CM9761_SPDIF_CTRL
] & 0x2)
2541 ucontrol
->value
.enumerated
.item
[0] = 1; /* ADC loopback */
2543 ucontrol
->value
.enumerated
.item
[0] = 0; /* AC-link */
2547 static int cm9761_spdif_out_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2549 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2551 if (ucontrol
->value
.enumerated
.item
[0] == 2)
2552 return snd_ac97_update_bits(ac97
, AC97_CM9761_FUNC
, 0x1, 0x1);
2553 snd_ac97_update_bits(ac97
, AC97_CM9761_FUNC
, 0x1, 0);
2554 return snd_ac97_update_bits(ac97
, AC97_CM9761_SPDIF_CTRL
, 0x2,
2555 ucontrol
->value
.enumerated
.item
[0] == 1 ? 0x2 : 0);
2558 static const char *cm9761_dac_clock
[] = { "AC-Link", "SPDIF-In", "Both" };
2559 static const struct ac97_enum cm9761_dac_clock_enum
=
2560 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL
, 9, 3, cm9761_dac_clock
);
2562 static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif
[] = {
2563 { /* BIT 1: SPDIFS */
2564 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2565 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
2566 .info
= cm9761_spdif_out_source_info
,
2567 .get
= cm9761_spdif_out_source_get
,
2568 .put
= cm9761_spdif_out_source_put
,
2570 /* BIT 2: IG_SPIV */
2571 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Valid Switch", AC97_CM9761_SPDIF_CTRL
, 2, 1, 0),
2573 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Monitor", AC97_CM9761_SPDIF_CTRL
, 3, 1, 0),
2574 /* BIT 4: SPI2SDI */
2575 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_CM9761_SPDIF_CTRL
, 4, 1, 0),
2576 /* BIT 9-10: DAC_CTL */
2577 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum
),
2580 static int patch_cm9761_post_spdif(struct snd_ac97
* ac97
)
2582 return patch_build_controls(ac97
, snd_ac97_cm9761_controls_spdif
, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif
));
2585 static int patch_cm9761_specific(struct snd_ac97
* ac97
)
2587 return patch_build_controls(ac97
, snd_ac97_cm9761_controls
, ARRAY_SIZE(snd_ac97_cm9761_controls
));
2590 static struct snd_ac97_build_ops patch_cm9761_ops
= {
2591 .build_specific
= patch_cm9761_specific
,
2592 .build_post_spdif
= patch_cm9761_post_spdif
,
2593 .update_jacks
= cm9761_update_jacks
2596 int patch_cm9761(struct snd_ac97
*ac97
)
2600 /* CM9761 has no PCM volume although the register reacts */
2601 /* Master volume seems to have _some_ influence on the analog
2604 ac97
->flags
|= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL
;
2605 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8808);
2606 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8808);
2608 ac97
->spec
.dev_flags
= 0; /* 1 = model 82 revision B, 2 = model 83 */
2609 if (ac97
->id
== AC97_ID_CM9761_82
) {
2611 /* check page 1, reg 0x60 */
2612 val
= snd_ac97_read(ac97
, AC97_INT_PAGING
);
2613 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, (val
& ~0x0f) | 0x01);
2614 tmp
= snd_ac97_read(ac97
, 0x60);
2615 ac97
->spec
.dev_flags
= tmp
& 1; /* revision B? */
2616 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, val
);
2617 } else if (ac97
->id
== AC97_ID_CM9761_83
)
2618 ac97
->spec
.dev_flags
= 2;
2620 ac97
->build_ops
= &patch_cm9761_ops
;
2623 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2624 ac97
->ext_id
|= AC97_EI_SPDIF
;
2625 /* to be sure: we overwrite the ext status bits */
2626 snd_ac97_write_cache(ac97
, AC97_EXTENDED_STATUS
, 0x05c0);
2627 /* Don't set 0x0200 here. This results in the silent analog output */
2628 snd_ac97_write_cache(ac97
, AC97_CM9761_SPDIF_CTRL
, 0x0001); /* enable spdif-in */
2629 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2631 /* set-up multi channel */
2632 /* bit 15: pc master beep off
2633 * bit 14: pin47 = EAPD/SPDIF
2634 * bit 13: vref ctl [= cm9739]
2635 * bit 12: CLFE control (reverted on rev B)
2636 * bit 11: Mic/center share (reverted on rev B)
2637 * bit 10: suddound/line share
2638 * bit 9: Analog-in mix -> surround
2639 * bit 8: Analog-in mix -> CLFE
2640 * bit 7: Mic/LFE share (mic/center/lfe)
2641 * bit 5: vref select (9761A)
2642 * bit 4: front control
2643 * bit 3: surround control (revereted with rev B)
2646 * bit 0: mic boost level (0=20dB, 1=30dB)
2650 if (ac97
->spec
.dev_flags
)
2655 val
= snd_ac97_read(ac97
, AC97_CM9761_MULTI_CHAN
);
2656 val
|= (1 << 4); /* front on */
2657 snd_ac97_write_cache(ac97
, AC97_CM9761_MULTI_CHAN
, val
);
2659 /* FIXME: set up GPIO */
2660 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
2661 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
2666 #define AC97_CM9780_SIDE 0x60
2667 #define AC97_CM9780_JACK 0x62
2668 #define AC97_CM9780_MIXER 0x64
2669 #define AC97_CM9780_MULTI_CHAN 0x66
2670 #define AC97_CM9780_SPDIF 0x6c
2672 static const char *cm9780_ch_select
[] = { "Front", "Side", "Center/LFE", "Rear" };
2673 static const struct ac97_enum cm9780_ch_select_enum
=
2674 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN
, 6, 4, cm9780_ch_select
);
2675 static const struct snd_kcontrol_new cm9780_controls
[] = {
2676 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE
, 15, 7, 1, 1),
2677 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE
, 8, 0, 31, 0),
2678 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum
),
2681 static int patch_cm9780_specific(struct snd_ac97
*ac97
)
2683 return patch_build_controls(ac97
, cm9780_controls
, ARRAY_SIZE(cm9780_controls
));
2686 static struct snd_ac97_build_ops patch_cm9780_ops
= {
2687 .build_specific
= patch_cm9780_specific
,
2688 .build_post_spdif
= patch_cm9761_post_spdif
/* identical with CM9761 */
2691 int patch_cm9780(struct snd_ac97
*ac97
)
2695 ac97
->build_ops
= &patch_cm9780_ops
;
2698 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2699 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2700 val
= snd_ac97_read(ac97
, AC97_CM9780_SPDIF
);
2701 val
|= 0x1; /* SPDI_EN */
2702 snd_ac97_write_cache(ac97
, AC97_CM9780_SPDIF
, val
);
2711 static const struct snd_kcontrol_new snd_ac97_controls_vt1616
[] = {
2712 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2713 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2714 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2715 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2718 static int patch_vt1616_specific(struct snd_ac97
* ac97
)
2722 if (snd_ac97_try_bit(ac97
, 0x5a, 9))
2723 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[0], 1)) < 0)
2725 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[1], ARRAY_SIZE(snd_ac97_controls_vt1616
) - 1)) < 0)
2730 static struct snd_ac97_build_ops patch_vt1616_ops
= {
2731 .build_specific
= patch_vt1616_specific
2734 int patch_vt1616(struct snd_ac97
* ac97
)
2736 ac97
->build_ops
= &patch_vt1616_ops
;
2743 int patch_vt1617a(struct snd_ac97
* ac97
)
2745 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
2746 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
;
2752 static void it2646_update_jacks(struct snd_ac97
*ac97
)
2754 /* shared Line-In */
2755 snd_ac97_update_bits(ac97
, 0x76, 1 << 9,
2756 is_shared_linein(ac97
) ? (1<<9) : 0);
2758 snd_ac97_update_bits(ac97
, 0x76, 1 << 10,
2759 is_shared_micin(ac97
) ? (1<<10) : 0);
2762 static const struct snd_kcontrol_new snd_ac97_controls_it2646
[] = {
2763 AC97_SURROUND_JACK_MODE_CTL
,
2764 AC97_CHANNEL_MODE_CTL
,
2767 static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646
[] = {
2768 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), 0x76, 11, 1, 0),
2769 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2770 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2773 static int patch_it2646_specific(struct snd_ac97
* ac97
)
2776 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_it2646
, ARRAY_SIZE(snd_ac97_controls_it2646
))) < 0)
2778 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_it2646
, ARRAY_SIZE(snd_ac97_spdif_controls_it2646
))) < 0)
2783 static struct snd_ac97_build_ops patch_it2646_ops
= {
2784 .build_specific
= patch_it2646_specific
,
2785 .update_jacks
= it2646_update_jacks
2788 int patch_it2646(struct snd_ac97
* ac97
)
2790 ac97
->build_ops
= &patch_it2646_ops
;
2791 /* full DAC volume */
2792 snd_ac97_write_cache(ac97
, 0x5E, 0x0808);
2793 snd_ac97_write_cache(ac97
, 0x7A, 0x0808);
2801 #define AC97_SI3036_CHIP_ID 0x5a
2802 #define AC97_SI3036_LINE_CFG 0x5c
2804 static const struct snd_kcontrol_new snd_ac97_controls_si3036
[] = {
2805 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2808 static int patch_si3036_specific(struct snd_ac97
* ac97
)
2811 for (idx
= 0; idx
< ARRAY_SIZE(snd_ac97_controls_si3036
); idx
++)
2812 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ctl_new1(&snd_ac97_controls_si3036
[idx
], ac97
))) < 0)
2817 static struct snd_ac97_build_ops patch_si3036_ops
= {
2818 .build_specific
= patch_si3036_specific
,
2821 int mpatch_si3036(struct snd_ac97
* ac97
)
2823 ac97
->build_ops
= &patch_si3036_ops
;
2824 snd_ac97_write_cache(ac97
, 0x5c, 0xf210 );
2825 snd_ac97_write_cache(ac97
, 0x68, 0);