blob: 50f420d69a8a282e41ea23596e32dc72874ddd0f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Universal interface for Audio Codec '97
4 *
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com) and to datasheets
7 * for specific codecs.
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "ac97_local.h"
Takashi Iwaiac519022007-02-22 12:58:27 +010027#include "ac97_patch.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/*
Andreas Mohr6ba92562011-02-19 00:49:48 +010030 * Forward declarations
31 */
32
33static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
34 const char *name);
35static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
36 const unsigned int *tlv, const char **slaves);
37
38/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * Chip specific initialization
40 */
41
Takashi Iwaiee423812005-11-17 14:21:36 +010042static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 int idx, err;
45
46 for (idx = 0; idx < count; idx++)
47 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
48 return err;
49 return 0;
50}
51
Takashi Iwai2f3482f2006-08-21 18:44:31 +020052/* replace with a new TLV */
53static void reset_tlv(struct snd_ac97 *ac97, const char *name,
Takashi Iwai0cb29ea2007-01-29 15:33:49 +010054 const unsigned int *tlv)
Takashi Iwai2f3482f2006-08-21 18:44:31 +020055{
56 struct snd_ctl_elem_id sid;
57 struct snd_kcontrol *kctl;
58 memset(&sid, 0, sizeof(sid));
59 strcpy(sid.name, name);
60 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
61 kctl = snd_ctl_find_id(ac97->bus->card, &sid);
62 if (kctl && kctl->tlv.p)
63 kctl->tlv.p = tlv;
64}
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/* set to the page, update bits and restore the page */
Takashi Iwaiee423812005-11-17 14:21:36 +010067static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 unsigned short page_save;
70 int ret;
71
Ingo Molnar62932df2006-01-16 16:34:20 +010072 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
74 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
75 ret = snd_ac97_update_bits(ac97, reg, mask, value);
76 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
Ingo Molnar62932df2006-01-16 16:34:20 +010077 mutex_unlock(&ac97->page_mutex); /* unlock paging */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return ret;
79}
80
Takashi Iwaieb8caf32005-04-13 14:32:57 +020081/*
82 * shared line-in/mic controls
83 */
Takashi Iwaiee423812005-11-17 14:21:36 +010084static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020085{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +020086 static const char * const texts[] = { "Shared", "Independent" };
87
88 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020089}
90
Takashi Iwaiee423812005-11-17 14:21:36 +010091static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020092{
Takashi Iwaiee423812005-11-17 14:21:36 +010093 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020094
95 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
96 return 0;
97}
98
Takashi Iwaiee423812005-11-17 14:21:36 +010099static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200100{
Takashi Iwaiee423812005-11-17 14:21:36 +0100101 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200102 unsigned char indep = !!ucontrol->value.enumerated.item[0];
103
104 if (indep != ac97->indep_surround) {
105 ac97->indep_surround = indep;
106 if (ac97->build_ops->update_jacks)
107 ac97->build_ops->update_jacks(ac97);
108 return 1;
109 }
110 return 0;
111}
112
Takashi Iwaiee423812005-11-17 14:21:36 +0100113static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200114{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200115 static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
116
117 return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200118}
119
Takashi Iwaiee423812005-11-17 14:21:36 +0100120static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200121{
Takashi Iwaiee423812005-11-17 14:21:36 +0100122 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200123
124 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
125 return 0;
126}
127
Takashi Iwaiee423812005-11-17 14:21:36 +0100128static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200129{
Takashi Iwaiee423812005-11-17 14:21:36 +0100130 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200131 unsigned char mode = ucontrol->value.enumerated.item[0];
132
Takashi Iwai4235a312008-02-18 12:23:13 +0100133 if (mode >= kcontrol->private_value)
134 return -EINVAL;
Takashi Iwai4e98d6a2007-11-15 15:58:13 +0100135
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200136 if (mode != ac97->channel_mode) {
137 ac97->channel_mode = mode;
138 if (ac97->build_ops->update_jacks)
139 ac97->build_ops->update_jacks(ac97);
140 return 1;
141 }
142 return 0;
143}
144
145#define AC97_SURROUND_JACK_MODE_CTL \
146 { \
147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
148 .name = "Surround Jack Mode", \
149 .info = ac97_surround_jack_mode_info, \
150 .get = ac97_surround_jack_mode_get, \
151 .put = ac97_surround_jack_mode_put, \
152 }
Takashi Iwai4235a312008-02-18 12:23:13 +0100153/* 6ch */
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200154#define AC97_CHANNEL_MODE_CTL \
155 { \
156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
157 .name = "Channel Mode", \
158 .info = ac97_channel_mode_info, \
159 .get = ac97_channel_mode_get, \
160 .put = ac97_channel_mode_put, \
Takashi Iwai4235a312008-02-18 12:23:13 +0100161 .private_value = 3, \
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200162 }
Takashi Iwai4235a312008-02-18 12:23:13 +0100163/* 4ch */
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200164#define AC97_CHANNEL_MODE_4CH_CTL \
165 { \
166 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
167 .name = "Channel Mode", \
168 .info = ac97_channel_mode_info, \
169 .get = ac97_channel_mode_get, \
170 .put = ac97_channel_mode_put, \
Takashi Iwai4235a312008-02-18 12:23:13 +0100171 .private_value = 2, \
172 }
173/* 8ch */
174#define AC97_CHANNEL_MODE_8CH_CTL \
175 { \
176 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
177 .name = "Channel Mode", \
178 .info = ac97_channel_mode_info, \
179 .get = ac97_channel_mode_get, \
180 .put = ac97_channel_mode_put, \
181 .private_value = 4, \
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200182 }
183
Takashi Iwaiee423812005-11-17 14:21:36 +0100184static inline int is_surround_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200185{
186 return ac97->channel_mode >= 1;
187}
188
Takashi Iwaiee423812005-11-17 14:21:36 +0100189static inline int is_clfe_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200190{
Takashi Iwaieb9b4142005-09-13 18:39:21 +0200191 return ac97->channel_mode >= 2;
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200192}
193
Randy Cushman831466f2006-12-19 18:42:16 +0100194/* system has shared jacks with surround out enabled */
195static inline int is_shared_surrout(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200196{
Randy Cushman831466f2006-12-19 18:42:16 +0100197 return !ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200198}
199
Randy Cushman831466f2006-12-19 18:42:16 +0100200/* system has shared jacks with center/lfe out enabled */
201static inline int is_shared_clfeout(struct snd_ac97 *ac97)
202{
203 return !ac97->indep_surround && is_clfe_on(ac97);
204}
205
206/* system has shared jacks with line in enabled */
207static inline int is_shared_linein(struct snd_ac97 *ac97)
208{
209 return !ac97->indep_surround && !is_surround_on(ac97);
210}
211
212/* system has shared jacks with mic in enabled */
Takashi Iwaiee423812005-11-17 14:21:36 +0100213static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200214{
Randy Cushman831466f2006-12-19 18:42:16 +0100215 return !ac97->indep_surround && !is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200216}
217
Takashi Iwai4235a312008-02-18 12:23:13 +0100218static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
219{
220 return is_surround_on(ac97);
221}
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
Keita Maehara43115f52007-09-19 14:29:37 +0200224/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Keita Maehara13043982007-09-19 14:27:38 +0200226/* It is possible to indicate to the Yamaha YMF7x3 the type of
227 speakers being used. */
228
229static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200232 static const char * const texts[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 "Standard", "Small", "Smaller"
234 };
235
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200236 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
Keita Maehara13043982007-09-19 14:27:38 +0200239static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
240 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Takashi Iwaiee423812005-11-17 14:21:36 +0100242 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 unsigned short val;
244
Keita Maehara13043982007-09-19 14:27:38 +0200245 val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 val = (val >> 10) & 3;
247 if (val > 0) /* 0 = invalid */
248 val--;
249 ucontrol->value.enumerated.item[0] = val;
250 return 0;
251}
252
Keita Maehara13043982007-09-19 14:27:38 +0200253static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Takashi Iwaiee423812005-11-17 14:21:36 +0100256 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 unsigned short val;
258
259 if (ucontrol->value.enumerated.item[0] > 2)
260 return -EINVAL;
261 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
Keita Maehara13043982007-09-19 14:27:38 +0200262 return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Keita Maehara13043982007-09-19 14:27:38 +0200265static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
268 .name = "3D Control - Speaker",
Keita Maehara13043982007-09-19 14:27:38 +0200269 .info = snd_ac97_ymf7x3_info_speaker,
270 .get = snd_ac97_ymf7x3_get_speaker,
271 .put = snd_ac97_ymf7x3_put_speaker,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272};
273
Keita Maehara13043982007-09-19 14:27:38 +0200274/* It is possible to indicate to the Yamaha YMF7x3 the source to
275 direct to the S/PDIF output. */
276static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200279 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200281 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Keita Maehara13043982007-09-19 14:27:38 +0200284static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Takashi Iwaiee423812005-11-17 14:21:36 +0100287 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 unsigned short val;
289
Keita Maehara13043982007-09-19 14:27:38 +0200290 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
292 return 0;
293}
294
Keita Maehara13043982007-09-19 14:27:38 +0200295static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Takashi Iwaiee423812005-11-17 14:21:36 +0100298 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 unsigned short val;
300
301 if (ucontrol->value.enumerated.item[0] > 1)
302 return -EINVAL;
303 val = ucontrol->value.enumerated.item[0] << 1;
Keita Maehara13043982007-09-19 14:27:38 +0200304 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
Keita Maehara43115f52007-09-19 14:29:37 +0200307static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
308{
309 struct snd_kcontrol *kctl;
310 int err;
311
312 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
313 err = snd_ctl_add(ac97->bus->card, kctl);
314 if (err < 0)
315 return err;
316 strcpy(kctl->id.name, "3D Control - Wide");
317 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
318 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
319 err = snd_ctl_add(ac97->bus->card,
320 snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
321 ac97));
322 if (err < 0)
323 return err;
324 snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
325 return 0;
326}
327
328static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
329{
330 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
331 AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
332 {
333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
334 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
335 .info = snd_ac97_ymf7x3_spdif_source_info,
336 .get = snd_ac97_ymf7x3_spdif_source_get,
337 .put = snd_ac97_ymf7x3_spdif_source_put,
338 },
339 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
340 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
341};
342
343static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
344{
345 int err;
346
347 err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
348 if (err < 0)
349 return err;
350 err = patch_build_controls(ac97,
351 snd_ac97_yamaha_ymf743_controls_spdif, 3);
352 if (err < 0)
353 return err;
354 /* set default PCM S/PDIF params */
355 /* PCM audio,no copyright,no preemphasis,PCM coder,original */
356 snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
357 return 0;
358}
359
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100360static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
Keita Maehara43115f52007-09-19 14:29:37 +0200361 .build_spdif = patch_yamaha_ymf743_build_spdif,
362 .build_3d = patch_yamaha_ymf7x3_3d,
363};
364
365static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
366{
367 ac97->build_ops = &patch_yamaha_ymf743_ops;
368 ac97->caps |= AC97_BC_BASS_TREBLE;
369 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
370 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
371 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
372 return 0;
373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
376 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
377 By default, no output pin is selected, and the S/PDIF signal is not output.
378 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100379static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200381 static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200383 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Takashi Iwaiee423812005-11-17 14:21:36 +0100386static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Takashi Iwaiee423812005-11-17 14:21:36 +0100388 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 unsigned short val;
390
Keita Maehara13043982007-09-19 14:27:38 +0200391 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
393 return 0;
394}
395
Takashi Iwaiee423812005-11-17 14:21:36 +0100396static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Takashi Iwaiee423812005-11-17 14:21:36 +0100398 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 unsigned short val;
400
401 if (ucontrol->value.enumerated.item[0] > 2)
402 return -EINVAL;
403 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
404 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
Keita Maehara13043982007-09-19 14:27:38 +0200405 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
407 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
408}
409
Takashi Iwaiee423812005-11-17 14:21:36 +0100410static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 {
412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
413 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Keita Maehara13043982007-09-19 14:27:38 +0200414 .info = snd_ac97_ymf7x3_spdif_source_info,
415 .get = snd_ac97_ymf7x3_spdif_source_get,
416 .put = snd_ac97_ymf7x3_spdif_source_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
418 {
419 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
420 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
421 .info = snd_ac97_ymf753_spdif_output_pin_info,
422 .get = snd_ac97_ymf753_spdif_output_pin_get,
423 .put = snd_ac97_ymf753_spdif_output_pin_put,
424 },
Keita Maehara13043982007-09-19 14:27:38 +0200425 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
426 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427};
428
Takashi Iwaiee423812005-11-17 14:21:36 +0100429static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 int err;
432
433 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
434 return err;
435 return 0;
436}
437
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100438static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
Keita Maehara13043982007-09-19 14:27:38 +0200439 .build_3d = patch_yamaha_ymf7x3_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 .build_post_spdif = patch_yamaha_ymf753_post_spdif
441};
442
Takashi Iwaiac519022007-02-22 12:58:27 +0100443static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
446 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
447 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
448 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
449 By default, no output pin is selected, and the S/PDIF signal is not output.
450 There is also a bit to mute S/PDIF output in a vendor-specific register.
451 */
452 ac97->build_ops = &patch_yamaha_ymf753_ops;
453 ac97->caps |= AC97_BC_BASS_TREBLE;
454 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
455 return 0;
456}
457
458/*
Liam Girdwoodd3311242008-10-12 13:17:36 +0100459 * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 * removed broken wolfson00 patch.
461 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
462 */
463
Takashi Iwaiee423812005-11-17 14:21:36 +0100464static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200465AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
466AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
467};
468
Takashi Iwaiee423812005-11-17 14:21:36 +0100469static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200472 * Randolph Bentson <bentson@holmsjoen.com>
473 * WM9703/9707/9708/9717
474 */
475 int err, i;
476
477 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
478 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
479 return err;
480 }
481 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 return 0;
483}
Liam Girdwood3998b702005-07-29 11:41:55 +0200484
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100485static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200486 .build_specific = patch_wolfson_wm9703_specific,
487};
488
Takashi Iwaiac519022007-02-22 12:58:27 +0100489static int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200490{
491 ac97->build_ops = &patch_wolfson_wm9703_ops;
492 return 0;
493}
494
Takashi Iwaiee423812005-11-17 14:21:36 +0100495static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200496AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
497AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
498AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
499AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
500AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
501AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
502};
503
Takashi Iwaiee423812005-11-17 14:21:36 +0100504static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200505{
506 int err, i;
507 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
508 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
509 return err;
510 }
511 /* patch for DVD noise */
512 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
513 return 0;
514}
515
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100516static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200517 .build_specific = patch_wolfson_wm9704_specific,
518};
519
Takashi Iwaiac519022007-02-22 12:58:27 +0100520static int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Liam Girdwood3998b702005-07-29 11:41:55 +0200522 /* WM9704M/9704Q */
523 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return 0;
525}
Liam Girdwood3998b702005-07-29 11:41:55 +0200526
Takashi Iwaiac519022007-02-22 12:58:27 +0100527static int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Liam Girdwood3998b702005-07-29 11:41:55 +0200529 /* WM9705, WM9710 */
Krzysztof Heltdd3533e2010-01-01 19:05:43 +0100530 ac97->build_ops = &patch_wolfson_wm9703_ops;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200531#ifdef CONFIG_TOUCHSCREEN_WM9705
532 /* WM9705 touchscreen uses AUX and VIDEO for touch */
Liam Girdwood8f888202006-09-07 18:07:46 +0200533 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200534#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return 0;
536}
537
Liam Girdwood3998b702005-07-29 11:41:55 +0200538static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
539static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
540static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
541static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
542static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
543static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
544static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
545static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
546static const char* wm9711_rec_sel[] =
547 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
548static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
549
550static const struct ac97_enum wm9711_enum[] = {
551AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
552AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
553AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
554AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
555AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
556AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
557AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
558AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
559AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
560AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
561};
562
Takashi Iwaiee423812005-11-17 14:21:36 +0100563static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200564AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
565AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
566AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
567AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
568AC97_ENUM("ALC Function", wm9711_enum[0]),
569AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
570AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
571AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
572AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
573AC97_ENUM("ALC NG Type", wm9711_enum[9]),
574AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
575
576AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
577AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
578AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
579AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
580
581AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200582AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200583AC97_ENUM("Out3 Mux", wm9711_enum[2]),
584AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
585AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
586
587AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
588AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
589AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
590AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
591AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
592AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
593
594AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
595AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
596AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
597AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
598AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
599AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
600
601AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
602AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
603
604AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
605AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
606AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
607
608AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
609AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
610AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
611
612AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
613AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
614AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
615AC97_ENUM("Capture Select", wm9711_enum[8]),
616
617AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
618AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
619
620AC97_ENUM("Bass Control", wm9711_enum[5]),
621AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
622AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
623AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
624
625AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
626AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200627AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200628AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
629
630AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
631AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
632AC97_ENUM("Mic Select Source", wm9711_enum[7]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200633AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
634AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100635AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200636
Juergen Beisert0264b3b2008-06-06 17:02:57 +0200637AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200638AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
639AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
640AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
641};
642
Takashi Iwaiee423812005-11-17 14:21:36 +0100643static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200644{
645 int err, i;
646
647 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
648 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
649 return err;
650 }
651 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
652 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
653 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
654 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
655 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
656 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
657 return 0;
658}
659
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100660static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200661 .build_specific = patch_wolfson_wm9711_specific,
662};
663
Takashi Iwaiac519022007-02-22 12:58:27 +0100664static int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Liam Girdwood3998b702005-07-29 11:41:55 +0200666 /* WM9711, WM9712 */
667 ac97->build_ops = &patch_wolfson_wm9711_ops;
668
669 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
670 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return 0;
673}
674
Liam Girdwood3998b702005-07-29 11:41:55 +0200675static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200677static const char* wm9713_rec_src[] =
678 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
679 "Mono Mix", "Zh"};
680static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
681static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
682static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
683static const char* wm9713_spk_pga[] =
684 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
685static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
686static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
687static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
688static const char* wm9713_dac_inv[] =
689 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
690 "Headphone Mix Mono", "NC", "Vmid"};
691static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
692static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694static const struct ac97_enum wm9713_enum[] = {
695AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
696AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
697AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200698AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
699AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
700AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
701AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
702AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
703AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
704AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
705AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
706AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
707AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
708AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709};
710
Takashi Iwaiee423812005-11-17 14:21:36 +0100711static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200713AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
714AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
715AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
716
717AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
718AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
719AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
720AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
721
722AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
723AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
724AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
725AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100726AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200727AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
728AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
729
730AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
731AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
732AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
733AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
734
735AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
736AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
737AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
738AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
739AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
740AC97_ENUM("Capture Select", wm9713_enum[3]),
741
742AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
743AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
744AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
745AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
746AC97_ENUM("ALC Function", wm9713_enum[5]),
747AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
748AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
749AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
750AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
751AC97_ENUM("ALC NG Type", wm9713_enum[13]),
752AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
753
754AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
755AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
756AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
757AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
758AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
759AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
760
761AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
762AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
763AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
764AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
765AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
766AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
767
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100768AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
769AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
770AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
771AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
772AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
773AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200774
775AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
776AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
777AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
778AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
779AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
780AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
781
782AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
783AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
784AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
785AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
786AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
787AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
788
789AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
790AC97_ENUM("Master Input Mux", wm9713_enum[7]),
791AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
792AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
793AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
794
795AC97_ENUM("Bass Control", wm9713_enum[12]),
796AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
797AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
798AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
799AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
800AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801};
802
Takashi Iwaiee423812005-11-17 14:21:36 +0100803static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200804AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
805AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
806AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
807AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808};
809
Takashi Iwaiee423812005-11-17 14:21:36 +0100810static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200811{
812 int err, i;
813
814 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
815 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
816 return err;
817 }
818 return 0;
819}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Takashi Iwaiee423812005-11-17 14:21:36 +0100821static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823 int err, i;
824
Liam Girdwood3998b702005-07-29 11:41:55 +0200825 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
826 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return err;
828 }
829 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
832 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
835 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 return 0;
837}
838
839#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100840static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
842 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
843 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
844}
845
Takashi Iwaiee423812005-11-17 14:21:36 +0100846static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
849 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
850 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
851}
852#endif
853
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100854static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200856 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#ifdef CONFIG_PM
858 .suspend = patch_wolfson_wm9713_suspend,
859 .resume = patch_wolfson_wm9713_resume
860#endif
861};
862
Takashi Iwaiac519022007-02-22 12:58:27 +0100863static int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Liam Girdwood3998b702005-07-29 11:41:55 +0200865 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 ac97->build_ops = &patch_wolfson_wm9713_ops;
867
868 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200869 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
870 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200871 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
874 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
875 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
876
877 return 0;
878}
879
880/*
881 * Tritech codec
882 */
Takashi Iwaiac519022007-02-22 12:58:27 +0100883static int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
885 snd_ac97_write_cache(ac97, 0x26, 0x0300);
886 snd_ac97_write_cache(ac97, 0x26, 0x0000);
887 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
888 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
889 return 0;
890}
891
892/*
893 * Sigmatel STAC97xx codecs
894 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100895static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Takashi Iwaiee423812005-11-17 14:21:36 +0100897 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 int err;
899
900 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
901 return err;
902 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
903 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
904 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
905 return 0;
906}
907
Takashi Iwaiee423812005-11-17 14:21:36 +0100908static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Takashi Iwaiee423812005-11-17 14:21:36 +0100910 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 int err;
912
913 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
914 return err;
915 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
916 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
917 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
918 return err;
919 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
920 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
921 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
922 return 0;
923}
924
Takashi Iwaiee423812005-11-17 14:21:36 +0100925static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200926AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
927 AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200929/* "Sigmatel " removed due to excessive name length: */
Takashi Iwaiee423812005-11-17 14:21:36 +0100930static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200931AC97_SINGLE("Surround Phase Inversion Playback Switch",
932 AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Takashi Iwaiee423812005-11-17 14:21:36 +0100934static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
936AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
937};
938
Takashi Iwaiee423812005-11-17 14:21:36 +0100939static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
941 int err;
942
943 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
944 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
945 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
946 return err;
947 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
948 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
949 return err;
950 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
951 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
952 return err;
953 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
954 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
955 return err;
956 return 0;
957}
958
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100959static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 .build_3d = patch_sigmatel_stac9700_3d,
961 .build_specific = patch_sigmatel_stac97xx_specific
962};
963
Takashi Iwaiac519022007-02-22 12:58:27 +0100964static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 ac97->build_ops = &patch_sigmatel_stac9700_ops;
967 return 0;
968}
969
Takashi Iwaiee423812005-11-17 14:21:36 +0100970static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Takashi Iwaiee423812005-11-17 14:21:36 +0100972 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 int err;
974
Ingo Molnar62932df2006-01-16 16:34:20 +0100975 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
977 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
978 (ucontrol->value.integer.value[0] & 1) << 4);
979 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100980 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 return err;
982}
983
Takashi Iwaiee423812005-11-17 14:21:36 +0100984static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
986 .name = "Sigmatel Output Bias Switch",
987 .info = snd_ac97_info_volsw,
988 .get = snd_ac97_get_volsw,
989 .put = snd_ac97_stac9708_put_bias,
990 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
991};
992
Takashi Iwaiee423812005-11-17 14:21:36 +0100993static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 int err;
996
James C Georgase4c3bf02006-12-19 11:09:41 +0100997 /* the register bit is writable, but the function is not implemented: */
998 snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
1001 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
1002 return err;
1003 return patch_sigmatel_stac97xx_specific(ac97);
1004}
1005
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001006static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .build_3d = patch_sigmatel_stac9708_3d,
1008 .build_specific = patch_sigmatel_stac9708_specific
1009};
1010
Takashi Iwaiac519022007-02-22 12:58:27 +01001011static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
1013 unsigned int codec72, codec6c;
1014
1015 ac97->build_ops = &patch_sigmatel_stac9708_ops;
1016 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
1017
1018 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
1019 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
1020
1021 if ((codec72==0) && (codec6c==0)) {
1022 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1023 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
1024 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1025 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
1026 } else if ((codec72==0x8000) && (codec6c==0)) {
1027 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1028 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
1029 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
1030 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
1031 /* nothing */
1032 }
1033 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1034 return 0;
1035}
1036
Takashi Iwaiac519022007-02-22 12:58:27 +01001037static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
1039 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1040 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1041 // patch for SigmaTel
1042 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1043 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1044 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1045 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1046 }
1047 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1048 return 0;
1049}
1050
Takashi Iwaiac519022007-02-22 12:58:27 +01001051static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
1053 // patch for SigmaTel
1054 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1055 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1056 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1057 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1058 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1059 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1060 return 0;
1061}
1062
Takashi Iwaiac519022007-02-22 12:58:27 +01001063static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
1065 // patch for SigmaTel
1066 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1067 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1068 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1069 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1070 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1071 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1072 return 0;
1073}
1074
Takashi Iwaiee423812005-11-17 14:21:36 +01001075static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001077 static const char * const texts[5] = {
1078 "Input/Disabled", "Front Output",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 "Rear Output", "Center/LFE Output", "Mixer Output" };
1080
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001081 return snd_ctl_enum_info(uinfo, 1, 5, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Takashi Iwaiee423812005-11-17 14:21:36 +01001084static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Takashi Iwaiee423812005-11-17 14:21:36 +01001086 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 int shift = kcontrol->private_value;
1088 unsigned short val;
1089
1090 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1091 if (!(val & 4))
1092 ucontrol->value.enumerated.item[0] = 0;
1093 else
1094 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1095 return 0;
1096}
1097
Takashi Iwaiee423812005-11-17 14:21:36 +01001098static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Takashi Iwaiee423812005-11-17 14:21:36 +01001100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 int shift = kcontrol->private_value;
1102 unsigned short val;
1103
1104 if (ucontrol->value.enumerated.item[0] > 4)
1105 return -EINVAL;
1106 if (ucontrol->value.enumerated.item[0] == 0)
1107 val = 0;
1108 else
1109 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1110 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1111 7 << shift, val << shift, 0);
1112}
1113
Takashi Iwaiee423812005-11-17 14:21:36 +01001114static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001116 static const char * const texts[7] = {
1117 "Mic2 Jack", "Mic1 Jack", "Line In Jack",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1119
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001120 return snd_ctl_enum_info(uinfo, 1, 7, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
Takashi Iwaiee423812005-11-17 14:21:36 +01001123static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Takashi Iwaiee423812005-11-17 14:21:36 +01001125 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 int shift = kcontrol->private_value;
1127 unsigned short val;
1128
1129 val = ac97->regs[AC97_SIGMATEL_INSEL];
1130 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1131 return 0;
1132}
1133
Takashi Iwaiee423812005-11-17 14:21:36 +01001134static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Takashi Iwaiee423812005-11-17 14:21:36 +01001136 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 int shift = kcontrol->private_value;
1138
1139 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1140 ucontrol->value.enumerated.item[0] << shift, 0);
1141}
1142
Takashi Iwaiee423812005-11-17 14:21:36 +01001143static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001145 static const char * const texts[3] = {
1146 "None", "Front Jack", "Rear Jack"
1147 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001149 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Takashi Iwaiee423812005-11-17 14:21:36 +01001152static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153{
Takashi Iwaiee423812005-11-17 14:21:36 +01001154 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1157 return 0;
1158}
1159
Takashi Iwaiee423812005-11-17 14:21:36 +01001160static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
Takashi Iwaiee423812005-11-17 14:21:36 +01001162 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1165 ucontrol->value.enumerated.item[0], 0);
1166}
1167
1168#define STAC9758_OUTPUT_JACK(xname, shift) \
1169{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1170 .info = snd_ac97_stac9758_output_jack_info, \
1171 .get = snd_ac97_stac9758_output_jack_get, \
1172 .put = snd_ac97_stac9758_output_jack_put, \
1173 .private_value = shift }
1174#define STAC9758_INPUT_JACK(xname, shift) \
1175{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1176 .info = snd_ac97_stac9758_input_jack_info, \
1177 .get = snd_ac97_stac9758_input_jack_get, \
1178 .put = snd_ac97_stac9758_input_jack_put, \
1179 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001180static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1182 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1183 STAC9758_OUTPUT_JACK("Front Jack", 7),
1184 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1185 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1186 STAC9758_INPUT_JACK("Mic Input Source", 0),
1187 STAC9758_INPUT_JACK("Line Input Source", 8),
1188 {
1189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190 .name = "Headphone Amp",
1191 .info = snd_ac97_stac9758_phonesel_info,
1192 .get = snd_ac97_stac9758_phonesel_get,
1193 .put = snd_ac97_stac9758_phonesel_put
1194 },
1195 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1196 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1197};
1198
Takashi Iwaiee423812005-11-17 14:21:36 +01001199static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200{
1201 int err;
1202
1203 err = patch_sigmatel_stac97xx_specific(ac97);
1204 if (err < 0)
1205 return err;
1206 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1207 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1208 if (err < 0)
1209 return err;
1210 /* DAC-A direct */
1211 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1212 /* DAC-A to Mix = PCM */
1213 /* DAC-B direct = Surround */
1214 /* DAC-B to Mix */
1215 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1216 /* DAC-C direct = Center/LFE */
1217
1218 return 0;
1219}
1220
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001221static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .build_3d = patch_sigmatel_stac9700_3d,
1223 .build_specific = patch_sigmatel_stac9758_specific
1224};
1225
Takashi Iwaiac519022007-02-22 12:58:27 +01001226static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
1228 static unsigned short regs[4] = {
1229 AC97_SIGMATEL_OUTSEL,
1230 AC97_SIGMATEL_IOMISC,
1231 AC97_SIGMATEL_INSEL,
1232 AC97_SIGMATEL_VARIOUS
1233 };
1234 static unsigned short def_regs[4] = {
1235 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1236 /* IOMISC */ 0x2001,
1237 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1238 /* VARIOUS */ 0x0040
1239 };
1240 static unsigned short m675_regs[4] = {
1241 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1242 /* IOMISC */ 0x2102, /* HP amp on */
1243 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1244 /* VARIOUS */ 0x0041 /* stereo mic */
1245 };
1246 unsigned short *pregs = def_regs;
1247 int i;
1248
1249 /* Gateway M675 notebook */
1250 if (ac97->pci &&
1251 ac97->subsystem_vendor == 0x107b &&
1252 ac97->subsystem_device == 0x0601)
1253 pregs = m675_regs;
1254
1255 // patch for SigmaTel
1256 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1257 /* FIXME: assume only page 0 for writing cache */
1258 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1259 for (i = 0; i < 4; i++)
1260 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1261
1262 ac97->flags |= AC97_STEREO_MUTES;
1263 return 0;
1264}
1265
1266/*
1267 * Cirrus Logic CS42xx codecs
1268 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001269static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1271 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1272};
1273
Takashi Iwaiee423812005-11-17 14:21:36 +01001274static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
1276 int err;
1277
1278 /* con mask, pro mask, default */
1279 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1280 return err;
1281 /* switch, spsa */
1282 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1283 return err;
1284 switch (ac97->id & AC97_ID_CS_MASK) {
1285 case AC97_ID_CS4205:
1286 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1287 return err;
1288 break;
1289 }
1290 /* set default PCM S/PDIF params */
1291 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1292 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1293 return 0;
1294}
1295
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001296static const struct snd_ac97_build_ops patch_cirrus_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 .build_spdif = patch_cirrus_build_spdif
1298};
1299
Takashi Iwaiac519022007-02-22 12:58:27 +01001300static int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1303 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1304 - sp/dif EA ID is not set, but sp/dif is always present.
1305 - enable/disable is spdif register bit 15.
1306 - sp/dif control register is 0x68. differs from AC97:
1307 - valid is bit 14 (vs 15)
1308 - no DRS
1309 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1310 - sp/dif ssource select is in 0x5e bits 0,1.
1311 */
1312
1313 ac97->build_ops = &patch_cirrus_ops;
1314 ac97->flags |= AC97_CS_SPDIF;
1315 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1316 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1317 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1318 return 0;
1319}
1320
Takashi Iwaiac519022007-02-22 12:58:27 +01001321static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
1323 /* force the detection of PC Beep */
1324 ac97->flags |= AC97_HAS_PC_BEEP;
1325
1326 return patch_cirrus_spdif(ac97);
1327}
1328
1329/*
1330 * Conexant codecs
1331 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001332static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1334};
1335
Takashi Iwaiee423812005-11-17 14:21:36 +01001336static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
1338 int err;
1339
1340 /* con mask, pro mask, default */
1341 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1342 return err;
1343 /* switch */
1344 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1345 return err;
1346 /* set default PCM S/PDIF params */
1347 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1348 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1349 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1350 return 0;
1351}
1352
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001353static const struct snd_ac97_build_ops patch_conexant_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .build_spdif = patch_conexant_build_spdif
1355};
1356
Takashi Iwaiac519022007-02-22 12:58:27 +01001357static int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
1359 ac97->build_ops = &patch_conexant_ops;
1360 ac97->flags |= AC97_CX_SPDIF;
1361 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1362 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1363 return 0;
1364}
1365
Takashi Iwaiac519022007-02-22 12:58:27 +01001366static int patch_cx20551(struct snd_ac97 *ac97)
Takashi Iwai9e292c02007-02-09 12:42:03 +01001367{
1368 snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
1369 return 0;
1370}
1371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372/*
1373 * Analog Device AD18xx, AD19xx codecs
1374 */
1375#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001376static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
1378 static unsigned short setup_regs[] = {
1379 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1380 };
1381 int i, codec;
1382
1383 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1384 unsigned short reg = setup_regs[i];
1385 if (test_bit(reg, ac97->reg_accessed)) {
1386 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1387 snd_ac97_read(ac97, reg);
1388 }
1389 }
1390
1391 if (! (ac97->flags & AC97_AD_MULTI))
1392 /* normal restore */
1393 snd_ac97_restore_status(ac97);
1394 else {
1395 /* restore the AD18xx codec configurations */
1396 for (codec = 0; codec < 3; codec++) {
1397 if (! ac97->spec.ad18xx.id[codec])
1398 continue;
1399 /* select single codec */
1400 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1401 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1402 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1403 }
1404 /* select all codecs */
1405 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1406
1407 /* restore status */
1408 for (i = 2; i < 0x7c ; i += 2) {
1409 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1410 continue;
1411 if (test_bit(i, ac97->reg_accessed)) {
1412 /* handle multi codecs for AD18xx */
1413 if (i == AC97_PCM) {
1414 for (codec = 0; codec < 3; codec++) {
1415 if (! ac97->spec.ad18xx.id[codec])
1416 continue;
1417 /* select single codec */
1418 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1419 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1420 /* update PCM bits */
1421 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1422 }
1423 /* select all codecs */
1424 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1425 continue;
1426 } else if (i == AC97_AD_TEST ||
1427 i == AC97_AD_CODEC_CFG ||
1428 i == AC97_AD_SERIAL_CFG)
1429 continue; /* ignore */
1430 }
1431 snd_ac97_write(ac97, i, ac97->regs[i]);
1432 snd_ac97_read(ac97, i);
1433 }
1434 }
1435
1436 snd_ac97_restore_iec958(ac97);
1437}
Jaya Kumar1561f092006-06-19 15:06:14 +02001438
1439static void ad1888_resume(struct snd_ac97 *ac97)
1440{
1441 ad18xx_resume(ac97);
1442 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1443}
1444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445#endif
1446
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001447static const struct snd_ac97_res_table ad1819_restbl[] = {
1448 { AC97_PHONE, 0x9f1f },
1449 { AC97_MIC, 0x9f1f },
1450 { AC97_LINE, 0x9f1f },
1451 { AC97_CD, 0x9f1f },
1452 { AC97_VIDEO, 0x9f1f },
1453 { AC97_AUX, 0x9f1f },
1454 { AC97_PCM, 0x9f1f },
1455 { } /* terminator */
1456};
1457
Takashi Iwaiac519022007-02-22 12:58:27 +01001458static int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
1460 unsigned short scfg;
1461
1462 // patch for Analog Devices
1463 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1464 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001465 ac97->res_table = ad1819_restbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 return 0;
1467}
1468
Takashi Iwaiee423812005-11-17 14:21:36 +01001469static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
1471 unsigned short val;
1472
1473 // test for unchained codec
1474 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1475 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1476 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1477 if ((val & 0xff40) != 0x5340)
1478 return 0;
1479 ac97->spec.ad18xx.unchained[idx] = mask;
1480 ac97->spec.ad18xx.id[idx] = val;
1481 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1482 return mask;
1483}
1484
Takashi Iwaiee423812005-11-17 14:21:36 +01001485static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
1487 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1488 unsigned short val;
1489
1490 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1491 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1492 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1493 if ((val & 0xff40) != 0x5340)
1494 return 0;
1495 if (codec_bits)
1496 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1497 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1498 ac97->spec.ad18xx.id[idx] = val;
1499 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1500 return 1;
1501}
1502
Takashi Iwaiee423812005-11-17 14:21:36 +01001503static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
1505 // already detected?
1506 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1507 cidx1 = -1;
1508 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1509 cidx2 = -1;
1510 if (cidx1 < 0 && cidx2 < 0)
1511 return;
1512 // test for chained codecs
1513 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1514 ac97->spec.ad18xx.unchained[unchained_idx]);
1515 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1516 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1517 if (cidx1 >= 0) {
Takashi Iwaic19bcdc2006-11-08 15:48:43 +01001518 if (cidx2 < 0)
1519 patch_ad1881_chained1(ac97, cidx1, 0);
1520 else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 patch_ad1881_chained1(ac97, cidx2, 0);
1522 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1523 patch_ad1881_chained1(ac97, cidx1, 0);
1524 } else if (cidx2 >= 0) {
1525 patch_ad1881_chained1(ac97, cidx2, 0);
1526 }
1527}
1528
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001529static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530#ifdef CONFIG_PM
1531 .resume = ad18xx_resume
1532#endif
1533};
1534
Takashi Iwaiac519022007-02-22 12:58:27 +01001535static int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
1537 static const char cfg_idxs[3][2] = {
1538 {2, 1},
1539 {0, 2},
1540 {0, 1}
1541 };
1542
1543 // patch for Analog Devices
1544 unsigned short codecs[3];
1545 unsigned short val;
1546 int idx, num;
1547
1548 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1549 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1550 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1551 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1552 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1553
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001554 if (! (codecs[0] || codecs[1] || codecs[2]))
1555 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 for (idx = 0; idx < 3; idx++)
1558 if (ac97->spec.ad18xx.unchained[idx])
1559 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1560
1561 if (ac97->spec.ad18xx.id[1]) {
1562 ac97->flags |= AC97_AD_MULTI;
1563 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1564 }
1565 if (ac97->spec.ad18xx.id[2]) {
1566 ac97->flags |= AC97_AD_MULTI;
1567 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1568 }
1569
1570 __end:
1571 /* select all codecs */
1572 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1573 /* check if only one codec is present */
1574 for (idx = num = 0; idx < 3; idx++)
1575 if (ac97->spec.ad18xx.id[idx])
1576 num++;
1577 if (num == 1) {
1578 /* ok, deselect all ID bits */
1579 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1580 ac97->spec.ad18xx.codec_cfg[0] =
1581 ac97->spec.ad18xx.codec_cfg[1] =
1582 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1583 }
1584 /* required for AD1886/AD1885 combination */
1585 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1586 if (ac97->spec.ad18xx.id[0]) {
1587 ac97->id &= 0xffff0000;
1588 ac97->id |= ac97->spec.ad18xx.id[0];
1589 }
1590 ac97->build_ops = &patch_ad1881_build_ops;
1591 return 0;
1592}
1593
Takashi Iwaiee423812005-11-17 14:21:36 +01001594static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1596 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1597 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1598 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1599 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1600 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1601};
1602
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001603static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001604
Takashi Iwaiee423812005-11-17 14:21:36 +01001605static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
1607 int err;
1608
1609 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1610 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001611 reset_tlv(ac97, "Headphone Playback Volume",
1612 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 return 0;
1614}
1615
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001616static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 .build_specific = &patch_ad1885_specific,
1618#ifdef CONFIG_PM
1619 .resume = ad18xx_resume
1620#endif
1621};
1622
Takashi Iwaiac519022007-02-22 12:58:27 +01001623static int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
1625 patch_ad1881(ac97);
1626 /* This is required to deal with the Intel D815EEAL2 */
1627 /* i.e. Line out is actually headphone out from codec */
1628
1629 /* set default */
1630 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1631
1632 ac97->build_ops = &patch_ad1885_build_ops;
1633 return 0;
1634}
1635
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001636static int patch_ad1886_specific(struct snd_ac97 * ac97)
1637{
1638 reset_tlv(ac97, "Headphone Playback Volume",
1639 db_scale_6bit_6db_max);
1640 return 0;
1641}
1642
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001643static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001644 .build_specific = &patch_ad1886_specific,
1645#ifdef CONFIG_PM
1646 .resume = ad18xx_resume
1647#endif
1648};
1649
Takashi Iwaiac519022007-02-22 12:58:27 +01001650static int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
1652 patch_ad1881(ac97);
1653 /* Presario700 workaround */
1654 /* for Jack Sense/SPDIF Register misetting causing */
1655 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001656 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 return 0;
1658}
1659
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001660/* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661#define AC97_AD198X_MBC 0x0003 /* mic boost */
1662#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1663#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1664#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1665#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
Randy Cushman6428ea12006-12-21 19:17:29 +01001666#define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1667#define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1668#define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1669#define AC97_AD198X_VREF_SHIFT 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1671#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1672#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1673#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
Randy Cushman6428ea12006-12-21 19:17:29 +01001674#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1675 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1677#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1678#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1679#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1680#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1681#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1682#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1683
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001684/* MISC 1 bits (AD1986 register 0x76) */
1685#define AC97_AD1986_MBC 0x0003 /* mic boost */
1686#define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1687#define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1688#define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1689#define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1690#define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1691#define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1692#define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1693#define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1694#define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1695#define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1696#define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1697#define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1698#define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1699#define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1700 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1701#define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1702#define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1703#define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1704#define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1705#define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1706#define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1707
1708/* MISC 2 bits (AD1986 register 0x70) */
1709#define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1710
1711#define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1712#define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1713#define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1714#define AC97_AD1986_CVREF_MASK \
1715 (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1716#define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1717#define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1718#define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1719#define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1720#define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1721#define AC97_AD1986_MVREF_MASK \
1722 (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1723
1724/* MISC 3 bits (AD1986 register 0x7a) */
1725#define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1726
1727#define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1728#define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1729#define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1730#define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1731#define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1732#define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1733#define AC97_AD1986_LVREF_MASK \
1734 (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1735#define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1736#define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1737#define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1738 /* input select Surround DACs */
1739#define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1740 /* select C/LFE DACs */
1741#define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1742
1743/* Serial Config bits (AD1986 register 0x74) (incomplete) */
1744#define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1745#define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1746#define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1747#define AC97_AD1986_OMS_MASK \
1748 (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1749#define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1750#define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1751#define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1752#define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1753 /* are MIC sources */
1754#define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1755 /* are MIC sources */
1756#define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1757 /* are MIC sources */
1758#define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1759 /* are MIC sources */
1760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Takashi Iwaiee423812005-11-17 14:21:36 +01001762static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001764 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001766 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767}
1768
Takashi Iwaiee423812005-11-17 14:21:36 +01001769static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770{
Takashi Iwaiee423812005-11-17 14:21:36 +01001771 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 unsigned short val;
1773
1774 val = ac97->regs[AC97_AD_SERIAL_CFG];
1775 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1776 return 0;
1777}
1778
Takashi Iwaiee423812005-11-17 14:21:36 +01001779static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Takashi Iwaiee423812005-11-17 14:21:36 +01001781 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 unsigned short val;
1783
1784 if (ucontrol->value.enumerated.item[0] > 1)
1785 return -EINVAL;
1786 val = ucontrol->value.enumerated.item[0] << 2;
1787 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1788}
1789
Takashi Iwaiee423812005-11-17 14:21:36 +01001790static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1792 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1793 .info = snd_ac97_ad198x_spdif_source_info,
1794 .get = snd_ac97_ad198x_spdif_source_get,
1795 .put = snd_ac97_ad198x_spdif_source_put,
1796};
1797
Takashi Iwaiee423812005-11-17 14:21:36 +01001798static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
1800 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1801}
1802
Takashi Iwaiee423812005-11-17 14:21:36 +01001803static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1805 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1806};
1807
Takashi Iwai128a46a2006-01-11 18:15:43 +01001808/* black list to avoid HP/Line jack-sense controls
1809 * (SS vendor << 16 | device)
1810 */
1811static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia31e8c72007-02-22 12:47:25 +01001812 0x10140523, /* Thinkpad R40 */
1813 0x10140534, /* Thinkpad X31 */
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001814 0x10140537, /* Thinkpad T41p */
Daniel T Chene1f7f022010-03-25 22:38:15 -07001815 0x1014053e, /* Thinkpad R40e */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001816 0x10140554, /* Thinkpad T42p/R50p */
Daniel T Chen8286c532007-05-15 11:46:23 +02001817 0x10140567, /* Thinkpad T43p 2668-G7U */
1818 0x10140581, /* Thinkpad X41-2527 */
Daniel T Chenaf9a75d2010-01-09 01:22:29 -05001819 0x10280160, /* Dell Dimension 2400 */
Daniel T Chen8286c532007-05-15 11:46:23 +02001820 0x104380b0, /* Asus A7V8X-MX */
1821 0x11790241, /* Toshiba Satellite A-15 S127 */
Daniel Chen5cd165e2010-03-28 13:32:34 -07001822 0x1179ff10, /* Toshiba P500 */
Daniel T Chen8286c532007-05-15 11:46:23 +02001823 0x144dc01a, /* Samsung NP-X20C004/SEG */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001824 0 /* end */
1825};
1826
1827static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1828{
1829 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1830 for (; *list; list++)
1831 if (*list == subid)
1832 return 1;
1833 return 0;
1834}
1835
Takashi Iwaiee423812005-11-17 14:21:36 +01001836static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001838 if (check_list(ac97, ad1981_jacks_blacklist))
1839 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1841 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1842}
1843
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001844static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 .build_post_spdif = patch_ad198x_post_spdif,
1846 .build_specific = patch_ad1981a_specific,
1847#ifdef CONFIG_PM
1848 .resume = ad18xx_resume
1849#endif
1850};
1851
Takashi Iwai128a46a2006-01-11 18:15:43 +01001852/* white list to enable HP jack-sense bits
1853 * (SS vendor << 16 | device)
1854 */
1855static unsigned int ad1981_jacks_whitelist[] = {
1856 0x0e11005a, /* HP nc4000/4010 */
1857 0x103c0890, /* HP nc6000 */
1858 0x103c0938, /* HP nc4220 */
1859 0x103c099c, /* HP nx6110 */
1860 0x103c0944, /* HP nc6220 */
1861 0x103c0934, /* HP nc8220 */
1862 0x103c006d, /* HP nx9105 */
Daniel T Cheneade7b22011-08-14 22:43:01 -04001863 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001864 0x17340088, /* FSC Scenic-W */
1865 0 /* end */
1866};
1867
Takashi Iwaiee423812005-11-17 14:21:36 +01001868static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001870 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 /* enable headphone jack sense */
1872 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873}
1874
Takashi Iwaiac519022007-02-22 12:58:27 +01001875static int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
1877 patch_ad1881(ac97);
1878 ac97->build_ops = &patch_ad1981a_build_ops;
1879 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1880 ac97->flags |= AC97_STEREO_MUTES;
1881 check_ad1981_hp_jack_sense(ac97);
1882 return 0;
1883}
1884
Takashi Iwaiee423812005-11-17 14:21:36 +01001885static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1887
Takashi Iwaiee423812005-11-17 14:21:36 +01001888static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
1890 int err;
1891
1892 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1893 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001894 if (check_list(ac97, ad1981_jacks_blacklist))
1895 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1897 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1898}
1899
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001900static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 .build_post_spdif = patch_ad198x_post_spdif,
1902 .build_specific = patch_ad1981b_specific,
1903#ifdef CONFIG_PM
1904 .resume = ad18xx_resume
1905#endif
1906};
1907
Takashi Iwaiac519022007-02-22 12:58:27 +01001908static int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
1910 patch_ad1881(ac97);
1911 ac97->build_ops = &patch_ad1981b_build_ops;
1912 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1913 ac97->flags |= AC97_STEREO_MUTES;
1914 check_ad1981_hp_jack_sense(ac97);
1915 return 0;
1916}
1917
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001918#define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
Takashi Iwaiee423812005-11-17 14:21:36 +01001920static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921{
Takashi Iwaiee423812005-11-17 14:21:36 +01001922 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 unsigned short val;
1924
1925 val = ac97->regs[AC97_AD_MISC];
1926 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001927 if (ac97->spec.ad18xx.lo_as_master)
1928 ucontrol->value.integer.value[0] =
1929 !ucontrol->value.integer.value[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 return 0;
1931}
1932
Takashi Iwaiee423812005-11-17 14:21:36 +01001933static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
Takashi Iwaiee423812005-11-17 14:21:36 +01001935 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 unsigned short val;
1937
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001938 val = !ucontrol->value.integer.value[0];
1939 if (ac97->spec.ad18xx.lo_as_master)
1940 val = !val;
1941 val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1943 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1944}
1945
Takashi Iwaiee423812005-11-17 14:21:36 +01001946static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001948 static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001950 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
Takashi Iwaiee423812005-11-17 14:21:36 +01001953static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
Takashi Iwaiee423812005-11-17 14:21:36 +01001955 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 unsigned short val;
1957
1958 val = ac97->regs[AC97_AD_MISC];
1959 if (!(val & AC97_AD198X_DMIX1))
1960 ucontrol->value.enumerated.item[0] = 0;
1961 else
1962 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1963 return 0;
1964}
1965
Takashi Iwaiee423812005-11-17 14:21:36 +01001966static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
Takashi Iwaiee423812005-11-17 14:21:36 +01001968 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 unsigned short val;
1970
1971 if (ucontrol->value.enumerated.item[0] > 2)
1972 return -EINVAL;
1973 if (ucontrol->value.enumerated.item[0] == 0)
1974 val = 0;
1975 else
1976 val = AC97_AD198X_DMIX1 |
1977 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1978 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1979 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1980}
1981
Takashi Iwaiee423812005-11-17 14:21:36 +01001982static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001983{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001984 unsigned short val = 0;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001985 /* clear LODIS if shared jack is to be used for Surround out */
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001986 if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001987 val |= (1 << 12);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001988 /* clear CLDIS if shared jack is to be used for C/LFE out */
1989 if (is_shared_micin(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001990 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001991 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001992 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001993}
1994
Takashi Iwaiee423812005-11-17 14:21:36 +01001995static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 {
1997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1998 .name = "Exchange Front/Surround",
1999 .info = snd_ac97_ad1888_lohpsel_info,
2000 .get = snd_ac97_ad1888_lohpsel_get,
2001 .put = snd_ac97_ad1888_lohpsel_put
2002 },
Andres Salomon0bed7b22008-11-05 17:29:53 -05002003 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
2004 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
2005 AC97_AD_HPFD_SHIFT, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
2007 {
2008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2009 .name = "Downmix",
2010 .info = snd_ac97_ad1888_downmix_info,
2011 .get = snd_ac97_ad1888_downmix_get,
2012 .put = snd_ac97_ad1888_downmix_put
2013 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002014 AC97_SURROUND_JACK_MODE_CTL,
2015 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02002016
2017 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2018 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019};
2020
Takashi Iwaiee423812005-11-17 14:21:36 +01002021static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022{
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002023 if (!ac97->spec.ad18xx.lo_as_master) {
2024 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2025 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2026 "Master Surround Playback");
2027 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
2028 "Master Playback");
2029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
2031}
2032
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002033static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 .build_post_spdif = patch_ad198x_post_spdif,
2035 .build_specific = patch_ad1888_specific,
2036#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02002037 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002039 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040};
2041
Takashi Iwaiac519022007-02-22 12:58:27 +01002042static int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
2044 unsigned short misc;
2045
2046 patch_ad1881(ac97);
2047 ac97->build_ops = &patch_ad1888_build_ops;
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002048
2049 /*
2050 * LO can be used as a real line-out on some devices,
2051 * and we need to revert the front/surround mixer switches
2052 */
2053 if (ac97->subsystem_vendor == 0x1043 &&
2054 ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
2055 ac97->spec.ad18xx.lo_as_master = 1;
2056
2057 misc = snd_ac97_read(ac97, AC97_AD_MISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 /* AD-compatible mode */
2059 /* Stereo mutes enabled */
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002060 misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
2061 if (!ac97->spec.ad18xx.lo_as_master)
2062 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2063 /* it seems that most vendors connect line-out connector to
2064 * headphone out of AC'97
2065 */
2066 misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
2067
2068 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 ac97->flags |= AC97_STEREO_MUTES;
2070 return 0;
2071}
2072
Takashi Iwaiee423812005-11-17 14:21:36 +01002073static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
2075 int err;
2076
2077 if ((err = patch_ad1888_specific(ac97)) < 0)
2078 return err;
2079 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2080}
2081
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002082static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 .build_post_spdif = patch_ad198x_post_spdif,
2084 .build_specific = patch_ad1980_specific,
2085#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002086 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02002088 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089};
2090
Takashi Iwaiac519022007-02-22 12:58:27 +01002091static int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
2093 patch_ad1888(ac97);
2094 ac97->build_ops = &patch_ad1980_build_ops;
2095 return 0;
2096}
2097
Randy Cushman6428ea12006-12-21 19:17:29 +01002098static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_info *uinfo)
2100{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002101 static const char * const texts[4] = {
2102 "High-Z", "3.7 V", "2.25 V", "0 V"
2103 };
Randy Cushman6428ea12006-12-21 19:17:29 +01002104
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002105 return snd_ctl_enum_info(uinfo, 1, 4, texts);
Randy Cushman6428ea12006-12-21 19:17:29 +01002106}
2107
2108static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
2109 struct snd_ctl_elem_value *ucontrol)
2110{
2111 static const int reg2ctrl[4] = {2, 0, 1, 3};
2112 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2113 unsigned short val;
2114 val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
2115 >> AC97_AD198X_VREF_SHIFT;
2116 ucontrol->value.enumerated.item[0] = reg2ctrl[val];
2117 return 0;
2118}
2119
2120static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
2121 struct snd_ctl_elem_value *ucontrol)
2122{
2123 static const int ctrl2reg[4] = {1, 2, 0, 3};
2124 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2125 unsigned short val;
2126
Takashi Iwai4e98d6a2007-11-15 15:58:13 +01002127 if (ucontrol->value.enumerated.item[0] > 3)
Randy Cushman6428ea12006-12-21 19:17:29 +01002128 return -EINVAL;
2129 val = ctrl2reg[ucontrol->value.enumerated.item[0]]
2130 << AC97_AD198X_VREF_SHIFT;
2131 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
2132 AC97_AD198X_VREF_MASK, val);
2133}
2134
Takashi Iwaiee423812005-11-17 14:21:36 +01002135static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Randy Cushman6428ea12006-12-21 19:17:29 +01002136 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2137 {
2138 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2139 .name = "Exchange Front/Surround",
2140 .info = snd_ac97_ad1888_lohpsel_info,
2141 .get = snd_ac97_ad1888_lohpsel_get,
2142 .put = snd_ac97_ad1888_lohpsel_put
2143 },
2144 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
2145 AC97_SINGLE("Spread Front to Surround and Center/LFE",
2146 AC97_AD_MISC, 7, 1, 0),
2147 {
2148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2149 .name = "Downmix",
2150 .info = snd_ac97_ad1888_downmix_info,
2151 .get = snd_ac97_ad1888_downmix_get,
2152 .put = snd_ac97_ad1888_downmix_put
2153 },
2154 {
2155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2156 .name = "V_REFOUT",
2157 .info = snd_ac97_ad1985_vrefout_info,
2158 .get = snd_ac97_ad1985_vrefout_get,
2159 .put = snd_ac97_ad1985_vrefout_put
2160 },
2161 AC97_SURROUND_JACK_MODE_CTL,
2162 AC97_CHANNEL_MODE_CTL,
2163
2164 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2165 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166};
2167
Takashi Iwaiee423812005-11-17 14:21:36 +01002168static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002169{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002170 ad1888_update_jacks(ac97);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002171 /* clear OMS if shared jack is to be used for C/LFE out */
Takashi Iwaifc232c62005-05-27 10:42:45 +02002172 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002173 is_shared_micin(ac97) ? 1 << 9 : 0);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002174}
2175
Takashi Iwaiee423812005-11-17 14:21:36 +01002176static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
2178 int err;
2179
Randy Cushman6428ea12006-12-21 19:17:29 +01002180 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2181 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2182 "Master Surround Playback");
2183 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2184
2185 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 return err;
Randy Cushman6428ea12006-12-21 19:17:29 +01002187
2188 return patch_build_controls(ac97, snd_ac97_ad1985_controls,
2189 ARRAY_SIZE(snd_ac97_ad1985_controls));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002192static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 .build_post_spdif = patch_ad198x_post_spdif,
2194 .build_specific = patch_ad1985_specific,
2195#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002196 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002198 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199};
2200
Takashi Iwaiac519022007-02-22 12:58:27 +01002201static int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
2203 unsigned short misc;
2204
2205 patch_ad1881(ac97);
2206 ac97->build_ops = &patch_ad1985_build_ops;
2207 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2208 /* switch front/surround line-out/hp-out */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /* AD-compatible mode */
2210 /* Stereo mutes enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 AC97_AD198X_LOSEL |
2213 AC97_AD198X_HPSEL |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 AC97_AD198X_MSPLT |
2215 AC97_AD198X_AC97NC);
2216 ac97->flags |= AC97_STEREO_MUTES;
Randy Cushman6428ea12006-12-21 19:17:29 +01002217
2218 /* update current jack configuration */
2219 ad1985_update_jacks(ac97);
2220
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2222 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2223 return 0;
2224}
2225
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002226#define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002227
2228static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
2229 struct snd_ctl_elem_value *ucontrol)
2230{
2231 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2232 unsigned short val;
2233
2234 val = ac97->regs[AC97_AD_MISC3];
2235 ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
2236 return 0;
2237}
2238
2239static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
2240 struct snd_ctl_elem_value *ucontrol)
2241{
2242 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2243 int ret0;
2244 int ret1;
2245 int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
2246
2247 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
2248 ucontrol->value.integer.value[0] != 0
2249 ? AC97_AD1986_LOSEL : 0);
2250 if (ret0 < 0)
2251 return ret0;
2252
2253 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2254 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2255 (ucontrol->value.integer.value[0] != 0
2256 || sprd)
2257 ? AC97_AD1986_SOSEL : 0);
2258 if (ret1 < 0)
2259 return ret1;
2260
2261 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2262}
2263
2264static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
2265 struct snd_ctl_elem_value *ucontrol)
2266{
2267 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2268 unsigned short val;
2269
2270 val = ac97->regs[AC97_AD_MISC];
2271 ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
2272 return 0;
2273}
2274
2275static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
2276 struct snd_ctl_elem_value *ucontrol)
2277{
2278 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2279 int ret0;
2280 int ret1;
2281 int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
2282
2283 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
2284 ucontrol->value.integer.value[0] != 0
2285 ? AC97_AD1986_SPRD : 0);
2286 if (ret0 < 0)
2287 return ret0;
2288
2289 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2290 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2291 (ucontrol->value.integer.value[0] != 0
2292 || sprd)
2293 ? AC97_AD1986_SOSEL : 0);
2294 if (ret1 < 0)
2295 return ret1;
2296
2297 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2298}
2299
2300static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_value *ucontrol)
2302{
2303 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2304
2305 ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
2306 return 0;
2307}
2308
2309static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
2310 struct snd_ctl_elem_value *ucontrol)
2311{
2312 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2313 unsigned char swap = ucontrol->value.integer.value[0] != 0;
2314
2315 if (swap != ac97->spec.ad18xx.swap_mic_linein) {
2316 ac97->spec.ad18xx.swap_mic_linein = swap;
2317 if (ac97->build_ops->update_jacks)
2318 ac97->build_ops->update_jacks(ac97);
2319 return 1;
2320 }
2321 return 0;
2322}
2323
2324static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
2325 struct snd_ctl_elem_value *ucontrol)
2326{
2327 /* Use MIC_1/2 V_REFOUT as the "get" value */
2328 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2329 unsigned short val;
2330 unsigned short reg = ac97->regs[AC97_AD_MISC2];
2331 if ((reg & AC97_AD1986_MVREF0) != 0)
2332 val = 2;
2333 else if ((reg & AC97_AD1986_MVREF1) != 0)
2334 val = 3;
2335 else if ((reg & AC97_AD1986_MVREF2) != 0)
2336 val = 1;
2337 else
2338 val = 0;
2339 ucontrol->value.enumerated.item[0] = val;
2340 return 0;
2341}
2342
2343static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
2344 struct snd_ctl_elem_value *ucontrol)
2345{
2346 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2347 unsigned short cval;
2348 unsigned short lval;
2349 unsigned short mval;
2350 int cret;
2351 int lret;
2352 int mret;
2353
2354 switch (ucontrol->value.enumerated.item[0])
2355 {
2356 case 0: /* High-Z */
2357 cval = 0;
2358 lval = 0;
2359 mval = 0;
2360 break;
2361 case 1: /* 3.7 V */
2362 cval = AC97_AD1986_CVREF2;
2363 lval = AC97_AD1986_LVREF2;
2364 mval = AC97_AD1986_MVREF2;
2365 break;
2366 case 2: /* 2.25 V */
2367 cval = AC97_AD1986_CVREF0;
2368 lval = AC97_AD1986_LVREF0;
2369 mval = AC97_AD1986_MVREF0;
2370 break;
2371 case 3: /* 0 V */
2372 cval = AC97_AD1986_CVREF1;
2373 lval = AC97_AD1986_LVREF1;
2374 mval = AC97_AD1986_MVREF1;
2375 break;
2376 default:
2377 return -EINVAL;
2378 }
2379
2380 cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2381 AC97_AD1986_CVREF_MASK, cval);
2382 if (cret < 0)
2383 return cret;
2384 lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
2385 AC97_AD1986_LVREF_MASK, lval);
2386 if (lret < 0)
2387 return lret;
2388 mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2389 AC97_AD1986_MVREF_MASK, mval);
2390 if (mret < 0)
2391 return mret;
2392
2393 return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
2394}
2395
2396static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
2397 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2398 {
2399 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2400 .name = "Exchange Front/Surround",
2401 .info = snd_ac97_ad1986_bool_info,
2402 .get = snd_ac97_ad1986_lososel_get,
2403 .put = snd_ac97_ad1986_lososel_put
2404 },
2405 {
2406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2407 .name = "Exchange Mic/Line In",
2408 .info = snd_ac97_ad1986_bool_info,
2409 .get = snd_ac97_ad1986_miclisel_get,
2410 .put = snd_ac97_ad1986_miclisel_put
2411 },
2412 {
2413 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2414 .name = "Spread Front to Surround and Center/LFE",
2415 .info = snd_ac97_ad1986_bool_info,
2416 .get = snd_ac97_ad1986_spread_get,
2417 .put = snd_ac97_ad1986_spread_put
2418 },
2419 {
2420 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2421 .name = "Downmix",
2422 .info = snd_ac97_ad1888_downmix_info,
2423 .get = snd_ac97_ad1888_downmix_get,
2424 .put = snd_ac97_ad1888_downmix_put
2425 },
2426 {
2427 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2428 .name = "V_REFOUT",
2429 .info = snd_ac97_ad1985_vrefout_info,
2430 .get = snd_ac97_ad1986_vrefout_get,
2431 .put = snd_ac97_ad1986_vrefout_put
2432 },
2433 AC97_SURROUND_JACK_MODE_CTL,
2434 AC97_CHANNEL_MODE_CTL,
2435
2436 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2437 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
2438};
2439
2440static void ad1986_update_jacks(struct snd_ac97 *ac97)
2441{
2442 unsigned short misc_val = 0;
2443 unsigned short ser_val;
2444
2445 /* disable SURROUND and CENTER/LFE if not surround mode */
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002446 if (!is_surround_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002447 misc_val |= AC97_AD1986_SODIS;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002448 if (!is_clfe_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002449 misc_val |= AC97_AD1986_CLDIS;
2450
2451 /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2452 if (is_shared_linein(ac97))
2453 misc_val |= AC97_AD1986_LISEL_SURR;
2454 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2455 misc_val |= AC97_AD1986_LISEL_MIC;
2456 snd_ac97_update_bits(ac97, AC97_AD_MISC,
2457 AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
2458 AC97_AD1986_LISEL_MASK,
2459 misc_val);
2460
2461 /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2462 if (is_shared_micin(ac97))
2463 ser_val = AC97_AD1986_OMS_C;
2464 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2465 ser_val = AC97_AD1986_OMS_L;
2466 else
2467 ser_val = AC97_AD1986_OMS_M;
2468 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
2469 AC97_AD1986_OMS_MASK,
2470 ser_val);
2471}
2472
2473static int patch_ad1986_specific(struct snd_ac97 *ac97)
2474{
2475 int err;
2476
2477 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2478 return err;
2479
2480 return patch_build_controls(ac97, snd_ac97_ad1986_controls,
2481 ARRAY_SIZE(snd_ac97_ad1985_controls));
2482}
2483
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002484static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002485 .build_post_spdif = patch_ad198x_post_spdif,
2486 .build_specific = patch_ad1986_specific,
2487#ifdef CONFIG_PM
2488 .resume = ad18xx_resume,
2489#endif
2490 .update_jacks = ad1986_update_jacks,
2491};
2492
Takashi Iwaiac519022007-02-22 12:58:27 +01002493static int patch_ad1986(struct snd_ac97 * ac97)
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002494{
2495 patch_ad1881(ac97);
2496 ac97->build_ops = &patch_ad1986_build_ops;
2497 ac97->flags |= AC97_STEREO_MUTES;
2498
2499 /* update current jack configuration */
2500 ad1986_update_jacks(ac97);
2501
2502 return 0;
2503}
2504
Takashi Iwai8f4f4ef2008-08-05 15:45:45 +02002505/*
2506 * realtek ALC203: use mono-out for pin 37
2507 */
2508static int patch_alc203(struct snd_ac97 *ac97)
2509{
2510 snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
2511 return 0;
2512}
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514/*
2515 * realtek ALC65x/850 codecs
2516 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002517static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002519 int shared;
2520
Randy Cushman831466f2006-12-19 18:42:16 +01002521 /* shared Line-In / Surround Out */
2522 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002523 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2524 shared ? (1 << 9) : 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002525 /* update shared Mic In / Center/LFE Out */
2526 shared = is_shared_clfeout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002527 /* disable/enable vref */
2528 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2529 shared ? (1 << 12) : 0);
2530 /* turn on/off center-on-mic */
2531 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2532 shared ? (1 << 10) : 0);
2533 /* GPIO0 high for mic */
2534 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2535 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
Takashi Iwai833a4932012-08-03 17:59:36 +02002538static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol,
2539 struct snd_ctl_elem_value *ucontrol)
2540{
2541 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2542 struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK];
2543
2544 if (map) {
2545 if (ucontrol->value.integer.value[0])
2546 map->chmap = snd_pcm_std_chmaps;
2547 else
2548 map->chmap = snd_pcm_alt_chmaps;
2549 }
2550 return snd_ac97_put_volsw(kcontrol, ucontrol);
2551}
2552
Takashi Iwaiee423812005-11-17 14:21:36 +01002553static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2555 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2556 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2557 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2558 /* 4: Analog Input To Surround */
2559 /* 5: Analog Input To Center/LFE */
2560 /* 6: Independent Master Volume Right */
2561 /* 7: Independent Master Volume Left */
2562 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002563 /* 9: Line-In/Surround share */
2564 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 /* 11-13: in IEC958 controls */
Takashi Iwai833a4932012-08-03 17:59:36 +02002566 {
2567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2568 .name = "Swap Surround Slot",
2569 .info = snd_ac97_info_volsw,
2570 .get = snd_ac97_get_volsw,
2571 .put = alc650_swap_surround_put,
2572 .private_value = AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0),
2573 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574#if 0 /* always set in patch_alc650 */
2575 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2576 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2577 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2578 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2579 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2580 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2581#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002582 AC97_SURROUND_JACK_MODE_CTL,
2583 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584};
2585
Takashi Iwaiee423812005-11-17 14:21:36 +01002586static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002587 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2589 /* disable this controls since it doesn't work as expected */
2590 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2591};
2592
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01002593static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002594
Takashi Iwaiee423812005-11-17 14:21:36 +01002595static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
2597 int err;
2598
2599 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2600 return err;
2601 if (ac97->ext_id & AC97_EI_SPDIF) {
2602 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2603 return err;
2604 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002605 if (ac97->id != AC97_ID_ALC650F)
2606 reset_tlv(ac97, "Master Playback Volume",
2607 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return 0;
2609}
2610
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002611static const struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002612 .build_specific = patch_alc650_specific,
2613 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614};
2615
Takashi Iwaiac519022007-02-22 12:58:27 +01002616static int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
2618 unsigned short val;
2619
2620 ac97->build_ops = &patch_alc650_ops;
2621
2622 /* determine the revision */
2623 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2624 if (val < 3)
2625 ac97->id = 0x414c4720; /* Old version */
2626 else if (val < 0x10)
2627 ac97->id = 0x414c4721; /* D version */
2628 else if (val < 0x20)
2629 ac97->id = 0x414c4722; /* E version */
2630 else if (val < 0x30)
2631 ac97->id = 0x414c4723; /* F version */
2632
2633 /* revision E or F */
2634 /* FIXME: what about revision D ? */
2635 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2636 ac97->id == 0x414c4723);
2637
2638 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2639 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2640 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2641
2642 /* Enable SPDIF-IN only on Rev.E and above */
2643 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2644 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002645 if (ac97->spec.dev_flags &&
2646 /* ASUS A6KM requires EAPD */
2647 ! (ac97->subsystem_vendor == 0x1043 &&
2648 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 val |= 0x03; /* enable */
2650 else
2651 val &= ~0x03; /* disable */
2652 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2653
2654 /* set default: slot 3,4,7,8,6,9
2655 spdif-in monitor off, analog-spdif off, spdif-in off
2656 center on mic off, surround on line-in off
2657 downmix off, duplicate front off
2658 */
2659 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2660
2661 /* set GPIO0 for mic bias */
2662 /* GPIO0 pin output, no interrupt, high */
2663 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2664 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2665 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2666 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2667
2668 /* full DAC volume */
2669 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2670 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2671 return 0;
2672}
2673
Takashi Iwaiee423812005-11-17 14:21:36 +01002674static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002676 int shared;
2677
Randy Cushman831466f2006-12-19 18:42:16 +01002678 /* shared Line-In / Surround Out */
2679 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002680 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2681 shared ? (1 << 9) : 0, 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002682 /* update shared Mic In / Center/LFE Out */
2683 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 /* misc control; vrefout disable */
2685 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002686 shared ? (1 << 12) : 0);
2687 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2688 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
Takashi Iwaiee423812005-11-17 14:21:36 +01002691static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002693 AC97_SURROUND_JACK_MODE_CTL,
2694 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695};
2696
Takashi Iwaiee423812005-11-17 14:21:36 +01002697static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002699 static const char * const texts_655[3] = {
2700 "PCM", "Analog In", "IEC958 In"
2701 };
2702 static const char * const texts_658[4] = {
2703 "PCM", "Analog1 In", "Analog2 In", "IEC958 In"
2704 };
Takashi Iwaiee423812005-11-17 14:21:36 +01002705 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002707 if (ac97->spec.dev_flags)
2708 return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
2709 else
2710 return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711}
2712
Takashi Iwaiee423812005-11-17 14:21:36 +01002713static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714{
Takashi Iwaiee423812005-11-17 14:21:36 +01002715 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 unsigned short val;
2717
2718 val = ac97->regs[AC97_ALC650_MULTICH];
2719 val = (val >> 12) & 3;
2720 if (ac97->spec.dev_flags && val == 3)
2721 val = 0;
2722 ucontrol->value.enumerated.item[0] = val;
2723 return 0;
2724}
2725
Takashi Iwaiee423812005-11-17 14:21:36 +01002726static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727{
Takashi Iwaiee423812005-11-17 14:21:36 +01002728 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2731 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2732 0);
2733}
2734
Takashi Iwaiee423812005-11-17 14:21:36 +01002735static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002736 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 /* disable this controls since it doesn't work as expected */
2738 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2739 {
2740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002741 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 .info = alc655_iec958_route_info,
2743 .get = alc655_iec958_route_get,
2744 .put = alc655_iec958_route_put,
2745 },
2746};
2747
Takashi Iwaiee423812005-11-17 14:21:36 +01002748static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749{
2750 int err;
2751
2752 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2753 return err;
2754 if (ac97->ext_id & AC97_EI_SPDIF) {
2755 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2756 return err;
2757 }
2758 return 0;
2759}
2760
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002761static const struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002762 .build_specific = patch_alc655_specific,
2763 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764};
2765
Takashi Iwaiac519022007-02-22 12:58:27 +01002766static int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
2768 unsigned int val;
2769
Takashi Iwaia5022b02005-09-02 14:03:05 +02002770 if (ac97->id == AC97_ID_ALC658) {
2771 ac97->spec.dev_flags = 1; /* ALC658 */
2772 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2773 ac97->id = AC97_ID_ALC658D;
2774 ac97->spec.dev_flags = 2;
2775 }
2776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
2778 ac97->build_ops = &patch_alc655_ops;
2779
2780 /* assume only page 0 for writing cache */
2781 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2782
2783 /* adjust default values */
2784 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002785 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002787 else { /* ALC655 */
2788 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002789 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
Jaroslav Kyselae7d24f02006-10-05 09:30:36 +02002790 ac97->subsystem_device == 0x0161 || /* LG K1 Express */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002791 ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
Takashi Iwai592a82e2007-03-12 11:33:32 +01002792 ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002793 ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002794 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2795 else
2796 val |= (1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaic872e8c2008-08-12 13:39:01 +02002797 /* this seems missing on some hardwares */
2798 ac97->ext_id |= AC97_EI_SPDIF;
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 val &= ~(1 << 12); /* vref enable */
2801 snd_ac97_write_cache(ac97, 0x7a, val);
2802 /* set default: spdif-in enabled,
2803 spdif-in monitor off, spdif-in PCM off
2804 center on mic off, surround on line-in off
2805 duplicate front off
2806 */
2807 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2808
2809 /* full DAC volume */
2810 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2811 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002812
2813 /* update undocumented bit... */
2814 if (ac97->id == AC97_ID_ALC658D)
2815 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2816
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 return 0;
2818}
2819
2820
2821#define AC97_ALC850_JACK_SELECT 0x76
2822#define AC97_ALC850_MISC1 0x7a
Takashi Iwai4235a312008-02-18 12:23:13 +01002823#define AC97_ALC850_MULTICH 0x6a
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
Takashi Iwaiee423812005-11-17 14:21:36 +01002825static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002827 int shared;
Takashi Iwai4235a312008-02-18 12:23:13 +01002828 int aux_is_back_surround;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002829
Randy Cushman831466f2006-12-19 18:42:16 +01002830 /* shared Line-In / Surround Out */
2831 shared = is_shared_surrout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 /* SURR 1kOhm (bit4), Amp (bit5) */
2833 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002834 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002836 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2837 shared ? (2<<12) : (0<<12));
Randy Cushman831466f2006-12-19 18:42:16 +01002838 /* update shared Mic In / Center/LFE Out */
2839 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 /* Vref disable (bit12), 1kOhm (bit13) */
2841 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002842 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002843 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002844 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002845 shared ? (5<<4) : (1<<4));
Takashi Iwai4235a312008-02-18 12:23:13 +01002846
2847 aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2848 /* Aux is Back Surround */
2849 snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2850 aux_is_back_surround ? (1<<10) : (0<<10));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851}
2852
Takashi Iwaiee423812005-11-17 14:21:36 +01002853static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002855 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002856 AC97_SURROUND_JACK_MODE_CTL,
Takashi Iwai4235a312008-02-18 12:23:13 +01002857 AC97_CHANNEL_MODE_8CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858};
2859
Takashi Iwaiee423812005-11-17 14:21:36 +01002860static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861{
2862 int err;
2863
2864 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2865 return err;
2866 if (ac97->ext_id & AC97_EI_SPDIF) {
2867 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2868 return err;
2869 }
2870 return 0;
2871}
2872
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002873static const struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002874 .build_specific = patch_alc850_specific,
2875 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876};
2877
Takashi Iwaiac519022007-02-22 12:58:27 +01002878static int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879{
2880 ac97->build_ops = &patch_alc850_ops;
2881
2882 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
Takashi Iwai4235a312008-02-18 12:23:13 +01002883 ac97->flags |= AC97_HAS_8CH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
2885 /* assume only page 0 for writing cache */
2886 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2887
2888 /* adjust default values */
2889 /* set default: spdif-in enabled,
2890 spdif-in monitor off, spdif-in PCM off
2891 center on mic off, surround on line-in off
2892 duplicate front off
Takashi Iwai4235a312008-02-18 12:23:13 +01002893 NB default bit 10=0 = Aux is Capture, not Back Surround
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 */
2895 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2896 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2897 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2898 */
2899 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2900 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2901 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2902 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2903 */
2904 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2905 (1<<11)|(0<<12)|(1<<15));
2906
2907 /* full DAC volume */
2908 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2909 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2910 return 0;
2911}
2912
Andreas Mohr6ba92562011-02-19 00:49:48 +01002913static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97)
2914{
2915 struct snd_kcontrol *kctl_3d_center =
2916 snd_ac97_find_mixer_ctl(ac97, "3D Control - Center");
2917 struct snd_kcontrol *kctl_3d_depth =
2918 snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth");
2919
2920 /*
2921 * 3D register is different from AC97 standard layout
2922 * (also do some renaming, to resemble Windows driver naming)
2923 */
2924 if (kctl_3d_center) {
2925 kctl_3d_center->private_value =
2926 AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0);
2927 snd_ac97_rename_vol_ctl(ac97,
2928 "3D Control - Center", "3D Control - Width"
2929 );
2930 }
2931 if (kctl_3d_depth)
2932 kctl_3d_depth->private_value =
2933 AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0);
2934
2935 /* Aztech Windows driver calls the
2936 equivalent control "Modem Playback", thus rename it: */
2937 snd_ac97_rename_vol_ctl(ac97,
2938 "Master Mono Playback", "Modem Playback"
2939 );
2940 snd_ac97_rename_vol_ctl(ac97,
2941 "Headphone Playback", "FM Synth Playback"
2942 );
2943
2944 return 0;
2945}
2946
2947static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = {
2948 .build_specific = patch_aztech_azf3328_specific
2949};
2950
2951static int patch_aztech_azf3328(struct snd_ac97 *ac97)
2952{
2953 ac97->build_ops = &patch_aztech_azf3328_ops;
2954 return 0;
2955}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
2957/*
2958 * C-Media CM97xx codecs
2959 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002960static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002961{
Randy Cushman831466f2006-12-19 18:42:16 +01002962 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002963 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002964 is_shared_surrout(ac97) ? (1 << 10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002965}
2966
Takashi Iwaiee423812005-11-17 14:21:36 +01002967static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002969 AC97_SURROUND_JACK_MODE_CTL,
2970 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971};
2972
Takashi Iwaiee423812005-11-17 14:21:36 +01002973static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2976}
2977
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002978static const struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002979 .build_specific = patch_cm9738_specific,
2980 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981};
2982
Takashi Iwaiac519022007-02-22 12:58:27 +01002983static int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984{
2985 ac97->build_ops = &patch_cm9738_ops;
2986 /* FIXME: can anyone confirm below? */
2987 /* CM9738 has no PCM volume although the register reacts */
2988 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2989 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2990
2991 return 0;
2992}
2993
Takashi Iwaiee423812005-11-17 14:21:36 +01002994static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002996 static const char * const texts[] = { "Analog", "Digital" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002998 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999}
3000
Takashi Iwaiee423812005-11-17 14:21:36 +01003001static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002{
Takashi Iwaiee423812005-11-17 14:21:36 +01003003 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 unsigned short val;
3005
3006 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
3007 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
3008 return 0;
3009}
3010
Takashi Iwaiee423812005-11-17 14:21:36 +01003011static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012{
Takashi Iwaiee423812005-11-17 14:21:36 +01003013 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
3015 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
3016 0x01 << 1,
3017 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
3018}
3019
Takashi Iwaiee423812005-11-17 14:21:36 +01003020static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 /* BIT 0: SPDI_EN - always true */
3022 { /* BIT 1: SPDIFS */
3023 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3024 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3025 .info = snd_ac97_cmedia_spdif_playback_source_info,
3026 .get = snd_ac97_cmedia_spdif_playback_source_get,
3027 .put = snd_ac97_cmedia_spdif_playback_source_put,
3028 },
3029 /* BIT 2: IG_SPIV */
3030 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
3031 /* BIT 3: SPI2F */
3032 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
3033 /* BIT 4: SPI2SDI */
3034 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
3035 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
3036};
3037
Takashi Iwaiee423812005-11-17 14:21:36 +01003038static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039{
Randy Cushman831466f2006-12-19 18:42:16 +01003040 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003041 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01003042 is_shared_surrout(ac97) ? (1 << 10) : 0);
3043 /* shared Mic In / Center/LFE Out **/
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003044 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
Randy Cushman831466f2006-12-19 18:42:16 +01003045 is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046}
3047
Takashi Iwaiee423812005-11-17 14:21:36 +01003048static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003049 AC97_SURROUND_JACK_MODE_CTL,
3050 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051};
3052
Takashi Iwaiee423812005-11-17 14:21:36 +01003053static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054{
3055 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
3056}
3057
Takashi Iwaiee423812005-11-17 14:21:36 +01003058static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059{
3060 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
3061}
3062
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003063static const struct snd_ac97_build_ops patch_cm9739_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003065 .build_post_spdif = patch_cm9739_post_spdif,
3066 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067};
3068
Takashi Iwaiac519022007-02-22 12:58:27 +01003069static int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070{
3071 unsigned short val;
3072
3073 ac97->build_ops = &patch_cm9739_ops;
3074
3075 /* CM9739/A has no Master and PCM volume although the register reacts */
3076 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
3077 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
3078 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
3079
3080 /* check spdif */
3081 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
3082 if (val & AC97_EA_SPCV) {
3083 /* enable spdif in */
3084 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3085 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
3086 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3087 } else {
3088 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
3089 ac97->rates[AC97_RATES_SPDIF] = 0;
3090 }
3091
3092 /* set-up multi channel */
3093 /* bit 14: 0 = SPDIF, 1 = EAPD */
3094 /* bit 13: enable internal vref output for mic */
3095 /* bit 12: disable center/lfe (swithable) */
3096 /* bit 10: disable surround/line (switchable) */
3097 /* bit 9: mix 2 surround off */
3098 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
3099 /* bit 3: undocumented; surround? */
3100 /* bit 0: dB */
3101 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
3102 val |= (1 << 3);
3103 val |= (1 << 13);
3104 if (! (ac97->ext_id & AC97_EI_SPDIF))
3105 val |= (1 << 14);
3106 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
3107
3108 /* FIXME: set up GPIO */
3109 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3110 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3111 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3112 if (ac97->pci &&
3113 ac97->subsystem_vendor == 0x1043 &&
3114 ac97->subsystem_device == 0x1843) {
3115 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3116 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
3117 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
3118 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
3119 }
3120
3121 return 0;
3122}
3123
3124#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003125#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126#define AC97_CM9761_SPDIF_CTRL 0x6c
3127
Takashi Iwaiee423812005-11-17 14:21:36 +01003128static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003130 /* FIXME: check the bits for each model
3131 * model 83 is confirmed to work
3132 */
3133 static unsigned short surr_on[3][2] = {
3134 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3135 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3136 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003138 static unsigned short clfe_on[3][2] = {
3139 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3140 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3141 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003143 static unsigned short surr_shared[3][2] = {
3144 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3145 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3146 { 0x0000, 0x0400 }, /* 9761-83 */
3147 };
3148 static unsigned short clfe_shared[3][2] = {
3149 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3150 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3151 { 0x2000, 0x0800 }, /* 9761-83 */
3152 };
3153 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003154
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003155 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
3156 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
Randy Cushman831466f2006-12-19 18:42:16 +01003157 val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3158 val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003159
3160 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
Takashi Iwaiee423812005-11-17 14:21:36 +01003163static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003164 AC97_SURROUND_JACK_MODE_CTL,
3165 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166};
3167
Takashi Iwaiee423812005-11-17 14:21:36 +01003168static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003169{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003170 static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003171
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003172 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003173}
3174
Takashi Iwaiee423812005-11-17 14:21:36 +01003175static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003176{
Takashi Iwaiee423812005-11-17 14:21:36 +01003177 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003178
3179 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
3180 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
3181 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
3182 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
3183 else
3184 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
3185 return 0;
3186}
3187
Takashi Iwaiee423812005-11-17 14:21:36 +01003188static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003189{
Takashi Iwaiee423812005-11-17 14:21:36 +01003190 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003191
3192 if (ucontrol->value.enumerated.item[0] == 2)
3193 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
3194 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
3195 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
3196 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3197}
3198
3199static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
3200static const struct ac97_enum cm9761_dac_clock_enum =
3201 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3202
Takashi Iwaiee423812005-11-17 14:21:36 +01003203static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003204 { /* BIT 1: SPDIFS */
3205 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3206 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3207 .info = cm9761_spdif_out_source_info,
3208 .get = cm9761_spdif_out_source_get,
3209 .put = cm9761_spdif_out_source_put,
3210 },
3211 /* BIT 2: IG_SPIV */
3212 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
3213 /* BIT 3: SPI2F */
3214 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
3215 /* BIT 4: SPI2SDI */
3216 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
3217 /* BIT 9-10: DAC_CTL */
3218 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
3219};
3220
Takashi Iwaiee423812005-11-17 14:21:36 +01003221static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003222{
3223 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
3224}
3225
Takashi Iwaiee423812005-11-17 14:21:36 +01003226static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227{
3228 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
3229}
3230
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003231static const struct snd_ac97_build_ops patch_cm9761_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003233 .build_post_spdif = patch_cm9761_post_spdif,
3234 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235};
3236
Takashi Iwaiac519022007-02-22 12:58:27 +01003237static int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238{
3239 unsigned short val;
3240
3241 /* CM9761 has no PCM volume although the register reacts */
3242 /* Master volume seems to have _some_ influence on the analog
3243 * input sounds
3244 */
3245 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
3246 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
3247 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
3248
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003249 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 if (ac97->id == AC97_ID_CM9761_82) {
3251 unsigned short tmp;
3252 /* check page 1, reg 0x60 */
3253 val = snd_ac97_read(ac97, AC97_INT_PAGING);
3254 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
3255 tmp = snd_ac97_read(ac97, 0x60);
3256 ac97->spec.dev_flags = tmp & 1; /* revision B? */
3257 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003258 } else if (ac97->id == AC97_ID_CM9761_83)
3259 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
3261 ac97->build_ops = &patch_cm9761_ops;
3262
3263 /* enable spdif */
3264 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3265 ac97->ext_id |= AC97_EI_SPDIF;
3266 /* to be sure: we overwrite the ext status bits */
3267 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
3268 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003269 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3271
3272 /* set-up multi channel */
3273 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003274 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003276 * bit 12: CLFE control (reverted on rev B)
3277 * bit 11: Mic/center share (reverted on rev B)
3278 * bit 10: suddound/line share
3279 * bit 9: Analog-in mix -> surround
3280 * bit 8: Analog-in mix -> CLFE
3281 * bit 7: Mic/LFE share (mic/center/lfe)
3282 * bit 5: vref select (9761A)
3283 * bit 4: front control
3284 * bit 3: surround control (revereted with rev B)
3285 * bit 2: front mic
3286 * bit 1: stereo mic
3287 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 */
3289
3290#if 0
3291 if (ac97->spec.dev_flags)
3292 val = 0x0214;
3293 else
3294 val = 0x321c;
3295#endif
3296 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
3297 val |= (1 << 4); /* front on */
3298 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
3299
3300 /* FIXME: set up GPIO */
3301 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3302 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3303
3304 return 0;
3305}
3306
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003307#define AC97_CM9780_SIDE 0x60
3308#define AC97_CM9780_JACK 0x62
3309#define AC97_CM9780_MIXER 0x64
3310#define AC97_CM9780_MULTI_CHAN 0x66
3311#define AC97_CM9780_SPDIF 0x6c
3312
3313static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
3314static const struct ac97_enum cm9780_ch_select_enum =
3315 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01003316static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003317 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
3318 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
3319 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
3320};
3321
Takashi Iwaiee423812005-11-17 14:21:36 +01003322static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003323{
3324 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
3325}
3326
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003327static const struct snd_ac97_build_ops patch_cm9780_ops = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003328 .build_specific = patch_cm9780_specific,
3329 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
3330};
3331
Takashi Iwaiac519022007-02-22 12:58:27 +01003332static int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003333{
3334 unsigned short val;
3335
3336 ac97->build_ops = &patch_cm9780_ops;
3337
3338 /* enable spdif */
3339 if (ac97->ext_id & AC97_EI_SPDIF) {
3340 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3341 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
3342 val |= 0x1; /* SPDI_EN */
3343 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
3344 }
3345
3346 return 0;
3347}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349/*
3350 * VIA VT1616 codec
3351 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003352static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3354AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3355AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3356AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3357};
3358
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003359static const char *slave_vols_vt1616[] = {
3360 "Front Playback Volume",
3361 "Surround Playback Volume",
3362 "Center Playback Volume",
3363 "LFE Playback Volume",
3364 NULL
3365};
3366
3367static const char *slave_sws_vt1616[] = {
3368 "Front Playback Switch",
3369 "Surround Playback Switch",
3370 "Center Playback Switch",
3371 "LFE Playback Switch",
3372 NULL
3373};
3374
3375/* find a mixer control element with the given name */
3376static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
3377 const char *name)
3378{
3379 struct snd_ctl_elem_id id;
3380 memset(&id, 0, sizeof(id));
3381 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
3382 strcpy(id.name, name);
3383 return snd_ctl_find_id(ac97->bus->card, &id);
3384}
3385
3386/* create a virtual master control and add slaves */
Adrian Bunk13c21082008-07-22 20:21:32 +03003387static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
3388 const unsigned int *tlv, const char **slaves)
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003389{
3390 struct snd_kcontrol *kctl;
3391 const char **s;
3392 int err;
3393
3394 kctl = snd_ctl_make_virtual_master(name, tlv);
3395 if (!kctl)
3396 return -ENOMEM;
3397 err = snd_ctl_add(ac97->bus->card, kctl);
3398 if (err < 0)
3399 return err;
3400
3401 for (s = slaves; *s; s++) {
3402 struct snd_kcontrol *sctl;
3403
3404 sctl = snd_ac97_find_mixer_ctl(ac97, *s);
3405 if (!sctl) {
Takashi Iwai38c16e32014-02-25 15:37:50 +01003406 dev_dbg(ac97->bus->card->dev,
3407 "Cannot find slave %s, skipped\n", *s);
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003408 continue;
3409 }
3410 err = snd_ctl_add_slave(kctl, sctl);
3411 if (err < 0)
3412 return err;
3413 }
3414 return 0;
3415}
3416
Takashi Iwaiee423812005-11-17 14:21:36 +01003417static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003419 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 int err;
3421
3422 if (snd_ac97_try_bit(ac97, 0x5a, 9))
3423 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
3424 return err;
3425 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
3426 return err;
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003427
3428 /* There is already a misnamed master switch. Rename it. */
3429 kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
3430 if (!kctl)
3431 return -EINVAL;
3432
3433 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
3434
3435 err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
3436 kctl->tlv.p, slave_vols_vt1616);
3437 if (err < 0)
3438 return err;
3439
3440 err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
3441 NULL, slave_sws_vt1616);
3442 if (err < 0)
3443 return err;
3444
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 return 0;
3446}
3447
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003448static const struct snd_ac97_build_ops patch_vt1616_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 .build_specific = patch_vt1616_specific
3450};
3451
Takashi Iwaiac519022007-02-22 12:58:27 +01003452static int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453{
3454 ac97->build_ops = &patch_vt1616_ops;
3455 return 0;
3456}
3457
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003458/*
Philip Prindeville4b499482005-08-12 16:46:17 +02003459 * VT1617A codec
3460 */
John Utze9024cc2007-03-12 12:30:06 +01003461
3462/*
3463 * unfortunately, the vt1617a stashes the twiddlers required for
John L. Utz III9e285e12008-08-28 16:04:40 +02003464 * noodling the i/o jacks on 2 different regs. that means that we can't
John Utze9024cc2007-03-12 12:30:06 +01003465 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3466 * are own funcs.
3467 *
3468 * NB: this is absolutely and utterly different from the vt1618. dunno
3469 * about the 1616.
3470 */
3471
3472/* copied from ac97_surround_jack_mode_info() */
3473static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3474 struct snd_ctl_elem_info *uinfo)
Philip Prindeville4b499482005-08-12 16:46:17 +02003475{
John Utze9024cc2007-03-12 12:30:06 +01003476 /* ordering in this list reflects vt1617a docs for Reg 20 and
3477 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3478 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3479 * counter-intuitive */
3480
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003481 static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
John Utze9024cc2007-03-12 12:30:06 +01003482 "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3483 "LineIn Mic2", "LineIn Mic2 Mic1",
3484 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003485
3486 return snd_ctl_enum_info(uinfo, 1, 8, texts);
John Utze9024cc2007-03-12 12:30:06 +01003487}
3488
3489static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3490 struct snd_ctl_elem_value *ucontrol)
3491{
3492 ushort usSM51, usMS;
3493
3494 struct snd_ac97 *pac97;
3495
3496 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3497
John L. Utz III9e285e12008-08-28 16:04:40 +02003498 /* grab our desired bits, then mash them together in a manner
John Utze9024cc2007-03-12 12:30:06 +01003499 * consistent with Table 6 on page 17 in the 1617a docs */
3500
3501 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3502 usMS = snd_ac97_read(pac97, 0x20) >> 8;
3503
3504 ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3505
3506 return 0;
3507}
3508
3509static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3510 struct snd_ctl_elem_value *ucontrol)
3511{
3512 ushort usSM51, usMS, usReg;
3513
3514 struct snd_ac97 *pac97;
3515
3516 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3517
3518 usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3519 usMS = ucontrol->value.enumerated.item[0] & 1;
3520
3521 /* push our values into the register - consider that things will be left
3522 * in a funky state if the write fails */
3523
3524 usReg = snd_ac97_read(pac97, 0x7a);
3525 snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3526 usReg = snd_ac97_read(pac97, 0x20);
3527 snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
3528
3529 return 0;
3530}
3531
3532static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3533
3534 AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3535 /*
3536 * These are used to enable/disable surround sound on motherboards
3537 * that have 3 bidirectional analog jacks
3538 */
3539 {
3540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3541 .name = "Smart 5.1 Select",
3542 .info = snd_ac97_vt1617a_smart51_info,
3543 .get = snd_ac97_vt1617a_smart51_get,
3544 .put = snd_ac97_vt1617a_smart51_put,
3545 },
3546};
3547
Harvey Harrisonb03671a2008-08-29 13:32:00 -07003548static int patch_vt1617a(struct snd_ac97 * ac97)
John Utze9024cc2007-03-12 12:30:06 +01003549{
3550 int err = 0;
Takashi Iwai2e75d052008-05-03 18:46:56 +02003551 int val;
John Utze9024cc2007-03-12 12:30:06 +01003552
3553 /* we choose to not fail out at this point, but we tell the
3554 caller when we return */
3555
3556 err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3557 ARRAY_SIZE(snd_ac97_controls_vt1617a));
3558
3559 /* bring analog power consumption to normal by turning off the
3560 * headphone amplifier, like WinXP driver for EPIA SP
Andrey Liakhovets9f458e72006-08-28 16:52:41 +02003561 */
Takashi Iwai2e75d052008-05-03 18:46:56 +02003562 /* We need to check the bit before writing it.
3563 * On some (many?) hardwares, setting bit actually clears it!
3564 */
3565 val = snd_ac97_read(ac97, 0x5c);
3566 if (!(val & 0x20))
3567 snd_ac97_write_cache(ac97, 0x5c, 0x20);
3568
Philip Prindeville4b499482005-08-12 16:46:17 +02003569 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3570 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
Daniel Jacobowitz9f428172007-01-12 19:11:47 +01003571 ac97->build_ops = &patch_vt1616_ops;
John Utze9024cc2007-03-12 12:30:06 +01003572
3573 return err;
Philip Prindeville4b499482005-08-12 16:46:17 +02003574}
3575
John L. Utz III9e285e12008-08-28 16:04:40 +02003576/* VIA VT1618 8 CHANNEL AC97 CODEC
3577 *
3578 * VIA implements 'Smart 5.1' completely differently on the 1618 than
3579 * it does on the 1617a. awesome! They seem to have sourced this
3580 * particular revision of the technology from somebody else, it's
3581 * called Universal Audio Jack and it shows up on some other folk's chips
3582 * as well.
3583 *
3584 * ordering in this list reflects vt1618 docs for Reg 60h and
3585 * the block diagram, DACs are as follows:
3586 *
3587 * OUT_O -> Front,
3588 * OUT_1 -> Surround,
3589 * OUT_2 -> C/LFE
3590 *
3591 * Unlike the 1617a, each OUT has a consistent set of mappings
3592 * for all bitpatterns other than 00:
3593 *
3594 * 01 Unmixed Output
3595 * 10 Line In
3596 * 11 Mic In
3597 *
3598 * Special Case of 00:
3599 *
3600 * OUT_0 Mixed Output
3601 * OUT_1 Reserved
3602 * OUT_2 Reserved
3603 *
3604 * I have no idea what the hell Reserved does, but on an MSI
3605 * CN700T, i have to set it to get 5.1 output - YMMV, bad
3606 * shit may happen.
3607 *
3608 * If other chips use Universal Audio Jack, then this code might be applicable
3609 * to them.
3610 */
3611
3612struct vt1618_uaj_item {
3613 unsigned short mask;
3614 unsigned short shift;
3615 const char *items[4];
3616};
3617
3618/* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
3619
3620static struct vt1618_uaj_item vt1618_uaj[3] = {
3621 {
3622 /* speaker jack */
3623 .mask = 0x03,
3624 .shift = 0,
3625 .items = {
3626 "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
3627 }
3628 },
3629 {
3630 /* line jack */
3631 .mask = 0x0c,
3632 .shift = 2,
3633 .items = {
3634 "Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
3635 }
3636 },
3637 {
3638 /* mic jack */
3639 .mask = 0x30,
3640 .shift = 4,
3641 .items = {
3642 "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
3643 },
3644 },
3645};
3646
3647static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
3648 struct snd_ctl_elem_info *uinfo)
3649{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003650 return snd_ctl_enum_info(uinfo, 1, 4,
3651 vt1618_uaj[kcontrol->private_value].items);
John L. Utz III9e285e12008-08-28 16:04:40 +02003652}
3653
3654/* All of the vt1618 Universal Audio Jack twiddlers are on
3655 * Vendor Defined Register 0x60, page 0. The bits, and thus
3656 * the mask, are the only thing that changes
3657 */
3658static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
3659 struct snd_ctl_elem_value *ucontrol)
3660{
3661 unsigned short datpag, uaj;
3662 struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
3663
3664 mutex_lock(&pac97->page_mutex);
3665
3666 datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
3667 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
3668
3669 uaj = snd_ac97_read(pac97, 0x60) &
3670 vt1618_uaj[kcontrol->private_value].mask;
3671
3672 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
3673 mutex_unlock(&pac97->page_mutex);
3674
3675 ucontrol->value.enumerated.item[0] = uaj >>
3676 vt1618_uaj[kcontrol->private_value].shift;
3677
3678 return 0;
3679}
3680
3681static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
3682 struct snd_ctl_elem_value *ucontrol)
3683{
3684 return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
3685 vt1618_uaj[kcontrol->private_value].mask,
3686 ucontrol->value.enumerated.item[0]<<
3687 vt1618_uaj[kcontrol->private_value].shift,
3688 0);
3689}
3690
3691/* config aux in jack - not found on 3 jack motherboards or soundcards */
3692
3693static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
3694 struct snd_ctl_elem_info *uinfo)
3695{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003696 static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
John L. Utz III9e285e12008-08-28 16:04:40 +02003697
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003698 return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
John L. Utz III9e285e12008-08-28 16:04:40 +02003699}
3700
3701static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
3702 struct snd_ctl_elem_value *ucontrol)
3703{
3704 ucontrol->value.enumerated.item[0] =
3705 (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
3706 return 0;
3707}
3708
3709static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
3710 struct snd_ctl_elem_value *ucontrol)
3711{
3712 /* toggle surround rear dac power */
3713
3714 snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
3715 ucontrol->value.enumerated.item[0] << 3);
3716
3717 /* toggle aux in surround rear out jack */
3718
3719 return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
3720 ucontrol->value.enumerated.item[0] << 3);
3721}
3722
3723static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
3724 AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0),
3725 AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0),
3726 AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1),
3727 AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1),
3728 AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1),
3729 AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1),
3730 {
3731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3732 .name = "Speaker Jack Mode",
3733 .info = snd_ac97_vt1618_UAJ_info,
3734 .get = snd_ac97_vt1618_UAJ_get,
3735 .put = snd_ac97_vt1618_UAJ_put,
3736 .private_value = 0
3737 },
3738 {
3739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3740 .name = "Line Jack Mode",
3741 .info = snd_ac97_vt1618_UAJ_info,
3742 .get = snd_ac97_vt1618_UAJ_get,
3743 .put = snd_ac97_vt1618_UAJ_put,
3744 .private_value = 1
3745 },
3746 {
3747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3748 .name = "Mic Jack Mode",
3749 .info = snd_ac97_vt1618_UAJ_info,
3750 .get = snd_ac97_vt1618_UAJ_get,
3751 .put = snd_ac97_vt1618_UAJ_put,
3752 .private_value = 2
3753 },
3754 {
3755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3756 .name = "Aux Jack Mode",
3757 .info = snd_ac97_vt1618_aux_info,
3758 .get = snd_ac97_vt1618_aux_get,
3759 .put = snd_ac97_vt1618_aux_put,
3760 }
3761};
3762
Harvey Harrisonb03671a2008-08-29 13:32:00 -07003763static int patch_vt1618(struct snd_ac97 *ac97)
John L. Utz III9e285e12008-08-28 16:04:40 +02003764{
3765 return patch_build_controls(ac97, snd_ac97_controls_vt1618,
3766 ARRAY_SIZE(snd_ac97_controls_vt1618));
3767}
3768
Philip Prindeville4b499482005-08-12 16:46:17 +02003769/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003770 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003771static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003772{
Randy Cushman831466f2006-12-19 18:42:16 +01003773 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003774 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
Randy Cushman831466f2006-12-19 18:42:16 +01003775 is_shared_surrout(ac97) ? (1<<9) : 0);
3776 /* shared Mic / Center/LFE Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003777 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01003778 is_shared_clfeout(ac97) ? (1<<10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003779}
3780
Takashi Iwaiee423812005-11-17 14:21:36 +01003781static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003782 AC97_SURROUND_JACK_MODE_CTL,
3783 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784};
3785
Takashi Iwaiee423812005-11-17 14:21:36 +01003786static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02003787 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3789 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3790};
3791
Takashi Iwaiee423812005-11-17 14:21:36 +01003792static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793{
3794 int err;
3795 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
3796 return err;
3797 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
3798 return err;
3799 return 0;
3800}
3801
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003802static const struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003803 .build_specific = patch_it2646_specific,
3804 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805};
3806
Takashi Iwaiac519022007-02-22 12:58:27 +01003807static int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808{
3809 ac97->build_ops = &patch_it2646_ops;
3810 /* full DAC volume */
3811 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
3812 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
3813 return 0;
3814}
3815
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003816/*
3817 * Si3036 codec
3818 */
3819
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003821#define AC97_SI3036_LINE_CFG 0x5c
3822
Takashi Iwaiee423812005-11-17 14:21:36 +01003823static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003824AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3825};
3826
Takashi Iwaiee423812005-11-17 14:21:36 +01003827static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003828{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02003829 int idx, err;
3830 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
3831 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
3832 return err;
3833 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003834}
3835
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003836static const struct snd_ac97_build_ops patch_si3036_ops = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003837 .build_specific = patch_si3036_specific,
3838};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
Takashi Iwaiac519022007-02-22 12:58:27 +01003840static int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003842 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
3844 snd_ac97_write_cache(ac97, 0x68, 0);
3845 return 0;
3846}
Charl Coetzeeba224292006-02-09 11:48:21 +01003847
3848/*
3849 * LM 4550 Codec
3850 *
3851 * We use a static resolution table since LM4550 codec cannot be
3852 * properly autoprobed to determine the resolution via
3853 * check_volume_resolution().
3854 */
3855
3856static struct snd_ac97_res_table lm4550_restbl[] = {
3857 { AC97_MASTER, 0x1f1f },
3858 { AC97_HEADPHONE, 0x1f1f },
3859 { AC97_MASTER_MONO, 0x001f },
3860 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
3861 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01003862 { AC97_MIC, 0x001f },
3863 { AC97_LINE, 0x1f1f },
3864 { AC97_CD, 0x1f1f },
3865 { AC97_VIDEO, 0x1f1f },
3866 { AC97_AUX, 0x1f1f },
3867 { AC97_PCM, 0x1f1f },
3868 { AC97_REC_GAIN, 0x0f0f },
3869 { } /* terminator */
3870};
3871
Takashi Iwaiac519022007-02-22 12:58:27 +01003872static int patch_lm4550(struct snd_ac97 *ac97)
Charl Coetzeeba224292006-02-09 11:48:21 +01003873{
3874 ac97->res_table = lm4550_restbl;
3875 return 0;
3876}
Mike Rapoport82466ad2006-06-29 17:15:33 +02003877
3878/*
3879 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3880 */
3881static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
3882/* enable/disable headphone driver which allows direct connection to
3883 stereo headphone without the use of external DC blocking
3884 capacitors */
3885AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3886/* Filter used to compensate the DC offset is added in the ADC to remove idle
3887 tones from the audio band. */
3888AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3889/* Control smart-low-power mode feature. Allows automatic power down
3890 of unused blocks in the ADC analog front end and the PLL. */
3891AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3892};
3893
3894static int patch_ucb1400_specific(struct snd_ac97 * ac97)
3895{
3896 int idx, err;
3897 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
3898 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
3899 return err;
3900 return 0;
3901}
3902
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003903static const struct snd_ac97_build_ops patch_ucb1400_ops = {
Mike Rapoport82466ad2006-06-29 17:15:33 +02003904 .build_specific = patch_ucb1400_specific,
3905};
3906
Takashi Iwaiac519022007-02-22 12:58:27 +01003907static int patch_ucb1400(struct snd_ac97 * ac97)
Mike Rapoport82466ad2006-06-29 17:15:33 +02003908{
3909 ac97->build_ops = &patch_ucb1400_ops;
3910 /* enable headphone driver and smart low power mode by default */
Mike Rapoport25552e82008-07-02 13:19:23 +03003911 snd_ac97_write_cache(ac97, 0x6a, 0x0050);
3912 snd_ac97_write_cache(ac97, 0x6c, 0x0030);
Mike Rapoport82466ad2006-06-29 17:15:33 +02003913 return 0;
3914}