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/tlv.h>
36 #include <sound/ac97_codec.h>
37 #include "ac97_patch.h"
39 #include "ac97_local.h"
42 * Chip specific initialization
45 static int patch_build_controls(struct snd_ac97
* ac97
, const struct snd_kcontrol_new
*controls
, int count
)
49 for (idx
= 0; idx
< count
; idx
++)
50 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&controls
[idx
], ac97
))) < 0)
55 /* replace with a new TLV */
56 static void reset_tlv(struct snd_ac97
*ac97
, const char *name
,
57 const unsigned int *tlv
)
59 struct snd_ctl_elem_id sid
;
60 struct snd_kcontrol
*kctl
;
61 memset(&sid
, 0, sizeof(sid
));
62 strcpy(sid
.name
, name
);
63 sid
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
64 kctl
= snd_ctl_find_id(ac97
->bus
->card
, &sid
);
65 if (kctl
&& kctl
->tlv
.p
)
69 /* set to the page, update bits and restore the page */
70 static int ac97_update_bits_page(struct snd_ac97
*ac97
, unsigned short reg
, unsigned short mask
, unsigned short value
, unsigned short page
)
72 unsigned short page_save
;
75 mutex_lock(&ac97
->page_mutex
);
76 page_save
= snd_ac97_read(ac97
, AC97_INT_PAGING
) & AC97_PAGE_MASK
;
77 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page
);
78 ret
= snd_ac97_update_bits(ac97
, reg
, mask
, value
);
79 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, page_save
);
80 mutex_unlock(&ac97
->page_mutex
); /* unlock paging */
85 * shared line-in/mic controls
87 static int ac97_enum_text_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
,
88 const char **texts
, unsigned int nums
)
90 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
92 uinfo
->value
.enumerated
.items
= nums
;
93 if (uinfo
->value
.enumerated
.item
> nums
- 1)
94 uinfo
->value
.enumerated
.item
= nums
- 1;
95 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
99 static int ac97_surround_jack_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
101 static const char *texts
[] = { "Shared", "Independent" };
102 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 2);
105 static int ac97_surround_jack_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
107 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
109 ucontrol
->value
.enumerated
.item
[0] = ac97
->indep_surround
;
113 static int ac97_surround_jack_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
115 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
116 unsigned char indep
= !!ucontrol
->value
.enumerated
.item
[0];
118 if (indep
!= ac97
->indep_surround
) {
119 ac97
->indep_surround
= indep
;
120 if (ac97
->build_ops
->update_jacks
)
121 ac97
->build_ops
->update_jacks(ac97
);
127 static int ac97_channel_mode_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
129 static const char *texts
[] = { "2ch", "4ch", "6ch" };
130 if (kcontrol
->private_value
)
131 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 2); /* 4ch only */
132 return ac97_enum_text_info(kcontrol
, uinfo
, texts
, 3);
135 static int ac97_channel_mode_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
137 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
139 ucontrol
->value
.enumerated
.item
[0] = ac97
->channel_mode
;
143 static int ac97_channel_mode_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
145 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
146 unsigned char mode
= ucontrol
->value
.enumerated
.item
[0];
148 if (mode
!= ac97
->channel_mode
) {
149 ac97
->channel_mode
= mode
;
150 if (ac97
->build_ops
->update_jacks
)
151 ac97
->build_ops
->update_jacks(ac97
);
157 #define AC97_SURROUND_JACK_MODE_CTL \
159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
160 .name = "Surround Jack Mode", \
161 .info = ac97_surround_jack_mode_info, \
162 .get = ac97_surround_jack_mode_get, \
163 .put = ac97_surround_jack_mode_put, \
165 #define AC97_CHANNEL_MODE_CTL \
167 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
168 .name = "Channel Mode", \
169 .info = ac97_channel_mode_info, \
170 .get = ac97_channel_mode_get, \
171 .put = ac97_channel_mode_put, \
173 #define AC97_CHANNEL_MODE_4CH_CTL \
175 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
176 .name = "Channel Mode", \
177 .info = ac97_channel_mode_info, \
178 .get = ac97_channel_mode_get, \
179 .put = ac97_channel_mode_put, \
180 .private_value = 1, \
183 static inline int is_surround_on(struct snd_ac97
*ac97
)
185 return ac97
->channel_mode
>= 1;
188 static inline int is_clfe_on(struct snd_ac97
*ac97
)
190 return ac97
->channel_mode
>= 2;
193 /* system has shared jacks with surround out enabled */
194 static inline int is_shared_surrout(struct snd_ac97
*ac97
)
196 return !ac97
->indep_surround
&& is_surround_on(ac97
);
199 /* system has shared jacks with center/lfe out enabled */
200 static inline int is_shared_clfeout(struct snd_ac97
*ac97
)
202 return !ac97
->indep_surround
&& is_clfe_on(ac97
);
205 /* system has shared jacks with line in enabled */
206 static inline int is_shared_linein(struct snd_ac97
*ac97
)
208 return !ac97
->indep_surround
&& !is_surround_on(ac97
);
211 /* system has shared jacks with mic in enabled */
212 static inline int is_shared_micin(struct snd_ac97
*ac97
)
214 return !ac97
->indep_surround
&& !is_clfe_on(ac97
);
218 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
220 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
221 static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
223 static char *texts
[3] = {
224 "Standard", "Small", "Smaller"
227 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
229 uinfo
->value
.enumerated
.items
= 3;
230 if (uinfo
->value
.enumerated
.item
> 2)
231 uinfo
->value
.enumerated
.item
= 2;
232 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
236 static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
238 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
241 val
= ac97
->regs
[AC97_YMF753_3D_MODE_SEL
];
242 val
= (val
>> 10) & 3;
243 if (val
> 0) /* 0 = invalid */
245 ucontrol
->value
.enumerated
.item
[0] = val
;
249 static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
251 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
254 if (ucontrol
->value
.enumerated
.item
[0] > 2)
256 val
= (ucontrol
->value
.enumerated
.item
[0] + 1) << 10;
257 return snd_ac97_update(ac97
, AC97_YMF753_3D_MODE_SEL
, val
);
260 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker
=
262 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
263 .name
= "3D Control - Speaker",
264 .info
= snd_ac97_ymf753_info_speaker
,
265 .get
= snd_ac97_ymf753_get_speaker
,
266 .put
= snd_ac97_ymf753_put_speaker
,
269 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
270 static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
272 static char *texts
[2] = { "AC-Link", "A/D Converter" };
274 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
276 uinfo
->value
.enumerated
.items
= 2;
277 if (uinfo
->value
.enumerated
.item
> 1)
278 uinfo
->value
.enumerated
.item
= 1;
279 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
283 static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
285 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
288 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
289 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 1;
293 static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
295 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
298 if (ucontrol
->value
.enumerated
.item
[0] > 1)
300 val
= ucontrol
->value
.enumerated
.item
[0] << 1;
301 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0002, val
);
304 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
305 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
306 By default, no output pin is selected, and the S/PDIF signal is not output.
307 There is also a bit to mute S/PDIF output in a vendor-specific register. */
308 static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
310 static char *texts
[3] = { "Disabled", "Pin 43", "Pin 48" };
312 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
314 uinfo
->value
.enumerated
.items
= 3;
315 if (uinfo
->value
.enumerated
.item
> 2)
316 uinfo
->value
.enumerated
.item
= 2;
317 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
321 static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
323 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
326 val
= ac97
->regs
[AC97_YMF753_DIT_CTRL2
];
327 ucontrol
->value
.enumerated
.item
[0] = (val
& 0x0008) ? 2 : (val
& 0x0020) ? 1 : 0;
331 static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
333 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
336 if (ucontrol
->value
.enumerated
.item
[0] > 2)
338 val
= (ucontrol
->value
.enumerated
.item
[0] == 2) ? 0x0008 :
339 (ucontrol
->value
.enumerated
.item
[0] == 1) ? 0x0020 : 0;
340 return snd_ac97_update_bits(ac97
, AC97_YMF753_DIT_CTRL2
, 0x0028, val
);
341 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
342 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
345 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif
[3] = {
347 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
348 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
349 .info
= snd_ac97_ymf753_spdif_source_info
,
350 .get
= snd_ac97_ymf753_spdif_source_get
,
351 .put
= snd_ac97_ymf753_spdif_source_put
,
354 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
355 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Output Pin",
356 .info
= snd_ac97_ymf753_spdif_output_pin_info
,
357 .get
= snd_ac97_ymf753_spdif_output_pin_get
,
358 .put
= snd_ac97_ymf753_spdif_output_pin_put
,
360 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE
,NONE
) "Mute", AC97_YMF753_DIT_CTRL2
, 2, 1, 1)
363 static int patch_yamaha_ymf753_3d(struct snd_ac97
* ac97
)
365 struct snd_kcontrol
*kctl
;
368 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
370 strcpy(kctl
->id
.name
, "3D Control - Wide");
371 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 9, 7, 0);
372 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
373 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker
, ac97
))) < 0)
375 snd_ac97_write_cache(ac97
, AC97_YMF753_3D_MODE_SEL
, 0x0c00);
379 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97
* ac97
)
383 if ((err
= patch_build_controls(ac97
, snd_ac97_ymf753_controls_spdif
, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif
))) < 0)
388 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops
= {
389 .build_3d
= patch_yamaha_ymf753_3d
,
390 .build_post_spdif
= patch_yamaha_ymf753_post_spdif
393 int patch_yamaha_ymf753(struct snd_ac97
* ac97
)
395 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
396 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
397 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
398 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
399 By default, no output pin is selected, and the S/PDIF signal is not output.
400 There is also a bit to mute S/PDIF output in a vendor-specific register.
402 ac97
->build_ops
= &patch_yamaha_ymf753_ops
;
403 ac97
->caps
|= AC97_BC_BASS_TREBLE
;
404 ac97
->caps
|= 0x04 << 10; /* Yamaha 3D enhancement */
409 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
410 * removed broken wolfson00 patch.
411 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
414 static const struct snd_kcontrol_new wm97xx_snd_ac97_controls
[] = {
415 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL
, 8, 0, 31, 1),
416 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL
, 15, 1, 1),
419 static int patch_wolfson_wm9703_specific(struct snd_ac97
* ac97
)
421 /* This is known to work for the ViewSonic ViewPad 1000
422 * Randolph Bentson <bentson@holmsjoen.com>
423 * WM9703/9707/9708/9717
427 for (i
= 0; i
< ARRAY_SIZE(wm97xx_snd_ac97_controls
); i
++) {
428 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm97xx_snd_ac97_controls
[i
], ac97
))) < 0)
431 snd_ac97_write_cache(ac97
, AC97_WM97XX_FMIXER_VOL
, 0x0808);
435 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops
= {
436 .build_specific
= patch_wolfson_wm9703_specific
,
439 int patch_wolfson03(struct snd_ac97
* ac97
)
441 ac97
->build_ops
= &patch_wolfson_wm9703_ops
;
445 static const struct snd_kcontrol_new wm9704_snd_ac97_controls
[] = {
446 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL
, 8, 0, 31, 1),
447 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL
, 15, 1, 1),
448 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL
, 8, 0, 31, 1),
449 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL
, 15, 1, 1),
450 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL
, 8, 0, 31, 1),
451 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER
, 8, 0, 31, 1),
454 static int patch_wolfson_wm9704_specific(struct snd_ac97
* ac97
)
457 for (i
= 0; i
< ARRAY_SIZE(wm9704_snd_ac97_controls
); i
++) {
458 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm9704_snd_ac97_controls
[i
], ac97
))) < 0)
461 /* patch for DVD noise */
462 snd_ac97_write_cache(ac97
, AC97_WM9704_TEST
, 0x0200);
466 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops
= {
467 .build_specific
= patch_wolfson_wm9704_specific
,
470 int patch_wolfson04(struct snd_ac97
* ac97
)
473 ac97
->build_ops
= &patch_wolfson_wm9704_ops
;
477 static int patch_wolfson_wm9705_specific(struct snd_ac97
* ac97
)
480 for (i
= 0; i
< ARRAY_SIZE(wm97xx_snd_ac97_controls
); i
++) {
481 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm97xx_snd_ac97_controls
[i
], ac97
))) < 0)
484 snd_ac97_write_cache(ac97
, 0x72, 0x0808);
488 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops
= {
489 .build_specific
= patch_wolfson_wm9705_specific
,
492 int patch_wolfson05(struct snd_ac97
* ac97
)
495 ac97
->build_ops
= &patch_wolfson_wm9705_ops
;
496 #ifdef CONFIG_TOUCHSCREEN_WM9705
497 /* WM9705 touchscreen uses AUX and VIDEO for touch */
498 ac97
->flags
|= AC97_HAS_NO_VIDEO
| AC97_HAS_NO_AUX
;
503 static const char* wm9711_alc_select
[] = {"None", "Left", "Right", "Stereo"};
504 static const char* wm9711_alc_mix
[] = {"Stereo", "Right", "Left", "None"};
505 static const char* wm9711_out3_src
[] = {"Left", "VREF", "Left + Right", "Mono"};
506 static const char* wm9711_out3_lrsrc
[] = {"Master Mix", "Headphone Mix"};
507 static const char* wm9711_rec_adc
[] = {"Stereo", "Left", "Right", "Mute"};
508 static const char* wm9711_base
[] = {"Linear Control", "Adaptive Boost"};
509 static const char* wm9711_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
510 static const char* wm9711_mic
[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
511 static const char* wm9711_rec_sel
[] =
512 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
513 static const char* wm9711_ng_type
[] = {"Constant Gain", "Mute"};
515 static const struct ac97_enum wm9711_enum
[] = {
516 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9711_alc_select
),
517 AC97_ENUM_SINGLE(AC97_VIDEO
, 10, 4, wm9711_alc_mix
),
518 AC97_ENUM_SINGLE(AC97_AUX
, 9, 4, wm9711_out3_src
),
519 AC97_ENUM_SINGLE(AC97_AUX
, 8, 2, wm9711_out3_lrsrc
),
520 AC97_ENUM_SINGLE(AC97_REC_SEL
, 12, 4, wm9711_rec_adc
),
521 AC97_ENUM_SINGLE(AC97_MASTER_TONE
, 15, 2, wm9711_base
),
522 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 14, 6, 2, wm9711_rec_gain
),
523 AC97_ENUM_SINGLE(AC97_MIC
, 5, 4, wm9711_mic
),
524 AC97_ENUM_DOUBLE(AC97_REC_SEL
, 8, 0, 8, wm9711_rec_sel
),
525 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9711_ng_type
),
528 static const struct snd_kcontrol_new wm9711_snd_ac97_controls
[] = {
529 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
530 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
531 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV
, 4, 15, 0),
532 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
533 AC97_ENUM("ALC Function", wm9711_enum
[0]),
534 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 1),
535 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 1),
536 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
537 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
538 AC97_ENUM("ALC NG Type", wm9711_enum
[9]),
539 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 1),
541 AC97_SINGLE("Side Tone Switch", AC97_VIDEO
, 15, 1, 1),
542 AC97_SINGLE("Side Tone Volume", AC97_VIDEO
, 12, 7, 1),
543 AC97_ENUM("ALC Headphone Mux", wm9711_enum
[1]),
544 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO
, 7, 7, 1),
546 AC97_SINGLE("Out3 Switch", AC97_AUX
, 15, 1, 1),
547 AC97_SINGLE("Out3 ZC Switch", AC97_AUX
, 7, 1, 0),
548 AC97_ENUM("Out3 Mux", wm9711_enum
[2]),
549 AC97_ENUM("Out3 LR Mux", wm9711_enum
[3]),
550 AC97_SINGLE("Out3 Volume", AC97_AUX
, 0, 31, 1),
552 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP
, 15, 1, 1),
553 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP
, 12, 7, 1),
554 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP
, 11, 1, 1),
555 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP
, 8, 7, 1),
556 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP
, 7, 1, 1),
557 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP
, 4, 7, 1),
559 AC97_SINGLE("Aux to Headphone Switch", AC97_CD
, 15, 1, 1),
560 AC97_SINGLE("Aux to Headphone Volume", AC97_CD
, 12, 7, 1),
561 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD
, 11, 1, 1),
562 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD
, 8, 7, 1),
563 AC97_SINGLE("Aux to Phone Switch", AC97_CD
, 7, 1, 1),
564 AC97_SINGLE("Aux to Phone Volume", AC97_CD
, 4, 7, 1),
566 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE
, 15, 1, 1),
567 AC97_SINGLE("Phone to Master Switch", AC97_PHONE
, 14, 1, 1),
569 AC97_SINGLE("Line to Headphone Switch", AC97_LINE
, 15, 1, 1),
570 AC97_SINGLE("Line to Master Switch", AC97_LINE
, 14, 1, 1),
571 AC97_SINGLE("Line to Phone Switch", AC97_LINE
, 13, 1, 1),
573 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM
, 15, 1, 1),
574 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM
, 14, 1, 1),
575 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM
, 13, 1, 1),
577 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL
, 14, 1, 0),
578 AC97_ENUM("Capture to Phone Mux", wm9711_enum
[4]),
579 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL
, 11, 1, 1),
580 AC97_ENUM("Capture Select", wm9711_enum
[8]),
582 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL
, 5, 1, 1),
583 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL
, 4, 1, 1),
585 AC97_ENUM("Bass Control", wm9711_enum
[5]),
586 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE
, 12, 1, 1),
587 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE
, 4, 1, 1),
588 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE
, 6, 1, 0),
590 AC97_SINGLE("ADC Switch", AC97_REC_GAIN
, 15, 1, 1),
591 AC97_ENUM("Capture Volume Steps", wm9711_enum
[6]),
592 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN
, 8, 0, 63, 1),
593 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN
, 7, 1, 0),
595 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC
, 14, 1, 1),
596 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC
, 13, 1, 1),
597 AC97_ENUM("Mic Select Source", wm9711_enum
[7]),
598 AC97_SINGLE("Mic 1 Volume", AC97_MIC
, 8, 31, 1),
599 AC97_SINGLE("Mic 2 Volume", AC97_MIC
, 0, 31, 1),
600 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC
, 7, 1, 0),
602 AC97_SINGLE("Master ZC Switch", AC97_MASTER
, 7, 1, 0),
603 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE
, 7, 1, 0),
604 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO
, 7, 1, 0),
607 static int patch_wolfson_wm9711_specific(struct snd_ac97
* ac97
)
611 for (i
= 0; i
< ARRAY_SIZE(wm9711_snd_ac97_controls
); i
++) {
612 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm9711_snd_ac97_controls
[i
], ac97
))) < 0)
615 snd_ac97_write_cache(ac97
, AC97_CODEC_CLASS_REV
, 0x0808);
616 snd_ac97_write_cache(ac97
, AC97_PCI_SVID
, 0x0808);
617 snd_ac97_write_cache(ac97
, AC97_VIDEO
, 0x0808);
618 snd_ac97_write_cache(ac97
, AC97_AUX
, 0x0808);
619 snd_ac97_write_cache(ac97
, AC97_PC_BEEP
, 0x0808);
620 snd_ac97_write_cache(ac97
, AC97_CD
, 0x0000);
624 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops
= {
625 .build_specific
= patch_wolfson_wm9711_specific
,
628 int patch_wolfson11(struct snd_ac97
* ac97
)
631 ac97
->build_ops
= &patch_wolfson_wm9711_ops
;
633 ac97
->flags
|= AC97_HAS_NO_REC_GAIN
| AC97_STEREO_MUTES
| AC97_HAS_NO_MIC
|
634 AC97_HAS_NO_PC_BEEP
| AC97_HAS_NO_VIDEO
| AC97_HAS_NO_CD
;
639 static const char* wm9713_mic_mixer
[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
640 static const char* wm9713_rec_mux
[] = {"Stereo", "Left", "Right", "Mute"};
641 static const char* wm9713_rec_src
[] =
642 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
644 static const char* wm9713_rec_gain
[] = {"+1.5dB Steps", "+0.75dB Steps"};
645 static const char* wm9713_alc_select
[] = {"None", "Left", "Right", "Stereo"};
646 static const char* wm9713_mono_pga
[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
647 static const char* wm9713_spk_pga
[] =
648 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
649 static const char* wm9713_hp_pga
[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
650 static const char* wm9713_out3_pga
[] = {"Vmid", "Zh", "Inv 1", "NC"};
651 static const char* wm9713_out4_pga
[] = {"Vmid", "Zh", "Inv 2", "NC"};
652 static const char* wm9713_dac_inv
[] =
653 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
654 "Headphone Mix Mono", "NC", "Vmid"};
655 static const char* wm9713_base
[] = {"Linear Control", "Adaptive Boost"};
656 static const char* wm9713_ng_type
[] = {"Constant Gain", "Mute"};
658 static const struct ac97_enum wm9713_enum
[] = {
659 AC97_ENUM_SINGLE(AC97_LINE
, 3, 4, wm9713_mic_mixer
),
660 AC97_ENUM_SINGLE(AC97_VIDEO
, 14, 4, wm9713_rec_mux
),
661 AC97_ENUM_SINGLE(AC97_VIDEO
, 9, 4, wm9713_rec_mux
),
662 AC97_ENUM_DOUBLE(AC97_VIDEO
, 3, 0, 8, wm9713_rec_src
),
663 AC97_ENUM_DOUBLE(AC97_CD
, 14, 6, 2, wm9713_rec_gain
),
664 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 14, 4, wm9713_alc_select
),
665 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 14, 4, wm9713_mono_pga
),
666 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 11, 8, 8, wm9713_spk_pga
),
667 AC97_ENUM_DOUBLE(AC97_REC_GAIN
, 6, 4, 4, wm9713_hp_pga
),
668 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 2, 4, wm9713_out3_pga
),
669 AC97_ENUM_SINGLE(AC97_REC_GAIN
, 0, 4, wm9713_out4_pga
),
670 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC
, 13, 10, 8, wm9713_dac_inv
),
671 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE
, 15, 2, wm9713_base
),
672 AC97_ENUM_SINGLE(AC97_PCI_SVID
, 5, 2, wm9713_ng_type
),
675 static const struct snd_kcontrol_new wm13_snd_ac97_controls
[] = {
676 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP
, 8, 0, 31, 1),
677 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP
, 15, 1, 1),
678 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP
, 14, 1, 1),
679 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP
, 13, 1, 1),
681 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE
, 8, 0, 31, 1),
682 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE
, 15, 1, 1),
683 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE
, 14, 1, 1),
684 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE
, 13, 1, 1),
686 AC97_SINGLE("Mic 1 Volume", AC97_MIC
, 8, 31, 1),
687 AC97_SINGLE("Mic 2 Volume", AC97_MIC
, 0, 31, 1),
688 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE
, 7, 1, 1),
689 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE
, 6, 1, 1),
690 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE
, 5, 1, 0),
691 AC97_ENUM("Mic to Headphone Mux", wm9713_enum
[0]),
692 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE
, 0, 7, 1),
694 AC97_SINGLE("Capture Switch", AC97_CD
, 15, 1, 1),
695 AC97_ENUM("Capture Volume Steps", wm9713_enum
[4]),
696 AC97_DOUBLE("Capture Volume", AC97_CD
, 8, 0, 15, 0),
697 AC97_SINGLE("Capture ZC Switch", AC97_CD
, 7, 1, 0),
699 AC97_ENUM("Capture to Headphone Mux", wm9713_enum
[1]),
700 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO
, 11, 7, 1),
701 AC97_ENUM("Capture to Mono Mux", wm9713_enum
[2]),
702 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO
, 8, 1, 0),
703 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO
, 6, 1, 0),
704 AC97_ENUM("Capture Select", wm9713_enum
[3]),
706 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV
, 12, 15, 0),
707 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV
, 8, 15, 0),
708 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV
, 4, 15, 0),
709 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV
, 0, 15, 0),
710 AC97_ENUM("ALC Function", wm9713_enum
[5]),
711 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID
, 11, 7, 0),
712 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID
, 9, 3, 0),
713 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID
, 8, 1, 0),
714 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID
, 7, 1, 0),
715 AC97_ENUM("ALC NG Type", wm9713_enum
[13]),
716 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID
, 0, 31, 0),
718 AC97_DOUBLE("Master ZC Switch", AC97_MASTER
, 14, 6, 1, 0),
719 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE
, 14, 6, 1, 0),
720 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO
, 14, 6, 1, 0),
721 AC97_SINGLE("Master Right Switch", AC97_MASTER
, 7, 1, 1),
722 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE
, 7, 1, 1),
723 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO
, 7, 1, 1),
725 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE
, 15, 1, 1),
726 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE
, 14, 1, 1),
727 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE
, 8, 31, 1),
728 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE
, 7, 1, 1),
729 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE
, 6, 1, 0),
730 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE
, 0, 31, 1),
732 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX
, 15, 1, 1),
733 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX
, 12, 7, 1),
734 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX
, 11, 1, 1),
735 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX
, 8, 7, 1),
736 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX
, 7, 1, 1),
737 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX
, 4, 7, 1),
739 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM
, 15, 1, 1),
740 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM
, 12, 7, 1),
741 AC97_SINGLE("Voice to Master Switch", AC97_PCM
, 11, 1, 1),
742 AC97_SINGLE("Voice to Master Volume", AC97_PCM
, 8, 7, 1),
743 AC97_SINGLE("Voice to Mono Switch", AC97_PCM
, 7, 1, 1),
744 AC97_SINGLE("Voice to Mono Volume", AC97_PCM
, 4, 7, 1),
746 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL
, 15, 1, 1),
747 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL
, 12, 7, 1),
748 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL
, 11, 1, 1),
749 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL
, 8, 7, 1),
750 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL
, 7, 1, 1),
751 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL
, 4, 7, 1),
753 AC97_ENUM("Mono Input Mux", wm9713_enum
[6]),
754 AC97_ENUM("Master Input Mux", wm9713_enum
[7]),
755 AC97_ENUM("Headphone Input Mux", wm9713_enum
[8]),
756 AC97_ENUM("Out 3 Input Mux", wm9713_enum
[9]),
757 AC97_ENUM("Out 4 Input Mux", wm9713_enum
[10]),
759 AC97_ENUM("Bass Control", wm9713_enum
[12]),
760 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE
, 12, 1, 1),
761 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE
, 4, 1, 1),
762 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE
, 6, 1, 0),
763 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE
, 8, 15, 1),
764 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE
, 0, 15, 1),
767 static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d
[] = {
768 AC97_ENUM("Inv Input Mux", wm9713_enum
[11]),
769 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC
, 5, 1, 0),
770 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC
, 4, 1, 0),
771 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC
, 0, 15, 1),
774 static int patch_wolfson_wm9713_3d (struct snd_ac97
* ac97
)
778 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls_3d
); i
++) {
779 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls_3d
[i
], ac97
))) < 0)
785 static int patch_wolfson_wm9713_specific(struct snd_ac97
* ac97
)
789 for (i
= 0; i
< ARRAY_SIZE(wm13_snd_ac97_controls
); i
++) {
790 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ac97_cnew(&wm13_snd_ac97_controls
[i
], ac97
))) < 0)
793 snd_ac97_write_cache(ac97
, AC97_PC_BEEP
, 0x0808);
794 snd_ac97_write_cache(ac97
, AC97_PHONE
, 0x0808);
795 snd_ac97_write_cache(ac97
, AC97_MIC
, 0x0808);
796 snd_ac97_write_cache(ac97
, AC97_LINE
, 0x00da);
797 snd_ac97_write_cache(ac97
, AC97_CD
, 0x0808);
798 snd_ac97_write_cache(ac97
, AC97_VIDEO
, 0xd612);
799 snd_ac97_write_cache(ac97
, AC97_REC_GAIN
, 0x1ba0);
804 static void patch_wolfson_wm9713_suspend (struct snd_ac97
* ac97
)
806 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xfeff);
807 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0xffff);
810 static void patch_wolfson_wm9713_resume (struct snd_ac97
* ac97
)
812 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
813 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
814 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
818 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops
= {
819 .build_specific
= patch_wolfson_wm9713_specific
,
820 .build_3d
= patch_wolfson_wm9713_3d
,
822 .suspend
= patch_wolfson_wm9713_suspend
,
823 .resume
= patch_wolfson_wm9713_resume
827 int patch_wolfson13(struct snd_ac97
* ac97
)
830 ac97
->build_ops
= &patch_wolfson_wm9713_ops
;
832 ac97
->flags
|= AC97_HAS_NO_REC_GAIN
| AC97_STEREO_MUTES
| AC97_HAS_NO_PHONE
|
833 AC97_HAS_NO_PC_BEEP
| AC97_HAS_NO_VIDEO
| AC97_HAS_NO_CD
| AC97_HAS_NO_TONE
|
835 ac97
->scaps
&= ~AC97_SCAP_MODEM
;
837 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MID
, 0xda00);
838 snd_ac97_write_cache(ac97
, AC97_EXTENDED_MSTATUS
, 0x3810);
839 snd_ac97_write_cache(ac97
, AC97_POWERDOWN
, 0x0);
847 int patch_tritech_tr28028(struct snd_ac97
* ac97
)
849 snd_ac97_write_cache(ac97
, 0x26, 0x0300);
850 snd_ac97_write_cache(ac97
, 0x26, 0x0000);
851 snd_ac97_write_cache(ac97
, AC97_SURROUND_MASTER
, 0x0000);
852 snd_ac97_write_cache(ac97
, AC97_SPDIF
, 0x0000);
857 * Sigmatel STAC97xx codecs
859 static int patch_sigmatel_stac9700_3d(struct snd_ac97
* ac97
)
861 struct snd_kcontrol
*kctl
;
864 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
866 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
867 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
868 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
872 static int patch_sigmatel_stac9708_3d(struct snd_ac97
* ac97
)
874 struct snd_kcontrol
*kctl
;
877 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
879 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Depth");
880 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 0, 3, 0);
881 if ((err
= snd_ctl_add(ac97
->bus
->card
, kctl
= snd_ac97_cnew(&snd_ac97_controls_3d
[0], ac97
))) < 0)
883 strcpy(kctl
->id
.name
, "3D Control Sigmatel - Rear Depth");
884 kctl
->private_value
= AC97_SINGLE_VALUE(AC97_3D_CONTROL
, 2, 3, 0);
885 snd_ac97_write_cache(ac97
, AC97_3D_CONTROL
, 0x0000);
889 static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker
=
890 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 2, 1, 0);
892 static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert
=
893 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT
, 3, 1, 0);
895 static const struct snd_kcontrol_new snd_ac97_sigmatel_controls
[] = {
896 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 1, 1, 0),
897 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG
, 0, 1, 0)
900 static int patch_sigmatel_stac97xx_specific(struct snd_ac97
* ac97
)
904 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_ANALOG
, snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) & ~0x0003);
905 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 1))
906 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[0], 1)) < 0)
908 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_ANALOG
, 0))
909 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_controls
[1], 1)) < 0)
911 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 2))
912 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_4speaker
, 1)) < 0)
914 if (snd_ac97_try_bit(ac97
, AC97_SIGMATEL_DAC2INVERT
, 3))
915 if ((err
= patch_build_controls(ac97
, &snd_ac97_sigmatel_phaseinvert
, 1)) < 0)
920 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops
= {
921 .build_3d
= patch_sigmatel_stac9700_3d
,
922 .build_specific
= patch_sigmatel_stac97xx_specific
925 int patch_sigmatel_stac9700(struct snd_ac97
* ac97
)
927 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
931 static int snd_ac97_stac9708_put_bias(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
933 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
936 mutex_lock(&ac97
->page_mutex
);
937 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
938 err
= snd_ac97_update_bits(ac97
, AC97_SIGMATEL_BIAS2
, 0x0010,
939 (ucontrol
->value
.integer
.value
[0] & 1) << 4);
940 snd_ac97_write(ac97
, AC97_SIGMATEL_BIAS1
, 0);
941 mutex_unlock(&ac97
->page_mutex
);
945 static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control
= {
946 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
947 .name
= "Sigmatel Output Bias Switch",
948 .info
= snd_ac97_info_volsw
,
949 .get
= snd_ac97_get_volsw
,
950 .put
= snd_ac97_stac9708_put_bias
,
951 .private_value
= AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2
, 4, 1, 0),
954 static int patch_sigmatel_stac9708_specific(struct snd_ac97
*ac97
)
958 /* the register bit is writable, but the function is not implemented: */
959 snd_ac97_remove_ctl(ac97
, "PCM Out Path & Mute", NULL
);
961 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Sigmatel Surround Playback");
962 if ((err
= patch_build_controls(ac97
, &snd_ac97_stac9708_bias_control
, 1)) < 0)
964 return patch_sigmatel_stac97xx_specific(ac97
);
967 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops
= {
968 .build_3d
= patch_sigmatel_stac9708_3d
,
969 .build_specific
= patch_sigmatel_stac9708_specific
972 int patch_sigmatel_stac9708(struct snd_ac97
* ac97
)
974 unsigned int codec72
, codec6c
;
976 ac97
->build_ops
= &patch_sigmatel_stac9708_ops
;
977 ac97
->caps
|= 0x10; /* HP (sigmatel surround) support */
979 codec72
= snd_ac97_read(ac97
, AC97_SIGMATEL_BIAS2
) & 0x8000;
980 codec6c
= snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
);
982 if ((codec72
==0) && (codec6c
==0)) {
983 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
984 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1000);
985 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
986 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0007);
987 } else if ((codec72
==0x8000) && (codec6c
==0)) {
988 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
989 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x1001);
990 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_DAC2INVERT
, 0x0008);
991 } else if ((codec72
==0x8000) && (codec6c
==0x0080)) {
994 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
998 int patch_sigmatel_stac9721(struct snd_ac97
* ac97
)
1000 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
1001 if (snd_ac97_read(ac97
, AC97_SIGMATEL_ANALOG
) == 0) {
1002 // patch for SigmaTel
1003 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
1004 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x4000);
1005 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
1006 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
1008 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
1012 int patch_sigmatel_stac9744(struct snd_ac97
* ac97
)
1014 // patch for SigmaTel
1015 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
1016 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
1017 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
1018 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
1019 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
1020 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
1024 int patch_sigmatel_stac9756(struct snd_ac97
* ac97
)
1026 // patch for SigmaTel
1027 ac97
->build_ops
= &patch_sigmatel_stac9700_ops
;
1028 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC1
, 0xabba);
1029 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_CIC2
, 0x0000); /* is this correct? --jk */
1030 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS1
, 0xabba);
1031 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_BIAS2
, 0x0002);
1032 snd_ac97_write_cache(ac97
, AC97_SIGMATEL_MULTICHN
, 0x0000);
1036 static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1038 static char *texts
[5] = { "Input/Disabled", "Front Output",
1039 "Rear Output", "Center/LFE Output", "Mixer Output" };
1041 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1043 uinfo
->value
.enumerated
.items
= 5;
1044 if (uinfo
->value
.enumerated
.item
> 4)
1045 uinfo
->value
.enumerated
.item
= 4;
1046 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1050 static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1052 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1053 int shift
= kcontrol
->private_value
;
1056 val
= ac97
->regs
[AC97_SIGMATEL_OUTSEL
] >> shift
;
1058 ucontrol
->value
.enumerated
.item
[0] = 0;
1060 ucontrol
->value
.enumerated
.item
[0] = 1 + (val
& 3);
1064 static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1066 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1067 int shift
= kcontrol
->private_value
;
1070 if (ucontrol
->value
.enumerated
.item
[0] > 4)
1072 if (ucontrol
->value
.enumerated
.item
[0] == 0)
1075 val
= 4 | (ucontrol
->value
.enumerated
.item
[0] - 1);
1076 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_OUTSEL
,
1077 7 << shift
, val
<< shift
, 0);
1080 static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1082 static char *texts
[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1083 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1085 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1087 uinfo
->value
.enumerated
.items
= 7;
1088 if (uinfo
->value
.enumerated
.item
> 6)
1089 uinfo
->value
.enumerated
.item
= 6;
1090 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1094 static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1096 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1097 int shift
= kcontrol
->private_value
;
1100 val
= ac97
->regs
[AC97_SIGMATEL_INSEL
];
1101 ucontrol
->value
.enumerated
.item
[0] = (val
>> shift
) & 7;
1105 static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1107 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1108 int shift
= kcontrol
->private_value
;
1110 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_INSEL
, 7 << shift
,
1111 ucontrol
->value
.enumerated
.item
[0] << shift
, 0);
1114 static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1116 static char *texts
[3] = { "None", "Front Jack", "Rear Jack" };
1118 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1120 uinfo
->value
.enumerated
.items
= 3;
1121 if (uinfo
->value
.enumerated
.item
> 2)
1122 uinfo
->value
.enumerated
.item
= 2;
1123 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1127 static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1129 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1131 ucontrol
->value
.enumerated
.item
[0] = ac97
->regs
[AC97_SIGMATEL_IOMISC
] & 3;
1135 static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1137 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1139 return ac97_update_bits_page(ac97
, AC97_SIGMATEL_IOMISC
, 3,
1140 ucontrol
->value
.enumerated
.item
[0], 0);
1143 #define STAC9758_OUTPUT_JACK(xname, shift) \
1144 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1145 .info = snd_ac97_stac9758_output_jack_info, \
1146 .get = snd_ac97_stac9758_output_jack_get, \
1147 .put = snd_ac97_stac9758_output_jack_put, \
1148 .private_value = shift }
1149 #define STAC9758_INPUT_JACK(xname, shift) \
1150 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1151 .info = snd_ac97_stac9758_input_jack_info, \
1152 .get = snd_ac97_stac9758_input_jack_get, \
1153 .put = snd_ac97_stac9758_input_jack_put, \
1154 .private_value = shift }
1155 static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls
[] = {
1156 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1157 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1158 STAC9758_OUTPUT_JACK("Front Jack", 7),
1159 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1160 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1161 STAC9758_INPUT_JACK("Mic Input Source", 0),
1162 STAC9758_INPUT_JACK("Line Input Source", 8),
1164 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1165 .name
= "Headphone Amp",
1166 .info
= snd_ac97_stac9758_phonesel_info
,
1167 .get
= snd_ac97_stac9758_phonesel_get
,
1168 .put
= snd_ac97_stac9758_phonesel_put
1170 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC
, 4, 1, 0),
1171 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC
, 8, 1, 0)
1174 static int patch_sigmatel_stac9758_specific(struct snd_ac97
*ac97
)
1178 err
= patch_sigmatel_stac97xx_specific(ac97
);
1181 err
= patch_build_controls(ac97
, snd_ac97_sigmatel_stac9758_controls
,
1182 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls
));
1186 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Front Playback");
1187 /* DAC-A to Mix = PCM */
1188 /* DAC-B direct = Surround */
1190 snd_ac97_rename_vol_ctl(ac97
, "Video Playback", "Surround Mix Playback");
1191 /* DAC-C direct = Center/LFE */
1196 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops
= {
1197 .build_3d
= patch_sigmatel_stac9700_3d
,
1198 .build_specific
= patch_sigmatel_stac9758_specific
1201 int patch_sigmatel_stac9758(struct snd_ac97
* ac97
)
1203 static unsigned short regs
[4] = {
1204 AC97_SIGMATEL_OUTSEL
,
1205 AC97_SIGMATEL_IOMISC
,
1206 AC97_SIGMATEL_INSEL
,
1207 AC97_SIGMATEL_VARIOUS
1209 static unsigned short def_regs
[4] = {
1210 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1211 /* IOMISC */ 0x2001,
1212 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1213 /* VARIOUS */ 0x0040
1215 static unsigned short m675_regs
[4] = {
1216 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1217 /* IOMISC */ 0x2102, /* HP amp on */
1218 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1219 /* VARIOUS */ 0x0041 /* stereo mic */
1221 unsigned short *pregs
= def_regs
;
1224 /* Gateway M675 notebook */
1226 ac97
->subsystem_vendor
== 0x107b &&
1227 ac97
->subsystem_device
== 0x0601)
1230 // patch for SigmaTel
1231 ac97
->build_ops
= &patch_sigmatel_stac9758_ops
;
1232 /* FIXME: assume only page 0 for writing cache */
1233 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
1234 for (i
= 0; i
< 4; i
++)
1235 snd_ac97_write_cache(ac97
, regs
[i
], pregs
[i
]);
1237 ac97
->flags
|= AC97_STEREO_MUTES
;
1242 * Cirrus Logic CS42xx codecs
1244 static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif
[2] = {
1245 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CSR_SPDIF
, 15, 1, 0),
1246 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "AC97-SPSA", AC97_CSR_ACMODE
, 0, 3, 0)
1249 static int patch_cirrus_build_spdif(struct snd_ac97
* ac97
)
1253 /* con mask, pro mask, default */
1254 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
1257 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[0], 1)) < 0)
1259 switch (ac97
->id
& AC97_ID_CS_MASK
) {
1260 case AC97_ID_CS4205
:
1261 if ((err
= patch_build_controls(ac97
, &snd_ac97_cirrus_controls_spdif
[1], 1)) < 0)
1265 /* set default PCM S/PDIF params */
1266 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1267 snd_ac97_write_cache(ac97
, AC97_CSR_SPDIF
, 0x0a20);
1271 static struct snd_ac97_build_ops patch_cirrus_ops
= {
1272 .build_spdif
= patch_cirrus_build_spdif
1275 int patch_cirrus_spdif(struct snd_ac97
* ac97
)
1277 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1278 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1279 - sp/dif EA ID is not set, but sp/dif is always present.
1280 - enable/disable is spdif register bit 15.
1281 - sp/dif control register is 0x68. differs from AC97:
1282 - valid is bit 14 (vs 15)
1284 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1285 - sp/dif ssource select is in 0x5e bits 0,1.
1288 ac97
->build_ops
= &patch_cirrus_ops
;
1289 ac97
->flags
|= AC97_CS_SPDIF
;
1290 ac97
->rates
[AC97_RATES_SPDIF
] &= ~SNDRV_PCM_RATE_32000
;
1291 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
1292 snd_ac97_write_cache(ac97
, AC97_CSR_ACMODE
, 0x0080);
1296 int patch_cirrus_cs4299(struct snd_ac97
* ac97
)
1298 /* force the detection of PC Beep */
1299 ac97
->flags
|= AC97_HAS_PC_BEEP
;
1301 return patch_cirrus_spdif(ac97
);
1307 static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif
[1] = {
1308 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK
,SWITCH
), AC97_CXR_AUDIO_MISC
, 3, 1, 0),
1311 static int patch_conexant_build_spdif(struct snd_ac97
* ac97
)
1315 /* con mask, pro mask, default */
1316 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_spdif
[0], 3)) < 0)
1319 if ((err
= patch_build_controls(ac97
, &snd_ac97_conexant_controls_spdif
[0], 1)) < 0)
1321 /* set default PCM S/PDIF params */
1322 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1323 snd_ac97_write_cache(ac97
, AC97_CXR_AUDIO_MISC
,
1324 snd_ac97_read(ac97
, AC97_CXR_AUDIO_MISC
) & ~(AC97_CXR_SPDIFEN
|AC97_CXR_COPYRGT
|AC97_CXR_SPDIF_MASK
));
1328 static struct snd_ac97_build_ops patch_conexant_ops
= {
1329 .build_spdif
= patch_conexant_build_spdif
1332 int patch_conexant(struct snd_ac97
* ac97
)
1334 ac97
->build_ops
= &patch_conexant_ops
;
1335 ac97
->flags
|= AC97_CX_SPDIF
;
1336 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
1337 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
1341 int patch_cx20551(struct snd_ac97
*ac97
)
1343 snd_ac97_update_bits(ac97
, 0x5c, 0x01, 0x01);
1348 * Analog Device AD18xx, AD19xx codecs
1351 static void ad18xx_resume(struct snd_ac97
*ac97
)
1353 static unsigned short setup_regs
[] = {
1354 AC97_AD_MISC
, AC97_AD_SERIAL_CFG
, AC97_AD_JACK_SPDIF
,
1358 for (i
= 0; i
< (int)ARRAY_SIZE(setup_regs
); i
++) {
1359 unsigned short reg
= setup_regs
[i
];
1360 if (test_bit(reg
, ac97
->reg_accessed
)) {
1361 snd_ac97_write(ac97
, reg
, ac97
->regs
[reg
]);
1362 snd_ac97_read(ac97
, reg
);
1366 if (! (ac97
->flags
& AC97_AD_MULTI
))
1367 /* normal restore */
1368 snd_ac97_restore_status(ac97
);
1370 /* restore the AD18xx codec configurations */
1371 for (codec
= 0; codec
< 3; codec
++) {
1372 if (! ac97
->spec
.ad18xx
.id
[codec
])
1374 /* select single codec */
1375 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1376 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
1377 ac97
->bus
->ops
->write(ac97
, AC97_AD_CODEC_CFG
, ac97
->spec
.ad18xx
.codec_cfg
[codec
]);
1379 /* select all codecs */
1380 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1382 /* restore status */
1383 for (i
= 2; i
< 0x7c ; i
+= 2) {
1384 if (i
== AC97_POWERDOWN
|| i
== AC97_EXTENDED_ID
)
1386 if (test_bit(i
, ac97
->reg_accessed
)) {
1387 /* handle multi codecs for AD18xx */
1388 if (i
== AC97_PCM
) {
1389 for (codec
= 0; codec
< 3; codec
++) {
1390 if (! ac97
->spec
.ad18xx
.id
[codec
])
1392 /* select single codec */
1393 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1394 ac97
->spec
.ad18xx
.unchained
[codec
] | ac97
->spec
.ad18xx
.chained
[codec
]);
1395 /* update PCM bits */
1396 ac97
->bus
->ops
->write(ac97
, AC97_PCM
, ac97
->spec
.ad18xx
.pcmreg
[codec
]);
1398 /* select all codecs */
1399 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1401 } else if (i
== AC97_AD_TEST
||
1402 i
== AC97_AD_CODEC_CFG
||
1403 i
== AC97_AD_SERIAL_CFG
)
1404 continue; /* ignore */
1406 snd_ac97_write(ac97
, i
, ac97
->regs
[i
]);
1407 snd_ac97_read(ac97
, i
);
1411 snd_ac97_restore_iec958(ac97
);
1414 static void ad1888_resume(struct snd_ac97
*ac97
)
1416 ad18xx_resume(ac97
);
1417 snd_ac97_write_cache(ac97
, AC97_CODEC_CLASS_REV
, 0x8080);
1422 static const struct snd_ac97_res_table ad1819_restbl
[] = {
1423 { AC97_PHONE
, 0x9f1f },
1424 { AC97_MIC
, 0x9f1f },
1425 { AC97_LINE
, 0x9f1f },
1426 { AC97_CD
, 0x9f1f },
1427 { AC97_VIDEO
, 0x9f1f },
1428 { AC97_AUX
, 0x9f1f },
1429 { AC97_PCM
, 0x9f1f },
1430 { } /* terminator */
1433 int patch_ad1819(struct snd_ac97
* ac97
)
1435 unsigned short scfg
;
1437 // patch for Analog Devices
1438 scfg
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1439 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, scfg
| 0x7000); /* select all codecs */
1440 ac97
->res_table
= ad1819_restbl
;
1444 static unsigned short patch_ad1881_unchained(struct snd_ac97
* ac97
, int idx
, unsigned short mask
)
1448 // test for unchained codec
1449 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, mask
);
1450 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000); /* ID0C, ID1C, SDIE = off */
1451 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1452 if ((val
& 0xff40) != 0x5340)
1454 ac97
->spec
.ad18xx
.unchained
[idx
] = mask
;
1455 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1456 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = 0x0000;
1460 static int patch_ad1881_chained1(struct snd_ac97
* ac97
, int idx
, unsigned short codec_bits
)
1462 static int cfg_bits
[3] = { 1<<12, 1<<14, 1<<13 };
1465 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, cfg_bits
[idx
]);
1466 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0004); // SDIE
1467 val
= snd_ac97_read(ac97
, AC97_VENDOR_ID2
);
1468 if ((val
& 0xff40) != 0x5340)
1471 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, codec_bits
);
1472 ac97
->spec
.ad18xx
.chained
[idx
] = cfg_bits
[idx
];
1473 ac97
->spec
.ad18xx
.id
[idx
] = val
;
1474 ac97
->spec
.ad18xx
.codec_cfg
[idx
] = codec_bits
? codec_bits
: 0x0004;
1478 static void patch_ad1881_chained(struct snd_ac97
* ac97
, int unchained_idx
, int cidx1
, int cidx2
)
1480 // already detected?
1481 if (ac97
->spec
.ad18xx
.unchained
[cidx1
] || ac97
->spec
.ad18xx
.chained
[cidx1
])
1483 if (ac97
->spec
.ad18xx
.unchained
[cidx2
] || ac97
->spec
.ad18xx
.chained
[cidx2
])
1485 if (cidx1
< 0 && cidx2
< 0)
1487 // test for chained codecs
1488 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
1489 ac97
->spec
.ad18xx
.unchained
[unchained_idx
]);
1490 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0002); // ID1C
1491 ac97
->spec
.ad18xx
.codec_cfg
[unchained_idx
] = 0x0002;
1494 patch_ad1881_chained1(ac97
, cidx1
, 0);
1495 else if (patch_ad1881_chained1(ac97
, cidx1
, 0x0006)) // SDIE | ID1C
1496 patch_ad1881_chained1(ac97
, cidx2
, 0);
1497 else if (patch_ad1881_chained1(ac97
, cidx2
, 0x0006)) // SDIE | ID1C
1498 patch_ad1881_chained1(ac97
, cidx1
, 0);
1499 } else if (cidx2
>= 0) {
1500 patch_ad1881_chained1(ac97
, cidx2
, 0);
1504 static struct snd_ac97_build_ops patch_ad1881_build_ops
= {
1506 .resume
= ad18xx_resume
1510 int patch_ad1881(struct snd_ac97
* ac97
)
1512 static const char cfg_idxs
[3][2] = {
1518 // patch for Analog Devices
1519 unsigned short codecs
[3];
1523 val
= snd_ac97_read(ac97
, AC97_AD_SERIAL_CFG
);
1524 snd_ac97_write_cache(ac97
, AC97_AD_SERIAL_CFG
, val
);
1525 codecs
[0] = patch_ad1881_unchained(ac97
, 0, (1<<12));
1526 codecs
[1] = patch_ad1881_unchained(ac97
, 1, (1<<14));
1527 codecs
[2] = patch_ad1881_unchained(ac97
, 2, (1<<13));
1529 if (! (codecs
[0] || codecs
[1] || codecs
[2]))
1532 for (idx
= 0; idx
< 3; idx
++)
1533 if (ac97
->spec
.ad18xx
.unchained
[idx
])
1534 patch_ad1881_chained(ac97
, idx
, cfg_idxs
[idx
][0], cfg_idxs
[idx
][1]);
1536 if (ac97
->spec
.ad18xx
.id
[1]) {
1537 ac97
->flags
|= AC97_AD_MULTI
;
1538 ac97
->scaps
|= AC97_SCAP_SURROUND_DAC
;
1540 if (ac97
->spec
.ad18xx
.id
[2]) {
1541 ac97
->flags
|= AC97_AD_MULTI
;
1542 ac97
->scaps
|= AC97_SCAP_CENTER_LFE_DAC
;
1546 /* select all codecs */
1547 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
1548 /* check if only one codec is present */
1549 for (idx
= num
= 0; idx
< 3; idx
++)
1550 if (ac97
->spec
.ad18xx
.id
[idx
])
1553 /* ok, deselect all ID bits */
1554 snd_ac97_write_cache(ac97
, AC97_AD_CODEC_CFG
, 0x0000);
1555 ac97
->spec
.ad18xx
.codec_cfg
[0] =
1556 ac97
->spec
.ad18xx
.codec_cfg
[1] =
1557 ac97
->spec
.ad18xx
.codec_cfg
[2] = 0x0000;
1559 /* required for AD1886/AD1885 combination */
1560 ac97
->ext_id
= snd_ac97_read(ac97
, AC97_EXTENDED_ID
);
1561 if (ac97
->spec
.ad18xx
.id
[0]) {
1562 ac97
->id
&= 0xffff0000;
1563 ac97
->id
|= ac97
->spec
.ad18xx
.id
[0];
1565 ac97
->build_ops
= &patch_ad1881_build_ops
;
1569 static const struct snd_kcontrol_new snd_ac97_controls_ad1885
[] = {
1570 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC
, 11, 1, 0),
1571 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1572 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC
, 14, 1, 0),
1573 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC
, 15, 1, 0),
1574 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 9, 1, 1), /* inverted */
1575 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 8, 1, 1), /* inverted */
1578 static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max
, -8850, 150, 0);
1580 static int patch_ad1885_specific(struct snd_ac97
* ac97
)
1584 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_ad1885
, ARRAY_SIZE(snd_ac97_controls_ad1885
))) < 0)
1586 reset_tlv(ac97
, "Headphone Playback Volume",
1587 db_scale_6bit_6db_max
);
1591 static struct snd_ac97_build_ops patch_ad1885_build_ops
= {
1592 .build_specific
= &patch_ad1885_specific
,
1594 .resume
= ad18xx_resume
1598 int patch_ad1885(struct snd_ac97
* ac97
)
1601 /* This is required to deal with the Intel D815EEAL2 */
1602 /* i.e. Line out is actually headphone out from codec */
1605 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, 0x0404);
1607 ac97
->build_ops
= &patch_ad1885_build_ops
;
1611 static int patch_ad1886_specific(struct snd_ac97
* ac97
)
1613 reset_tlv(ac97
, "Headphone Playback Volume",
1614 db_scale_6bit_6db_max
);
1618 static struct snd_ac97_build_ops patch_ad1886_build_ops
= {
1619 .build_specific
= &patch_ad1886_specific
,
1621 .resume
= ad18xx_resume
1625 int patch_ad1886(struct snd_ac97
* ac97
)
1628 /* Presario700 workaround */
1629 /* for Jack Sense/SPDIF Register misetting causing */
1630 snd_ac97_write_cache(ac97
, AC97_AD_JACK_SPDIF
, 0x0010);
1631 ac97
->build_ops
= &patch_ad1886_build_ops
;
1635 /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
1636 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1637 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1638 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1639 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1640 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1641 #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1642 #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1643 #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1644 #define AC97_AD198X_VREF_SHIFT 2
1645 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1646 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1647 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1648 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1649 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1650 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1651 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1652 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1653 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1654 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1655 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1656 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1657 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1659 /* MISC 1 bits (AD1986 register 0x76) */
1660 #define AC97_AD1986_MBC 0x0003 /* mic boost */
1661 #define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1662 #define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1663 #define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1664 #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1665 #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1666 #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1667 #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1668 #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1669 #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1670 #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1671 #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1672 #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1673 #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1674 #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1675 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1676 #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1677 #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1678 #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1679 #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1680 #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1681 #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1683 /* MISC 2 bits (AD1986 register 0x70) */
1684 #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1686 #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1687 #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1688 #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1689 #define AC97_AD1986_CVREF_MASK \
1690 (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1691 #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1692 #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1693 #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1694 #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1695 #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1696 #define AC97_AD1986_MVREF_MASK \
1697 (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1699 /* MISC 3 bits (AD1986 register 0x7a) */
1700 #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1702 #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1703 #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1704 #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1705 #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1706 #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1707 #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1708 #define AC97_AD1986_LVREF_MASK \
1709 (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1710 #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1711 #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1712 #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1713 /* input select Surround DACs */
1714 #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1715 /* select C/LFE DACs */
1716 #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1718 /* Serial Config bits (AD1986 register 0x74) (incomplete) */
1719 #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1720 #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1721 #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1722 #define AC97_AD1986_OMS_MASK \
1723 (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1724 #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1725 #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1726 #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1727 #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1728 /* are MIC sources */
1729 #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1730 /* are MIC sources */
1731 #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1732 /* are MIC sources */
1733 #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1734 /* are MIC sources */
1737 static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1739 static char *texts
[2] = { "AC-Link", "A/D Converter" };
1741 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1743 uinfo
->value
.enumerated
.items
= 2;
1744 if (uinfo
->value
.enumerated
.item
> 1)
1745 uinfo
->value
.enumerated
.item
= 1;
1746 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1750 static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1752 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1755 val
= ac97
->regs
[AC97_AD_SERIAL_CFG
];
1756 ucontrol
->value
.enumerated
.item
[0] = (val
>> 2) & 1;
1760 static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1762 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1765 if (ucontrol
->value
.enumerated
.item
[0] > 1)
1767 val
= ucontrol
->value
.enumerated
.item
[0] << 2;
1768 return snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x0004, val
);
1771 static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source
= {
1772 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1773 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
1774 .info
= snd_ac97_ad198x_spdif_source_info
,
1775 .get
= snd_ac97_ad198x_spdif_source_get
,
1776 .put
= snd_ac97_ad198x_spdif_source_put
,
1779 static int patch_ad198x_post_spdif(struct snd_ac97
* ac97
)
1781 return patch_build_controls(ac97
, &snd_ac97_ad198x_spdif_source
, 1);
1784 static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense
[] = {
1785 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 11, 1, 0),
1786 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
1789 /* black list to avoid HP/Line jack-sense controls
1790 * (SS vendor << 16 | device)
1792 static unsigned int ad1981_jacks_blacklist
[] = {
1793 0x10140523, /* Thinkpad R40 */
1794 0x10140534, /* Thinkpad X31 */
1795 0x10140537, /* Thinkpad T41p */
1796 0x10140554, /* Thinkpad T42p/R50p */
1800 static int check_list(struct snd_ac97
*ac97
, const unsigned int *list
)
1802 u32 subid
= ((u32
)ac97
->subsystem_vendor
<< 16) | ac97
->subsystem_device
;
1803 for (; *list
; list
++)
1809 static int patch_ad1981a_specific(struct snd_ac97
* ac97
)
1811 if (check_list(ac97
, ad1981_jacks_blacklist
))
1813 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1814 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1817 static struct snd_ac97_build_ops patch_ad1981a_build_ops
= {
1818 .build_post_spdif
= patch_ad198x_post_spdif
,
1819 .build_specific
= patch_ad1981a_specific
,
1821 .resume
= ad18xx_resume
1825 /* white list to enable HP jack-sense bits
1826 * (SS vendor << 16 | device)
1828 static unsigned int ad1981_jacks_whitelist
[] = {
1829 0x0e11005a, /* HP nc4000/4010 */
1830 0x103c0890, /* HP nc6000 */
1831 0x103c0938, /* HP nc4220 */
1832 0x103c099c, /* HP nx6110 */
1833 0x103c0944, /* HP nc6220 */
1834 0x103c0934, /* HP nc8220 */
1835 0x103c006d, /* HP nx9105 */
1836 0x17340088, /* FSC Scenic-W */
1840 static void check_ad1981_hp_jack_sense(struct snd_ac97
*ac97
)
1842 if (check_list(ac97
, ad1981_jacks_whitelist
))
1843 /* enable headphone jack sense */
1844 snd_ac97_update_bits(ac97
, AC97_AD_JACK_SPDIF
, 1<<11, 1<<11);
1847 int patch_ad1981a(struct snd_ac97
*ac97
)
1850 ac97
->build_ops
= &patch_ad1981a_build_ops
;
1851 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1852 ac97
->flags
|= AC97_STEREO_MUTES
;
1853 check_ad1981_hp_jack_sense(ac97
);
1857 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic
=
1858 AC97_SINGLE("Stereo Mic", AC97_AD_MISC
, 6, 1, 0);
1860 static int patch_ad1981b_specific(struct snd_ac97
*ac97
)
1864 if ((err
= patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1)) < 0)
1866 if (check_list(ac97
, ad1981_jacks_blacklist
))
1868 return patch_build_controls(ac97
, snd_ac97_ad1981x_jack_sense
,
1869 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense
));
1872 static struct snd_ac97_build_ops patch_ad1981b_build_ops
= {
1873 .build_post_spdif
= patch_ad198x_post_spdif
,
1874 .build_specific
= patch_ad1981b_specific
,
1876 .resume
= ad18xx_resume
1880 int patch_ad1981b(struct snd_ac97
*ac97
)
1883 ac97
->build_ops
= &patch_ad1981b_build_ops
;
1884 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD198X_MSPLT
, AC97_AD198X_MSPLT
);
1885 ac97
->flags
|= AC97_STEREO_MUTES
;
1886 check_ad1981_hp_jack_sense(ac97
);
1890 static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1892 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1894 uinfo
->value
.integer
.min
= 0;
1895 uinfo
->value
.integer
.max
= 1;
1899 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1901 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1904 val
= ac97
->regs
[AC97_AD_MISC
];
1905 ucontrol
->value
.integer
.value
[0] = !(val
& AC97_AD198X_LOSEL
);
1909 static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1911 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1914 val
= !ucontrol
->value
.integer
.value
[0]
1915 ? (AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
) : 0;
1916 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1917 AC97_AD198X_LOSEL
| AC97_AD198X_HPSEL
, val
);
1920 static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1922 static char *texts
[3] = {"Off", "6 -> 4", "6 -> 2"};
1924 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1926 uinfo
->value
.enumerated
.items
= 3;
1927 if (uinfo
->value
.enumerated
.item
> 2)
1928 uinfo
->value
.enumerated
.item
= 2;
1929 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1933 static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1935 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1938 val
= ac97
->regs
[AC97_AD_MISC
];
1939 if (!(val
& AC97_AD198X_DMIX1
))
1940 ucontrol
->value
.enumerated
.item
[0] = 0;
1942 ucontrol
->value
.enumerated
.item
[0] = 1 + ((val
>> 8) & 1);
1946 static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1948 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
1951 if (ucontrol
->value
.enumerated
.item
[0] > 2)
1953 if (ucontrol
->value
.enumerated
.item
[0] == 0)
1956 val
= AC97_AD198X_DMIX1
|
1957 ((ucontrol
->value
.enumerated
.item
[0] - 1) << 8);
1958 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
1959 AC97_AD198X_DMIX0
| AC97_AD198X_DMIX1
, val
);
1962 static void ad1888_update_jacks(struct snd_ac97
*ac97
)
1964 unsigned short val
= 0;
1965 /* clear LODIS if shared jack is to be used for Surround out */
1966 if (is_shared_linein(ac97
))
1968 /* clear CLDIS if shared jack is to be used for C/LFE out */
1969 if (is_shared_micin(ac97
))
1971 /* shared Line-In */
1972 snd_ac97_update_bits(ac97
, AC97_AD_MISC
, (1 << 11) | (1 << 12), val
);
1975 static const struct snd_kcontrol_new snd_ac97_ad1888_controls
[] = {
1977 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1978 .name
= "Exchange Front/Surround",
1979 .info
= snd_ac97_ad1888_lohpsel_info
,
1980 .get
= snd_ac97_ad1888_lohpsel_get
,
1981 .put
= snd_ac97_ad1888_lohpsel_put
1983 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC
, 2, 1, 1),
1984 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2
, 12, 1, 1),
1985 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC
, 7, 1, 0),
1987 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1989 .info
= snd_ac97_ad1888_downmix_info
,
1990 .get
= snd_ac97_ad1888_downmix_get
,
1991 .put
= snd_ac97_ad1888_downmix_put
1993 AC97_SURROUND_JACK_MODE_CTL
,
1994 AC97_CHANNEL_MODE_CTL
,
1996 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 10, 1, 0),
1997 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
2000 static int patch_ad1888_specific(struct snd_ac97
*ac97
)
2002 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2003 snd_ac97_rename_vol_ctl(ac97
, "Master Playback", "Master Surround Playback");
2004 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Master Playback");
2005 return patch_build_controls(ac97
, snd_ac97_ad1888_controls
, ARRAY_SIZE(snd_ac97_ad1888_controls
));
2008 static struct snd_ac97_build_ops patch_ad1888_build_ops
= {
2009 .build_post_spdif
= patch_ad198x_post_spdif
,
2010 .build_specific
= patch_ad1888_specific
,
2012 .resume
= ad1888_resume
,
2014 .update_jacks
= ad1888_update_jacks
,
2017 int patch_ad1888(struct snd_ac97
* ac97
)
2019 unsigned short misc
;
2022 ac97
->build_ops
= &patch_ad1888_build_ops
;
2023 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2024 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
2025 /* AD-compatible mode */
2026 /* Stereo mutes enabled */
2027 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
2028 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
2032 AC97_AD198X_AC97NC
);
2033 ac97
->flags
|= AC97_STEREO_MUTES
;
2037 static int patch_ad1980_specific(struct snd_ac97
*ac97
)
2041 if ((err
= patch_ad1888_specific(ac97
)) < 0)
2043 return patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1);
2046 static struct snd_ac97_build_ops patch_ad1980_build_ops
= {
2047 .build_post_spdif
= patch_ad198x_post_spdif
,
2048 .build_specific
= patch_ad1980_specific
,
2050 .resume
= ad18xx_resume
,
2052 .update_jacks
= ad1888_update_jacks
,
2055 int patch_ad1980(struct snd_ac97
* ac97
)
2058 ac97
->build_ops
= &patch_ad1980_build_ops
;
2062 static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol
*kcontrol
,
2063 struct snd_ctl_elem_info
*uinfo
)
2065 static char *texts
[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
2067 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2069 uinfo
->value
.enumerated
.items
= 4;
2070 if (uinfo
->value
.enumerated
.item
> 3)
2071 uinfo
->value
.enumerated
.item
= 3;
2072 strcpy(uinfo
->value
.enumerated
.name
,
2073 texts
[uinfo
->value
.enumerated
.item
]);
2077 static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol
*kcontrol
,
2078 struct snd_ctl_elem_value
*ucontrol
)
2080 static const int reg2ctrl
[4] = {2, 0, 1, 3};
2081 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2083 val
= (ac97
->regs
[AC97_AD_MISC
] & AC97_AD198X_VREF_MASK
)
2084 >> AC97_AD198X_VREF_SHIFT
;
2085 ucontrol
->value
.enumerated
.item
[0] = reg2ctrl
[val
];
2089 static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol
*kcontrol
,
2090 struct snd_ctl_elem_value
*ucontrol
)
2092 static const int ctrl2reg
[4] = {1, 2, 0, 3};
2093 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2096 if (ucontrol
->value
.enumerated
.item
[0] > 3
2097 || ucontrol
->value
.enumerated
.item
[0] < 0)
2099 val
= ctrl2reg
[ucontrol
->value
.enumerated
.item
[0]]
2100 << AC97_AD198X_VREF_SHIFT
;
2101 return snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
2102 AC97_AD198X_VREF_MASK
, val
);
2105 static const struct snd_kcontrol_new snd_ac97_ad1985_controls
[] = {
2106 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG
, 3, 1, 0),
2108 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2109 .name
= "Exchange Front/Surround",
2110 .info
= snd_ac97_ad1888_lohpsel_info
,
2111 .get
= snd_ac97_ad1888_lohpsel_get
,
2112 .put
= snd_ac97_ad1888_lohpsel_put
2114 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2
, 12, 1, 1),
2115 AC97_SINGLE("Spread Front to Surround and Center/LFE",
2116 AC97_AD_MISC
, 7, 1, 0),
2118 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2120 .info
= snd_ac97_ad1888_downmix_info
,
2121 .get
= snd_ac97_ad1888_downmix_get
,
2122 .put
= snd_ac97_ad1888_downmix_put
2125 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2127 .info
= snd_ac97_ad1985_vrefout_info
,
2128 .get
= snd_ac97_ad1985_vrefout_get
,
2129 .put
= snd_ac97_ad1985_vrefout_put
2131 AC97_SURROUND_JACK_MODE_CTL
,
2132 AC97_CHANNEL_MODE_CTL
,
2134 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 10, 1, 0),
2135 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0),
2138 static void ad1985_update_jacks(struct snd_ac97
*ac97
)
2140 ad1888_update_jacks(ac97
);
2141 /* clear OMS if shared jack is to be used for C/LFE out */
2142 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 1 << 9,
2143 is_shared_micin(ac97
) ? 1 << 9 : 0);
2146 static int patch_ad1985_specific(struct snd_ac97
*ac97
)
2150 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2151 snd_ac97_rename_vol_ctl(ac97
, "Master Playback",
2152 "Master Surround Playback");
2153 snd_ac97_rename_vol_ctl(ac97
, "Headphone Playback", "Master Playback");
2155 if ((err
= patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1)) < 0)
2158 return patch_build_controls(ac97
, snd_ac97_ad1985_controls
,
2159 ARRAY_SIZE(snd_ac97_ad1985_controls
));
2162 static struct snd_ac97_build_ops patch_ad1985_build_ops
= {
2163 .build_post_spdif
= patch_ad198x_post_spdif
,
2164 .build_specific
= patch_ad1985_specific
,
2166 .resume
= ad18xx_resume
,
2168 .update_jacks
= ad1985_update_jacks
,
2171 int patch_ad1985(struct snd_ac97
* ac97
)
2173 unsigned short misc
;
2176 ac97
->build_ops
= &patch_ad1985_build_ops
;
2177 misc
= snd_ac97_read(ac97
, AC97_AD_MISC
);
2178 /* switch front/surround line-out/hp-out */
2179 /* AD-compatible mode */
2180 /* Stereo mutes enabled */
2181 snd_ac97_write_cache(ac97
, AC97_AD_MISC
, misc
|
2185 AC97_AD198X_AC97NC
);
2186 ac97
->flags
|= AC97_STEREO_MUTES
;
2188 /* update current jack configuration */
2189 ad1985_update_jacks(ac97
);
2191 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2192 ac97
->ext_id
= (ac97
->ext_id
& ~AC97_EI_REV_MASK
) | AC97_EI_REV_23
;
2196 static int snd_ac97_ad1986_bool_info(struct snd_kcontrol
*kcontrol
,
2197 struct snd_ctl_elem_info
*uinfo
)
2199 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2201 uinfo
->value
.integer
.min
= 0;
2202 uinfo
->value
.integer
.max
= 1;
2206 static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol
*kcontrol
,
2207 struct snd_ctl_elem_value
*ucontrol
)
2209 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2212 val
= ac97
->regs
[AC97_AD_MISC3
];
2213 ucontrol
->value
.integer
.value
[0] = (val
& AC97_AD1986_LOSEL
) != 0;
2217 static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol
*kcontrol
,
2218 struct snd_ctl_elem_value
*ucontrol
)
2220 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2223 int sprd
= (ac97
->regs
[AC97_AD_MISC
] & AC97_AD1986_SPRD
) != 0;
2225 ret0
= snd_ac97_update_bits(ac97
, AC97_AD_MISC3
, AC97_AD1986_LOSEL
,
2226 ucontrol
->value
.integer
.value
[0] != 0
2227 ? AC97_AD1986_LOSEL
: 0);
2231 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2232 ret1
= snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD1986_SOSEL
,
2233 (ucontrol
->value
.integer
.value
[0] != 0
2235 ? AC97_AD1986_SOSEL
: 0);
2239 return (ret0
> 0 || ret1
> 0) ? 1 : 0;
2242 static int snd_ac97_ad1986_spread_get(struct snd_kcontrol
*kcontrol
,
2243 struct snd_ctl_elem_value
*ucontrol
)
2245 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2248 val
= ac97
->regs
[AC97_AD_MISC
];
2249 ucontrol
->value
.integer
.value
[0] = (val
& AC97_AD1986_SPRD
) != 0;
2253 static int snd_ac97_ad1986_spread_put(struct snd_kcontrol
*kcontrol
,
2254 struct snd_ctl_elem_value
*ucontrol
)
2256 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2259 int sprd
= (ac97
->regs
[AC97_AD_MISC3
] & AC97_AD1986_LOSEL
) != 0;
2261 ret0
= snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD1986_SPRD
,
2262 ucontrol
->value
.integer
.value
[0] != 0
2263 ? AC97_AD1986_SPRD
: 0);
2267 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2268 ret1
= snd_ac97_update_bits(ac97
, AC97_AD_MISC
, AC97_AD1986_SOSEL
,
2269 (ucontrol
->value
.integer
.value
[0] != 0
2271 ? AC97_AD1986_SOSEL
: 0);
2275 return (ret0
> 0 || ret1
> 0) ? 1 : 0;
2278 static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol
*kcontrol
,
2279 struct snd_ctl_elem_value
*ucontrol
)
2281 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2283 ucontrol
->value
.integer
.value
[0] = ac97
->spec
.ad18xx
.swap_mic_linein
;
2287 static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol
*kcontrol
,
2288 struct snd_ctl_elem_value
*ucontrol
)
2290 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2291 unsigned char swap
= ucontrol
->value
.integer
.value
[0] != 0;
2293 if (swap
!= ac97
->spec
.ad18xx
.swap_mic_linein
) {
2294 ac97
->spec
.ad18xx
.swap_mic_linein
= swap
;
2295 if (ac97
->build_ops
->update_jacks
)
2296 ac97
->build_ops
->update_jacks(ac97
);
2302 static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol
*kcontrol
,
2303 struct snd_ctl_elem_value
*ucontrol
)
2305 /* Use MIC_1/2 V_REFOUT as the "get" value */
2306 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2308 unsigned short reg
= ac97
->regs
[AC97_AD_MISC2
];
2309 if ((reg
& AC97_AD1986_MVREF0
) != 0)
2311 else if ((reg
& AC97_AD1986_MVREF1
) != 0)
2313 else if ((reg
& AC97_AD1986_MVREF2
) != 0)
2317 ucontrol
->value
.enumerated
.item
[0] = val
;
2321 static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol
*kcontrol
,
2322 struct snd_ctl_elem_value
*ucontrol
)
2324 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2325 unsigned short cval
;
2326 unsigned short lval
;
2327 unsigned short mval
;
2332 switch (ucontrol
->value
.enumerated
.item
[0])
2334 case 0: /* High-Z */
2340 cval
= AC97_AD1986_CVREF2
;
2341 lval
= AC97_AD1986_LVREF2
;
2342 mval
= AC97_AD1986_MVREF2
;
2344 case 2: /* 2.25 V */
2345 cval
= AC97_AD1986_CVREF0
;
2346 lval
= AC97_AD1986_LVREF0
;
2347 mval
= AC97_AD1986_MVREF0
;
2350 cval
= AC97_AD1986_CVREF1
;
2351 lval
= AC97_AD1986_LVREF1
;
2352 mval
= AC97_AD1986_MVREF1
;
2358 cret
= snd_ac97_update_bits(ac97
, AC97_AD_MISC2
,
2359 AC97_AD1986_CVREF_MASK
, cval
);
2362 lret
= snd_ac97_update_bits(ac97
, AC97_AD_MISC3
,
2363 AC97_AD1986_LVREF_MASK
, lval
);
2366 mret
= snd_ac97_update_bits(ac97
, AC97_AD_MISC2
,
2367 AC97_AD1986_MVREF_MASK
, mval
);
2371 return (cret
> 0 || lret
> 0 || mret
> 0) ? 1 : 0;
2374 static const struct snd_kcontrol_new snd_ac97_ad1986_controls
[] = {
2375 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG
, 3, 1, 0),
2377 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2378 .name
= "Exchange Front/Surround",
2379 .info
= snd_ac97_ad1986_bool_info
,
2380 .get
= snd_ac97_ad1986_lososel_get
,
2381 .put
= snd_ac97_ad1986_lososel_put
2384 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2385 .name
= "Exchange Mic/Line In",
2386 .info
= snd_ac97_ad1986_bool_info
,
2387 .get
= snd_ac97_ad1986_miclisel_get
,
2388 .put
= snd_ac97_ad1986_miclisel_put
2391 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2392 .name
= "Spread Front to Surround and Center/LFE",
2393 .info
= snd_ac97_ad1986_bool_info
,
2394 .get
= snd_ac97_ad1986_spread_get
,
2395 .put
= snd_ac97_ad1986_spread_put
2398 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2400 .info
= snd_ac97_ad1888_downmix_info
,
2401 .get
= snd_ac97_ad1888_downmix_get
,
2402 .put
= snd_ac97_ad1888_downmix_put
2405 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2407 .info
= snd_ac97_ad1985_vrefout_info
,
2408 .get
= snd_ac97_ad1986_vrefout_get
,
2409 .put
= snd_ac97_ad1986_vrefout_put
2411 AC97_SURROUND_JACK_MODE_CTL
,
2412 AC97_CHANNEL_MODE_CTL
,
2414 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF
, 10, 1, 0),
2415 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF
, 12, 1, 0)
2418 static void ad1986_update_jacks(struct snd_ac97
*ac97
)
2420 unsigned short misc_val
= 0;
2421 unsigned short ser_val
;
2423 /* disable SURROUND and CENTER/LFE if not surround mode */
2424 if (!is_surround_on(ac97
))
2425 misc_val
|= AC97_AD1986_SODIS
;
2426 if (!is_clfe_on(ac97
))
2427 misc_val
|= AC97_AD1986_CLDIS
;
2429 /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2430 if (is_shared_linein(ac97
))
2431 misc_val
|= AC97_AD1986_LISEL_SURR
;
2432 else if (ac97
->spec
.ad18xx
.swap_mic_linein
!= 0)
2433 misc_val
|= AC97_AD1986_LISEL_MIC
;
2434 snd_ac97_update_bits(ac97
, AC97_AD_MISC
,
2435 AC97_AD1986_SODIS
| AC97_AD1986_CLDIS
|
2436 AC97_AD1986_LISEL_MASK
,
2439 /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2440 if (is_shared_micin(ac97
))
2441 ser_val
= AC97_AD1986_OMS_C
;
2442 else if (ac97
->spec
.ad18xx
.swap_mic_linein
!= 0)
2443 ser_val
= AC97_AD1986_OMS_L
;
2445 ser_val
= AC97_AD1986_OMS_M
;
2446 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
,
2447 AC97_AD1986_OMS_MASK
,
2451 static int patch_ad1986_specific(struct snd_ac97
*ac97
)
2455 if ((err
= patch_build_controls(ac97
, &snd_ac97_ad198x_2cmic
, 1)) < 0)
2458 return patch_build_controls(ac97
, snd_ac97_ad1986_controls
,
2459 ARRAY_SIZE(snd_ac97_ad1985_controls
));
2462 static struct snd_ac97_build_ops patch_ad1986_build_ops
= {
2463 .build_post_spdif
= patch_ad198x_post_spdif
,
2464 .build_specific
= patch_ad1986_specific
,
2466 .resume
= ad18xx_resume
,
2468 .update_jacks
= ad1986_update_jacks
,
2471 int patch_ad1986(struct snd_ac97
* ac97
)
2474 ac97
->build_ops
= &patch_ad1986_build_ops
;
2475 ac97
->flags
|= AC97_STEREO_MUTES
;
2477 /* update current jack configuration */
2478 ad1986_update_jacks(ac97
);
2485 * realtek ALC65x/850 codecs
2487 static void alc650_update_jacks(struct snd_ac97
*ac97
)
2491 /* shared Line-In / Surround Out */
2492 shared
= is_shared_surrout(ac97
);
2493 snd_ac97_update_bits(ac97
, AC97_ALC650_MULTICH
, 1 << 9,
2494 shared
? (1 << 9) : 0);
2495 /* update shared Mic In / Center/LFE Out */
2496 shared
= is_shared_clfeout(ac97
);
2497 /* disable/enable vref */
2498 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
2499 shared
? (1 << 12) : 0);
2500 /* turn on/off center-on-mic */
2501 snd_ac97_update_bits(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
2502 shared
? (1 << 10) : 0);
2503 /* GPIO0 high for mic */
2504 snd_ac97_update_bits(ac97
, AC97_ALC650_GPIO_STATUS
, 0x100,
2505 shared
? 0 : 0x100);
2508 static const struct snd_kcontrol_new snd_ac97_controls_alc650
[] = {
2509 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0),
2510 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH
, 1, 1, 0),
2511 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH
, 2, 1, 0),
2512 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH
, 3, 1, 0),
2513 /* 4: Analog Input To Surround */
2514 /* 5: Analog Input To Center/LFE */
2515 /* 6: Independent Master Volume Right */
2516 /* 7: Independent Master Volume Left */
2518 /* 9: Line-In/Surround share */
2519 /* 10: Mic/CLFE share */
2520 /* 11-13: in IEC958 controls */
2521 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH
, 14, 1, 0),
2522 #if 0 /* always set in patch_alc650 */
2523 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK
, 0, 1, 0),
2524 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK
, 1, 1, 0),
2525 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL
, 15, 1, 1),
2526 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL
, 8, 0, 31, 1),
2527 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL
, 15, 1, 1),
2528 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL
, 8, 0, 31, 1),
2530 AC97_SURROUND_JACK_MODE_CTL
,
2531 AC97_CHANNEL_MODE_CTL
,
2534 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650
[] = {
2535 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_ALC650_MULTICH
, 11, 1, 0),
2536 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH
, 12, 1, 0),
2537 /* disable this controls since it doesn't work as expected */
2538 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2541 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max
, -4350, 150, 0);
2543 static int patch_alc650_specific(struct snd_ac97
* ac97
)
2547 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc650
, ARRAY_SIZE(snd_ac97_controls_alc650
))) < 0)
2549 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2550 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc650
, ARRAY_SIZE(snd_ac97_spdif_controls_alc650
))) < 0)
2553 if (ac97
->id
!= AC97_ID_ALC650F
)
2554 reset_tlv(ac97
, "Master Playback Volume",
2555 db_scale_5bit_3db_max
);
2559 static struct snd_ac97_build_ops patch_alc650_ops
= {
2560 .build_specific
= patch_alc650_specific
,
2561 .update_jacks
= alc650_update_jacks
2564 int patch_alc650(struct snd_ac97
* ac97
)
2568 ac97
->build_ops
= &patch_alc650_ops
;
2570 /* determine the revision */
2571 val
= snd_ac97_read(ac97
, AC97_ALC650_REVISION
) & 0x3f;
2573 ac97
->id
= 0x414c4720; /* Old version */
2574 else if (val
< 0x10)
2575 ac97
->id
= 0x414c4721; /* D version */
2576 else if (val
< 0x20)
2577 ac97
->id
= 0x414c4722; /* E version */
2578 else if (val
< 0x30)
2579 ac97
->id
= 0x414c4723; /* F version */
2581 /* revision E or F */
2582 /* FIXME: what about revision D ? */
2583 ac97
->spec
.dev_flags
= (ac97
->id
== 0x414c4722 ||
2584 ac97
->id
== 0x414c4723);
2586 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2587 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
2588 snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x8000);
2590 /* Enable SPDIF-IN only on Rev.E and above */
2591 val
= snd_ac97_read(ac97
, AC97_ALC650_CLOCK
);
2592 /* SPDIF IN with pin 47 */
2593 if (ac97
->spec
.dev_flags
&&
2594 /* ASUS A6KM requires EAPD */
2595 ! (ac97
->subsystem_vendor
== 0x1043 &&
2596 ac97
->subsystem_device
== 0x1103))
2597 val
|= 0x03; /* enable */
2599 val
&= ~0x03; /* disable */
2600 snd_ac97_write_cache(ac97
, AC97_ALC650_CLOCK
, val
);
2602 /* set default: slot 3,4,7,8,6,9
2603 spdif-in monitor off, analog-spdif off, spdif-in off
2604 center on mic off, surround on line-in off
2605 downmix off, duplicate front off
2607 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 0);
2609 /* set GPIO0 for mic bias */
2610 /* GPIO0 pin output, no interrupt, high */
2611 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_SETUP
,
2612 snd_ac97_read(ac97
, AC97_ALC650_GPIO_SETUP
) | 0x01);
2613 snd_ac97_write_cache(ac97
, AC97_ALC650_GPIO_STATUS
,
2614 (snd_ac97_read(ac97
, AC97_ALC650_GPIO_STATUS
) | 0x100) & ~0x10);
2616 /* full DAC volume */
2617 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2618 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2622 static void alc655_update_jacks(struct snd_ac97
*ac97
)
2626 /* shared Line-In / Surround Out */
2627 shared
= is_shared_surrout(ac97
);
2628 ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 1 << 9,
2629 shared
? (1 << 9) : 0, 0);
2630 /* update shared Mic In / Center/LFE Out */
2631 shared
= is_shared_clfeout(ac97
);
2632 /* misc control; vrefout disable */
2633 snd_ac97_update_bits(ac97
, AC97_ALC650_CLOCK
, 1 << 12,
2634 shared
? (1 << 12) : 0);
2635 ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 1 << 10,
2636 shared
? (1 << 10) : 0, 0);
2639 static const struct snd_kcontrol_new snd_ac97_controls_alc655
[] = {
2640 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
2641 AC97_SURROUND_JACK_MODE_CTL
,
2642 AC97_CHANNEL_MODE_CTL
,
2645 static int alc655_iec958_route_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2647 static char *texts_655
[3] = { "PCM", "Analog In", "IEC958 In" };
2648 static char *texts_658
[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2649 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2651 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2653 uinfo
->value
.enumerated
.items
= ac97
->spec
.dev_flags
? 4 : 3;
2654 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2655 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2656 strcpy(uinfo
->value
.enumerated
.name
,
2657 ac97
->spec
.dev_flags
?
2658 texts_658
[uinfo
->value
.enumerated
.item
] :
2659 texts_655
[uinfo
->value
.enumerated
.item
]);
2663 static int alc655_iec958_route_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2665 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2668 val
= ac97
->regs
[AC97_ALC650_MULTICH
];
2669 val
= (val
>> 12) & 3;
2670 if (ac97
->spec
.dev_flags
&& val
== 3)
2672 ucontrol
->value
.enumerated
.item
[0] = val
;
2676 static int alc655_iec958_route_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2678 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2680 return ac97_update_bits_page(ac97
, AC97_ALC650_MULTICH
, 3 << 12,
2681 (unsigned short)ucontrol
->value
.enumerated
.item
[0] << 12,
2685 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655
[] = {
2686 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_ALC650_MULTICH
, 11, 1, 0, 0),
2687 /* disable this controls since it doesn't work as expected */
2688 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2690 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2691 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
2692 .info
= alc655_iec958_route_info
,
2693 .get
= alc655_iec958_route_get
,
2694 .put
= alc655_iec958_route_put
,
2698 static int patch_alc655_specific(struct snd_ac97
* ac97
)
2702 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc655
, ARRAY_SIZE(snd_ac97_controls_alc655
))) < 0)
2704 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2705 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
2711 static struct snd_ac97_build_ops patch_alc655_ops
= {
2712 .build_specific
= patch_alc655_specific
,
2713 .update_jacks
= alc655_update_jacks
2716 int patch_alc655(struct snd_ac97
* ac97
)
2720 if (ac97
->id
== AC97_ID_ALC658
) {
2721 ac97
->spec
.dev_flags
= 1; /* ALC658 */
2722 if ((snd_ac97_read(ac97
, AC97_ALC650_REVISION
) & 0x3f) == 2) {
2723 ac97
->id
= AC97_ID_ALC658D
;
2724 ac97
->spec
.dev_flags
= 2;
2728 ac97
->build_ops
= &patch_alc655_ops
;
2730 /* assume only page 0 for writing cache */
2731 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
2733 /* adjust default values */
2734 val
= snd_ac97_read(ac97
, 0x7a); /* misc control */
2735 if (ac97
->spec
.dev_flags
) /* ALC658 */
2736 val
&= ~(1 << 1); /* Pin 47 is spdif input pin */
2738 if (ac97
->subsystem_vendor
== 0x1462 &&
2739 (ac97
->subsystem_device
== 0x0131 || /* MSI S270 laptop */
2740 ac97
->subsystem_device
== 0x0161 || /* LG K1 Express */
2741 ac97
->subsystem_device
== 0x0351 || /* MSI L725 laptop */
2742 ac97
->subsystem_device
== 0x0061)) /* MSI S250 laptop */
2743 val
&= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2745 val
|= (1 << 1); /* Pin 47 is spdif input pin */
2747 val
&= ~(1 << 12); /* vref enable */
2748 snd_ac97_write_cache(ac97
, 0x7a, val
);
2749 /* set default: spdif-in enabled,
2750 spdif-in monitor off, spdif-in PCM off
2751 center on mic off, surround on line-in off
2754 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
2756 /* full DAC volume */
2757 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2758 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2760 /* update undocumented bit... */
2761 if (ac97
->id
== AC97_ID_ALC658D
)
2762 snd_ac97_update_bits(ac97
, 0x74, 0x0800, 0x0800);
2768 #define AC97_ALC850_JACK_SELECT 0x76
2769 #define AC97_ALC850_MISC1 0x7a
2771 static void alc850_update_jacks(struct snd_ac97
*ac97
)
2775 /* shared Line-In / Surround Out */
2776 shared
= is_shared_surrout(ac97
);
2777 /* SURR 1kOhm (bit4), Amp (bit5) */
2778 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<4)|(1<<5),
2779 shared
? (1<<5) : (1<<4));
2780 /* LINE-IN = 0, SURROUND = 2 */
2781 snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 12,
2782 shared
? (2<<12) : (0<<12));
2783 /* update shared Mic In / Center/LFE Out */
2784 shared
= is_shared_clfeout(ac97
);
2785 /* Vref disable (bit12), 1kOhm (bit13) */
2786 snd_ac97_update_bits(ac97
, AC97_ALC850_MISC1
, (1<<12)|(1<<13),
2787 shared
? (1<<12) : (1<<13));
2788 /* MIC-IN = 1, CENTER-LFE = 5 */
2789 snd_ac97_update_bits(ac97
, AC97_ALC850_JACK_SELECT
, 7 << 4,
2790 shared
? (5<<4) : (1<<4));
2793 static const struct snd_kcontrol_new snd_ac97_controls_alc850
[] = {
2794 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH
, 0, 1, 0, 0),
2795 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT
, 15, 1, 1),
2796 AC97_SURROUND_JACK_MODE_CTL
,
2797 AC97_CHANNEL_MODE_CTL
,
2800 static int patch_alc850_specific(struct snd_ac97
*ac97
)
2804 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_alc850
, ARRAY_SIZE(snd_ac97_controls_alc850
))) < 0)
2806 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
2807 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_alc655
, ARRAY_SIZE(snd_ac97_spdif_controls_alc655
))) < 0)
2813 static struct snd_ac97_build_ops patch_alc850_ops
= {
2814 .build_specific
= patch_alc850_specific
,
2815 .update_jacks
= alc850_update_jacks
2818 int patch_alc850(struct snd_ac97
*ac97
)
2820 ac97
->build_ops
= &patch_alc850_ops
;
2822 ac97
->spec
.dev_flags
= 0; /* for IEC958 playback route - ALC655 compatible */
2824 /* assume only page 0 for writing cache */
2825 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
, AC97_PAGE_MASK
, AC97_PAGE_VENDOR
);
2827 /* adjust default values */
2828 /* set default: spdif-in enabled,
2829 spdif-in monitor off, spdif-in PCM off
2830 center on mic off, surround on line-in off
2833 snd_ac97_write_cache(ac97
, AC97_ALC650_MULTICH
, 1<<15);
2834 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2835 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2837 snd_ac97_write_cache(ac97
, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2838 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2839 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2840 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2842 snd_ac97_write_cache(ac97
, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2843 (1<<11)|(0<<12)|(1<<15));
2845 /* full DAC volume */
2846 snd_ac97_write_cache(ac97
, AC97_ALC650_SURR_DAC_VOL
, 0x0808);
2847 snd_ac97_write_cache(ac97
, AC97_ALC650_LFE_DAC_VOL
, 0x0808);
2853 * C-Media CM97xx codecs
2855 static void cm9738_update_jacks(struct snd_ac97
*ac97
)
2857 /* shared Line-In / Surround Out */
2858 snd_ac97_update_bits(ac97
, AC97_CM9738_VENDOR_CTRL
, 1 << 10,
2859 is_shared_surrout(ac97
) ? (1 << 10) : 0);
2862 static const struct snd_kcontrol_new snd_ac97_cm9738_controls
[] = {
2863 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL
, 13, 1, 0),
2864 AC97_SURROUND_JACK_MODE_CTL
,
2865 AC97_CHANNEL_MODE_4CH_CTL
,
2868 static int patch_cm9738_specific(struct snd_ac97
* ac97
)
2870 return patch_build_controls(ac97
, snd_ac97_cm9738_controls
, ARRAY_SIZE(snd_ac97_cm9738_controls
));
2873 static struct snd_ac97_build_ops patch_cm9738_ops
= {
2874 .build_specific
= patch_cm9738_specific
,
2875 .update_jacks
= cm9738_update_jacks
2878 int patch_cm9738(struct snd_ac97
* ac97
)
2880 ac97
->build_ops
= &patch_cm9738_ops
;
2881 /* FIXME: can anyone confirm below? */
2882 /* CM9738 has no PCM volume although the register reacts */
2883 ac97
->flags
|= AC97_HAS_NO_PCM_VOL
;
2884 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
2889 static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2891 static char *texts
[] = { "Analog", "Digital" };
2893 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2895 uinfo
->value
.enumerated
.items
= 2;
2896 if (uinfo
->value
.enumerated
.item
> 1)
2897 uinfo
->value
.enumerated
.item
= 1;
2898 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2902 static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2904 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2907 val
= ac97
->regs
[AC97_CM9739_SPDIF_CTRL
];
2908 ucontrol
->value
.enumerated
.item
[0] = (val
>> 1) & 0x01;
2912 static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2914 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
2916 return snd_ac97_update_bits(ac97
, AC97_CM9739_SPDIF_CTRL
,
2918 (ucontrol
->value
.enumerated
.item
[0] & 0x01) << 1);
2921 static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif
[] = {
2922 /* BIT 0: SPDI_EN - always true */
2923 { /* BIT 1: SPDIFS */
2924 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2925 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
2926 .info
= snd_ac97_cmedia_spdif_playback_source_info
,
2927 .get
= snd_ac97_cmedia_spdif_playback_source_get
,
2928 .put
= snd_ac97_cmedia_spdif_playback_source_put
,
2930 /* BIT 2: IG_SPIV */
2931 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Valid Switch", AC97_CM9739_SPDIF_CTRL
, 2, 1, 0),
2933 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Monitor", AC97_CM9739_SPDIF_CTRL
, 3, 1, 0),
2934 /* BIT 4: SPI2SDI */
2935 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_CM9739_SPDIF_CTRL
, 4, 1, 0),
2936 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2939 static void cm9739_update_jacks(struct snd_ac97
*ac97
)
2941 /* shared Line-In / Surround Out */
2942 snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 1 << 10,
2943 is_shared_surrout(ac97
) ? (1 << 10) : 0);
2944 /* shared Mic In / Center/LFE Out **/
2945 snd_ac97_update_bits(ac97
, AC97_CM9739_MULTI_CHAN
, 0x3000,
2946 is_shared_clfeout(ac97
) ? 0x1000 : 0x2000);
2949 static const struct snd_kcontrol_new snd_ac97_cm9739_controls
[] = {
2950 AC97_SURROUND_JACK_MODE_CTL
,
2951 AC97_CHANNEL_MODE_CTL
,
2954 static int patch_cm9739_specific(struct snd_ac97
* ac97
)
2956 return patch_build_controls(ac97
, snd_ac97_cm9739_controls
, ARRAY_SIZE(snd_ac97_cm9739_controls
));
2959 static int patch_cm9739_post_spdif(struct snd_ac97
* ac97
)
2961 return patch_build_controls(ac97
, snd_ac97_cm9739_controls_spdif
, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif
));
2964 static struct snd_ac97_build_ops patch_cm9739_ops
= {
2965 .build_specific
= patch_cm9739_specific
,
2966 .build_post_spdif
= patch_cm9739_post_spdif
,
2967 .update_jacks
= cm9739_update_jacks
2970 int patch_cm9739(struct snd_ac97
* ac97
)
2974 ac97
->build_ops
= &patch_cm9739_ops
;
2976 /* CM9739/A has no Master and PCM volume although the register reacts */
2977 ac97
->flags
|= AC97_HAS_NO_MASTER_VOL
| AC97_HAS_NO_PCM_VOL
;
2978 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8000);
2979 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8000);
2982 val
= snd_ac97_read(ac97
, AC97_EXTENDED_STATUS
);
2983 if (val
& AC97_EA_SPCV
) {
2984 /* enable spdif in */
2985 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
2986 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) | 0x01);
2987 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
2989 ac97
->ext_id
&= ~AC97_EI_SPDIF
; /* disable extended-id */
2990 ac97
->rates
[AC97_RATES_SPDIF
] = 0;
2993 /* set-up multi channel */
2994 /* bit 14: 0 = SPDIF, 1 = EAPD */
2995 /* bit 13: enable internal vref output for mic */
2996 /* bit 12: disable center/lfe (swithable) */
2997 /* bit 10: disable surround/line (switchable) */
2998 /* bit 9: mix 2 surround off */
2999 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
3000 /* bit 3: undocumented; surround? */
3002 val
= snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) & (1 << 4);
3005 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
3007 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
, val
);
3009 /* FIXME: set up GPIO */
3010 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
3011 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
3012 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3014 ac97
->subsystem_vendor
== 0x1043 &&
3015 ac97
->subsystem_device
== 0x1843) {
3016 snd_ac97_write_cache(ac97
, AC97_CM9739_SPDIF_CTRL
,
3017 snd_ac97_read(ac97
, AC97_CM9739_SPDIF_CTRL
) & ~0x01);
3018 snd_ac97_write_cache(ac97
, AC97_CM9739_MULTI_CHAN
,
3019 snd_ac97_read(ac97
, AC97_CM9739_MULTI_CHAN
) | (1 << 14));
3025 #define AC97_CM9761_MULTI_CHAN 0x64
3026 #define AC97_CM9761_FUNC 0x66
3027 #define AC97_CM9761_SPDIF_CTRL 0x6c
3029 static void cm9761_update_jacks(struct snd_ac97
*ac97
)
3031 /* FIXME: check the bits for each model
3032 * model 83 is confirmed to work
3034 static unsigned short surr_on
[3][2] = {
3035 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3036 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3037 { 0x0000, 0x0008 }, /* 9761-83 */
3039 static unsigned short clfe_on
[3][2] = {
3040 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3041 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3042 { 0x0000, 0x1000 }, /* 9761-83 */
3044 static unsigned short surr_shared
[3][2] = {
3045 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3046 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3047 { 0x0000, 0x0400 }, /* 9761-83 */
3049 static unsigned short clfe_shared
[3][2] = {
3050 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3051 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3052 { 0x2000, 0x0800 }, /* 9761-83 */
3054 unsigned short val
= 0;
3056 val
|= surr_on
[ac97
->spec
.dev_flags
][is_surround_on(ac97
)];
3057 val
|= clfe_on
[ac97
->spec
.dev_flags
][is_clfe_on(ac97
)];
3058 val
|= surr_shared
[ac97
->spec
.dev_flags
][is_shared_surrout(ac97
)];
3059 val
|= clfe_shared
[ac97
->spec
.dev_flags
][is_shared_clfeout(ac97
)];
3061 snd_ac97_update_bits(ac97
, AC97_CM9761_MULTI_CHAN
, 0x3c88, val
);
3064 static const struct snd_kcontrol_new snd_ac97_cm9761_controls
[] = {
3065 AC97_SURROUND_JACK_MODE_CTL
,
3066 AC97_CHANNEL_MODE_CTL
,
3069 static int cm9761_spdif_out_source_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3071 static char *texts
[] = { "AC-Link", "ADC", "SPDIF-In" };
3073 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3075 uinfo
->value
.enumerated
.items
= 3;
3076 if (uinfo
->value
.enumerated
.item
> 2)
3077 uinfo
->value
.enumerated
.item
= 2;
3078 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3082 static int cm9761_spdif_out_source_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3084 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
3086 if (ac97
->regs
[AC97_CM9761_FUNC
] & 0x1)
3087 ucontrol
->value
.enumerated
.item
[0] = 2; /* SPDIF-loopback */
3088 else if (ac97
->regs
[AC97_CM9761_SPDIF_CTRL
] & 0x2)
3089 ucontrol
->value
.enumerated
.item
[0] = 1; /* ADC loopback */
3091 ucontrol
->value
.enumerated
.item
[0] = 0; /* AC-link */
3095 static int cm9761_spdif_out_source_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3097 struct snd_ac97
*ac97
= snd_kcontrol_chip(kcontrol
);
3099 if (ucontrol
->value
.enumerated
.item
[0] == 2)
3100 return snd_ac97_update_bits(ac97
, AC97_CM9761_FUNC
, 0x1, 0x1);
3101 snd_ac97_update_bits(ac97
, AC97_CM9761_FUNC
, 0x1, 0);
3102 return snd_ac97_update_bits(ac97
, AC97_CM9761_SPDIF_CTRL
, 0x2,
3103 ucontrol
->value
.enumerated
.item
[0] == 1 ? 0x2 : 0);
3106 static const char *cm9761_dac_clock
[] = { "AC-Link", "SPDIF-In", "Both" };
3107 static const struct ac97_enum cm9761_dac_clock_enum
=
3108 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL
, 9, 3, cm9761_dac_clock
);
3110 static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif
[] = {
3111 { /* BIT 1: SPDIFS */
3112 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3113 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,NONE
) "Source",
3114 .info
= cm9761_spdif_out_source_info
,
3115 .get
= cm9761_spdif_out_source_get
,
3116 .put
= cm9761_spdif_out_source_put
,
3118 /* BIT 2: IG_SPIV */
3119 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Valid Switch", AC97_CM9761_SPDIF_CTRL
, 2, 1, 0),
3121 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,NONE
) "Monitor", AC97_CM9761_SPDIF_CTRL
, 3, 1, 0),
3122 /* BIT 4: SPI2SDI */
3123 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), AC97_CM9761_SPDIF_CTRL
, 4, 1, 0),
3124 /* BIT 9-10: DAC_CTL */
3125 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum
),
3128 static int patch_cm9761_post_spdif(struct snd_ac97
* ac97
)
3130 return patch_build_controls(ac97
, snd_ac97_cm9761_controls_spdif
, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif
));
3133 static int patch_cm9761_specific(struct snd_ac97
* ac97
)
3135 return patch_build_controls(ac97
, snd_ac97_cm9761_controls
, ARRAY_SIZE(snd_ac97_cm9761_controls
));
3138 static struct snd_ac97_build_ops patch_cm9761_ops
= {
3139 .build_specific
= patch_cm9761_specific
,
3140 .build_post_spdif
= patch_cm9761_post_spdif
,
3141 .update_jacks
= cm9761_update_jacks
3144 int patch_cm9761(struct snd_ac97
*ac97
)
3148 /* CM9761 has no PCM volume although the register reacts */
3149 /* Master volume seems to have _some_ influence on the analog
3152 ac97
->flags
|= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL
;
3153 snd_ac97_write_cache(ac97
, AC97_MASTER
, 0x8808);
3154 snd_ac97_write_cache(ac97
, AC97_PCM
, 0x8808);
3156 ac97
->spec
.dev_flags
= 0; /* 1 = model 82 revision B, 2 = model 83 */
3157 if (ac97
->id
== AC97_ID_CM9761_82
) {
3159 /* check page 1, reg 0x60 */
3160 val
= snd_ac97_read(ac97
, AC97_INT_PAGING
);
3161 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, (val
& ~0x0f) | 0x01);
3162 tmp
= snd_ac97_read(ac97
, 0x60);
3163 ac97
->spec
.dev_flags
= tmp
& 1; /* revision B? */
3164 snd_ac97_write_cache(ac97
, AC97_INT_PAGING
, val
);
3165 } else if (ac97
->id
== AC97_ID_CM9761_83
)
3166 ac97
->spec
.dev_flags
= 2;
3168 ac97
->build_ops
= &patch_cm9761_ops
;
3171 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3172 ac97
->ext_id
|= AC97_EI_SPDIF
;
3173 /* to be sure: we overwrite the ext status bits */
3174 snd_ac97_write_cache(ac97
, AC97_EXTENDED_STATUS
, 0x05c0);
3175 /* Don't set 0x0200 here. This results in the silent analog output */
3176 snd_ac97_write_cache(ac97
, AC97_CM9761_SPDIF_CTRL
, 0x0001); /* enable spdif-in */
3177 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
3179 /* set-up multi channel */
3180 /* bit 15: pc master beep off
3181 * bit 14: pin47 = EAPD/SPDIF
3182 * bit 13: vref ctl [= cm9739]
3183 * bit 12: CLFE control (reverted on rev B)
3184 * bit 11: Mic/center share (reverted on rev B)
3185 * bit 10: suddound/line share
3186 * bit 9: Analog-in mix -> surround
3187 * bit 8: Analog-in mix -> CLFE
3188 * bit 7: Mic/LFE share (mic/center/lfe)
3189 * bit 5: vref select (9761A)
3190 * bit 4: front control
3191 * bit 3: surround control (revereted with rev B)
3194 * bit 0: mic boost level (0=20dB, 1=30dB)
3198 if (ac97
->spec
.dev_flags
)
3203 val
= snd_ac97_read(ac97
, AC97_CM9761_MULTI_CHAN
);
3204 val
|= (1 << 4); /* front on */
3205 snd_ac97_write_cache(ac97
, AC97_CM9761_MULTI_CHAN
, val
);
3207 /* FIXME: set up GPIO */
3208 snd_ac97_write_cache(ac97
, 0x70, 0x0100);
3209 snd_ac97_write_cache(ac97
, 0x72, 0x0020);
3214 #define AC97_CM9780_SIDE 0x60
3215 #define AC97_CM9780_JACK 0x62
3216 #define AC97_CM9780_MIXER 0x64
3217 #define AC97_CM9780_MULTI_CHAN 0x66
3218 #define AC97_CM9780_SPDIF 0x6c
3220 static const char *cm9780_ch_select
[] = { "Front", "Side", "Center/LFE", "Rear" };
3221 static const struct ac97_enum cm9780_ch_select_enum
=
3222 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN
, 6, 4, cm9780_ch_select
);
3223 static const struct snd_kcontrol_new cm9780_controls
[] = {
3224 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE
, 15, 7, 1, 1),
3225 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE
, 8, 0, 31, 0),
3226 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum
),
3229 static int patch_cm9780_specific(struct snd_ac97
*ac97
)
3231 return patch_build_controls(ac97
, cm9780_controls
, ARRAY_SIZE(cm9780_controls
));
3234 static struct snd_ac97_build_ops patch_cm9780_ops
= {
3235 .build_specific
= patch_cm9780_specific
,
3236 .build_post_spdif
= patch_cm9761_post_spdif
/* identical with CM9761 */
3239 int patch_cm9780(struct snd_ac97
*ac97
)
3243 ac97
->build_ops
= &patch_cm9780_ops
;
3246 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
3247 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_48000
; /* 48k only */
3248 val
= snd_ac97_read(ac97
, AC97_CM9780_SPDIF
);
3249 val
|= 0x1; /* SPDI_EN */
3250 snd_ac97_write_cache(ac97
, AC97_CM9780_SPDIF
, val
);
3259 static const struct snd_kcontrol_new snd_ac97_controls_vt1616
[] = {
3260 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3261 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3262 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3263 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3266 static int patch_vt1616_specific(struct snd_ac97
* ac97
)
3270 if (snd_ac97_try_bit(ac97
, 0x5a, 9))
3271 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[0], 1)) < 0)
3273 if ((err
= patch_build_controls(ac97
, &snd_ac97_controls_vt1616
[1], ARRAY_SIZE(snd_ac97_controls_vt1616
) - 1)) < 0)
3278 static struct snd_ac97_build_ops patch_vt1616_ops
= {
3279 .build_specific
= patch_vt1616_specific
3282 int patch_vt1616(struct snd_ac97
* ac97
)
3284 ac97
->build_ops
= &patch_vt1616_ops
;
3291 int patch_vt1617a(struct snd_ac97
* ac97
)
3293 /* bring analog power consumption to normal, like WinXP driver
3296 snd_ac97_write_cache(ac97
, 0x5c, 0x20);
3297 ac97
->ext_id
|= AC97_EI_SPDIF
; /* force the detection of spdif */
3298 ac97
->rates
[AC97_RATES_SPDIF
] = SNDRV_PCM_RATE_44100
| SNDRV_PCM_RATE_48000
;
3299 ac97
->build_ops
= &patch_vt1616_ops
;
3305 static void it2646_update_jacks(struct snd_ac97
*ac97
)
3307 /* shared Line-In / Surround Out */
3308 snd_ac97_update_bits(ac97
, 0x76, 1 << 9,
3309 is_shared_surrout(ac97
) ? (1<<9) : 0);
3310 /* shared Mic / Center/LFE Out */
3311 snd_ac97_update_bits(ac97
, 0x76, 1 << 10,
3312 is_shared_clfeout(ac97
) ? (1<<10) : 0);
3315 static const struct snd_kcontrol_new snd_ac97_controls_it2646
[] = {
3316 AC97_SURROUND_JACK_MODE_CTL
,
3317 AC97_CHANNEL_MODE_CTL
,
3320 static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646
[] = {
3321 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE
,SWITCH
), 0x76, 11, 1, 0),
3322 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3323 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3326 static int patch_it2646_specific(struct snd_ac97
* ac97
)
3329 if ((err
= patch_build_controls(ac97
, snd_ac97_controls_it2646
, ARRAY_SIZE(snd_ac97_controls_it2646
))) < 0)
3331 if ((err
= patch_build_controls(ac97
, snd_ac97_spdif_controls_it2646
, ARRAY_SIZE(snd_ac97_spdif_controls_it2646
))) < 0)
3336 static struct snd_ac97_build_ops patch_it2646_ops
= {
3337 .build_specific
= patch_it2646_specific
,
3338 .update_jacks
= it2646_update_jacks
3341 int patch_it2646(struct snd_ac97
* ac97
)
3343 ac97
->build_ops
= &patch_it2646_ops
;
3344 /* full DAC volume */
3345 snd_ac97_write_cache(ac97
, 0x5E, 0x0808);
3346 snd_ac97_write_cache(ac97
, 0x7A, 0x0808);
3354 #define AC97_SI3036_CHIP_ID 0x5a
3355 #define AC97_SI3036_LINE_CFG 0x5c
3357 static const struct snd_kcontrol_new snd_ac97_controls_si3036
[] = {
3358 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3361 static int patch_si3036_specific(struct snd_ac97
* ac97
)
3364 for (idx
= 0; idx
< ARRAY_SIZE(snd_ac97_controls_si3036
); idx
++)
3365 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ctl_new1(&snd_ac97_controls_si3036
[idx
], ac97
))) < 0)
3370 static struct snd_ac97_build_ops patch_si3036_ops
= {
3371 .build_specific
= patch_si3036_specific
,
3374 int mpatch_si3036(struct snd_ac97
* ac97
)
3376 ac97
->build_ops
= &patch_si3036_ops
;
3377 snd_ac97_write_cache(ac97
, 0x5c, 0xf210 );
3378 snd_ac97_write_cache(ac97
, 0x68, 0);
3385 * We use a static resolution table since LM4550 codec cannot be
3386 * properly autoprobed to determine the resolution via
3387 * check_volume_resolution().
3390 static struct snd_ac97_res_table lm4550_restbl
[] = {
3391 { AC97_MASTER
, 0x1f1f },
3392 { AC97_HEADPHONE
, 0x1f1f },
3393 { AC97_MASTER_MONO
, 0x001f },
3394 { AC97_PC_BEEP
, 0x001f }, /* LSB is ignored */
3395 { AC97_PHONE
, 0x001f },
3396 { AC97_MIC
, 0x001f },
3397 { AC97_LINE
, 0x1f1f },
3398 { AC97_CD
, 0x1f1f },
3399 { AC97_VIDEO
, 0x1f1f },
3400 { AC97_AUX
, 0x1f1f },
3401 { AC97_PCM
, 0x1f1f },
3402 { AC97_REC_GAIN
, 0x0f0f },
3403 { } /* terminator */
3406 int patch_lm4550(struct snd_ac97
*ac97
)
3408 ac97
->res_table
= lm4550_restbl
;
3413 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3415 static const struct snd_kcontrol_new snd_ac97_controls_ucb1400
[] = {
3416 /* enable/disable headphone driver which allows direct connection to
3417 stereo headphone without the use of external DC blocking
3419 AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3420 /* Filter used to compensate the DC offset is added in the ADC to remove idle
3421 tones from the audio band. */
3422 AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3423 /* Control smart-low-power mode feature. Allows automatic power down
3424 of unused blocks in the ADC analog front end and the PLL. */
3425 AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3428 static int patch_ucb1400_specific(struct snd_ac97
* ac97
)
3431 for (idx
= 0; idx
< ARRAY_SIZE(snd_ac97_controls_ucb1400
); idx
++)
3432 if ((err
= snd_ctl_add(ac97
->bus
->card
, snd_ctl_new1(&snd_ac97_controls_ucb1400
[idx
], ac97
))) < 0)
3437 static struct snd_ac97_build_ops patch_ucb1400_ops
= {
3438 .build_specific
= patch_ucb1400_specific
,
3441 int patch_ucb1400(struct snd_ac97
* ac97
)
3443 ac97
->build_ops
= &patch_ucb1400_ops
;
3444 /* enable headphone driver and smart low power mode by default */
3445 snd_ac97_write(ac97
, 0x6a, 0x0050);
3446 snd_ac97_write(ac97
, 0x6c, 0x0030);