blob: 8cf0dc7a07a4ce90a2114ddaa1ed0ca5c797bc22 [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,
Takashi Iwai1bc10bb2014-10-21 08:51:45 +020036 const unsigned int *tlv,
37 const char * const *slaves);
Andreas Mohr6ba92562011-02-19 00:49:48 +010038
39/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * Chip specific initialization
41 */
42
Takashi Iwaiee423812005-11-17 14:21:36 +010043static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 int idx, err;
46
47 for (idx = 0; idx < count; idx++)
48 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
49 return err;
50 return 0;
51}
52
Takashi Iwai2f3482f2006-08-21 18:44:31 +020053/* replace with a new TLV */
54static void reset_tlv(struct snd_ac97 *ac97, const char *name,
Takashi Iwai0cb29ea2007-01-29 15:33:49 +010055 const unsigned int *tlv)
Takashi Iwai2f3482f2006-08-21 18:44:31 +020056{
57 struct snd_ctl_elem_id sid;
58 struct snd_kcontrol *kctl;
59 memset(&sid, 0, sizeof(sid));
60 strcpy(sid.name, name);
61 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
62 kctl = snd_ctl_find_id(ac97->bus->card, &sid);
63 if (kctl && kctl->tlv.p)
64 kctl->tlv.p = tlv;
65}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/* set to the page, update bits and restore the page */
Takashi Iwaiee423812005-11-17 14:21:36 +010068static 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 -070069{
70 unsigned short page_save;
71 int ret;
72
Ingo Molnar62932df2006-01-16 16:34:20 +010073 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
75 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
76 ret = snd_ac97_update_bits(ac97, reg, mask, value);
77 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
Ingo Molnar62932df2006-01-16 16:34:20 +010078 mutex_unlock(&ac97->page_mutex); /* unlock paging */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return ret;
80}
81
Takashi Iwaieb8caf32005-04-13 14:32:57 +020082/*
83 * shared line-in/mic controls
84 */
Takashi Iwaiee423812005-11-17 14:21:36 +010085static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020086{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +020087 static const char * const texts[] = { "Shared", "Independent" };
88
89 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020090}
91
Takashi Iwaiee423812005-11-17 14:21:36 +010092static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020093{
Takashi Iwaiee423812005-11-17 14:21:36 +010094 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020095
96 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
97 return 0;
98}
99
Takashi Iwaiee423812005-11-17 14:21:36 +0100100static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200101{
Takashi Iwaiee423812005-11-17 14:21:36 +0100102 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200103 unsigned char indep = !!ucontrol->value.enumerated.item[0];
104
105 if (indep != ac97->indep_surround) {
106 ac97->indep_surround = indep;
107 if (ac97->build_ops->update_jacks)
108 ac97->build_ops->update_jacks(ac97);
109 return 1;
110 }
111 return 0;
112}
113
Takashi Iwaiee423812005-11-17 14:21:36 +0100114static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200115{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200116 static const char * const texts[] = { "2ch", "4ch", "6ch", "8ch" };
117
118 return snd_ctl_enum_info(uinfo, 1, kcontrol->private_value, texts);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200119}
120
Takashi Iwaiee423812005-11-17 14:21:36 +0100121static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200122{
Takashi Iwaiee423812005-11-17 14:21:36 +0100123 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200124
125 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
126 return 0;
127}
128
Takashi Iwaiee423812005-11-17 14:21:36 +0100129static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200130{
Takashi Iwaiee423812005-11-17 14:21:36 +0100131 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200132 unsigned char mode = ucontrol->value.enumerated.item[0];
133
Takashi Iwai4235a312008-02-18 12:23:13 +0100134 if (mode >= kcontrol->private_value)
135 return -EINVAL;
Takashi Iwai4e98d6a2007-11-15 15:58:13 +0100136
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200137 if (mode != ac97->channel_mode) {
138 ac97->channel_mode = mode;
139 if (ac97->build_ops->update_jacks)
140 ac97->build_ops->update_jacks(ac97);
141 return 1;
142 }
143 return 0;
144}
145
146#define AC97_SURROUND_JACK_MODE_CTL \
147 { \
148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
149 .name = "Surround Jack Mode", \
150 .info = ac97_surround_jack_mode_info, \
151 .get = ac97_surround_jack_mode_get, \
152 .put = ac97_surround_jack_mode_put, \
153 }
Takashi Iwai4235a312008-02-18 12:23:13 +0100154/* 6ch */
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200155#define AC97_CHANNEL_MODE_CTL \
156 { \
157 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
158 .name = "Channel Mode", \
159 .info = ac97_channel_mode_info, \
160 .get = ac97_channel_mode_get, \
161 .put = ac97_channel_mode_put, \
Takashi Iwai4235a312008-02-18 12:23:13 +0100162 .private_value = 3, \
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200163 }
Takashi Iwai4235a312008-02-18 12:23:13 +0100164/* 4ch */
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200165#define AC97_CHANNEL_MODE_4CH_CTL \
166 { \
167 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
168 .name = "Channel Mode", \
169 .info = ac97_channel_mode_info, \
170 .get = ac97_channel_mode_get, \
171 .put = ac97_channel_mode_put, \
Takashi Iwai4235a312008-02-18 12:23:13 +0100172 .private_value = 2, \
173 }
174/* 8ch */
175#define AC97_CHANNEL_MODE_8CH_CTL \
176 { \
177 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
178 .name = "Channel Mode", \
179 .info = ac97_channel_mode_info, \
180 .get = ac97_channel_mode_get, \
181 .put = ac97_channel_mode_put, \
182 .private_value = 4, \
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200183 }
184
Takashi Iwaiee423812005-11-17 14:21:36 +0100185static inline int is_surround_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200186{
187 return ac97->channel_mode >= 1;
188}
189
Takashi Iwaiee423812005-11-17 14:21:36 +0100190static inline int is_clfe_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200191{
Takashi Iwaieb9b4142005-09-13 18:39:21 +0200192 return ac97->channel_mode >= 2;
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200193}
194
Randy Cushman831466f2006-12-19 18:42:16 +0100195/* system has shared jacks with surround out enabled */
196static inline int is_shared_surrout(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200197{
Randy Cushman831466f2006-12-19 18:42:16 +0100198 return !ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200199}
200
Randy Cushman831466f2006-12-19 18:42:16 +0100201/* system has shared jacks with center/lfe out enabled */
202static inline int is_shared_clfeout(struct snd_ac97 *ac97)
203{
204 return !ac97->indep_surround && is_clfe_on(ac97);
205}
206
207/* system has shared jacks with line in enabled */
208static inline int is_shared_linein(struct snd_ac97 *ac97)
209{
210 return !ac97->indep_surround && !is_surround_on(ac97);
211}
212
213/* system has shared jacks with mic in enabled */
Takashi Iwaiee423812005-11-17 14:21:36 +0100214static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200215{
Randy Cushman831466f2006-12-19 18:42:16 +0100216 return !ac97->indep_surround && !is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200217}
218
Takashi Iwai4235a312008-02-18 12:23:13 +0100219static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
220{
221 return is_surround_on(ac97);
222}
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
Keita Maehara43115f52007-09-19 14:29:37 +0200225/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Keita Maehara13043982007-09-19 14:27:38 +0200227/* It is possible to indicate to the Yamaha YMF7x3 the type of
228 speakers being used. */
229
230static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
231 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200233 static const char * const texts[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 "Standard", "Small", "Smaller"
235 };
236
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200237 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
Keita Maehara13043982007-09-19 14:27:38 +0200240static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Takashi Iwaiee423812005-11-17 14:21:36 +0100243 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 unsigned short val;
245
Keita Maehara13043982007-09-19 14:27:38 +0200246 val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 val = (val >> 10) & 3;
248 if (val > 0) /* 0 = invalid */
249 val--;
250 ucontrol->value.enumerated.item[0] = val;
251 return 0;
252}
253
Keita Maehara13043982007-09-19 14:27:38 +0200254static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
Takashi Iwaiee423812005-11-17 14:21:36 +0100257 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 unsigned short val;
259
260 if (ucontrol->value.enumerated.item[0] > 2)
261 return -EINVAL;
262 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
Keita Maehara13043982007-09-19 14:27:38 +0200263 return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
Keita Maehara13043982007-09-19 14:27:38 +0200266static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
269 .name = "3D Control - Speaker",
Keita Maehara13043982007-09-19 14:27:38 +0200270 .info = snd_ac97_ymf7x3_info_speaker,
271 .get = snd_ac97_ymf7x3_get_speaker,
272 .put = snd_ac97_ymf7x3_put_speaker,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273};
274
Keita Maehara13043982007-09-19 14:27:38 +0200275/* It is possible to indicate to the Yamaha YMF7x3 the source to
276 direct to the S/PDIF output. */
277static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200280 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200282 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Keita Maehara13043982007-09-19 14:27:38 +0200285static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Takashi Iwaiee423812005-11-17 14:21:36 +0100288 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 unsigned short val;
290
Keita Maehara13043982007-09-19 14:27:38 +0200291 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
293 return 0;
294}
295
Keita Maehara13043982007-09-19 14:27:38 +0200296static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
297 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Takashi Iwaiee423812005-11-17 14:21:36 +0100299 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 unsigned short val;
301
302 if (ucontrol->value.enumerated.item[0] > 1)
303 return -EINVAL;
304 val = ucontrol->value.enumerated.item[0] << 1;
Keita Maehara13043982007-09-19 14:27:38 +0200305 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Keita Maehara43115f52007-09-19 14:29:37 +0200308static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
309{
310 struct snd_kcontrol *kctl;
311 int err;
312
313 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
314 err = snd_ctl_add(ac97->bus->card, kctl);
315 if (err < 0)
316 return err;
317 strcpy(kctl->id.name, "3D Control - Wide");
318 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
319 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
320 err = snd_ctl_add(ac97->bus->card,
321 snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
322 ac97));
323 if (err < 0)
324 return err;
325 snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
326 return 0;
327}
328
329static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
330{
331 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
332 AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
333 {
334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
335 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
336 .info = snd_ac97_ymf7x3_spdif_source_info,
337 .get = snd_ac97_ymf7x3_spdif_source_get,
338 .put = snd_ac97_ymf7x3_spdif_source_put,
339 },
340 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
341 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
342};
343
344static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
345{
346 int err;
347
348 err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
349 if (err < 0)
350 return err;
351 err = patch_build_controls(ac97,
352 snd_ac97_yamaha_ymf743_controls_spdif, 3);
353 if (err < 0)
354 return err;
355 /* set default PCM S/PDIF params */
356 /* PCM audio,no copyright,no preemphasis,PCM coder,original */
357 snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
358 return 0;
359}
360
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100361static const struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
Keita Maehara43115f52007-09-19 14:29:37 +0200362 .build_spdif = patch_yamaha_ymf743_build_spdif,
363 .build_3d = patch_yamaha_ymf7x3_3d,
364};
365
366static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
367{
368 ac97->build_ops = &patch_yamaha_ymf743_ops;
369 ac97->caps |= AC97_BC_BASS_TREBLE;
370 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
371 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
372 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
373 return 0;
374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
377 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
378 By default, no output pin is selected, and the S/PDIF signal is not output.
379 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100380static 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 -0700381{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200382 static const char * const texts[3] = { "Disabled", "Pin 43", "Pin 48" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Takashi Iwai3b7a00d2014-10-20 18:15:36 +0200384 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Takashi Iwaiee423812005-11-17 14:21:36 +0100387static 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 -0700388{
Takashi Iwaiee423812005-11-17 14:21:36 +0100389 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 unsigned short val;
391
Keita Maehara13043982007-09-19 14:27:38 +0200392 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
394 return 0;
395}
396
Takashi Iwaiee423812005-11-17 14:21:36 +0100397static 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 -0700398{
Takashi Iwaiee423812005-11-17 14:21:36 +0100399 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 unsigned short val;
401
402 if (ucontrol->value.enumerated.item[0] > 2)
403 return -EINVAL;
404 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
405 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
Keita Maehara13043982007-09-19 14:27:38 +0200406 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
408 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
409}
410
Takashi Iwaiee423812005-11-17 14:21:36 +0100411static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 {
413 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
414 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Keita Maehara13043982007-09-19 14:27:38 +0200415 .info = snd_ac97_ymf7x3_spdif_source_info,
416 .get = snd_ac97_ymf7x3_spdif_source_get,
417 .put = snd_ac97_ymf7x3_spdif_source_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
419 {
420 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
421 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
422 .info = snd_ac97_ymf753_spdif_output_pin_info,
423 .get = snd_ac97_ymf753_spdif_output_pin_get,
424 .put = snd_ac97_ymf753_spdif_output_pin_put,
425 },
Keita Maehara13043982007-09-19 14:27:38 +0200426 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
427 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428};
429
Takashi Iwaiee423812005-11-17 14:21:36 +0100430static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 int err;
433
434 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
435 return err;
436 return 0;
437}
438
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100439static const struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
Keita Maehara13043982007-09-19 14:27:38 +0200440 .build_3d = patch_yamaha_ymf7x3_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .build_post_spdif = patch_yamaha_ymf753_post_spdif
442};
443
Takashi Iwaiac519022007-02-22 12:58:27 +0100444static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
447 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
448 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
449 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
450 By default, no output pin is selected, and the S/PDIF signal is not output.
451 There is also a bit to mute S/PDIF output in a vendor-specific register.
452 */
453 ac97->build_ops = &patch_yamaha_ymf753_ops;
454 ac97->caps |= AC97_BC_BASS_TREBLE;
455 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
456 return 0;
457}
458
459/*
Liam Girdwoodd3311242008-10-12 13:17:36 +0100460 * May 2, 2003 Liam Girdwood <lrg@slimlogic.co.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 * removed broken wolfson00 patch.
462 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
463 */
464
Takashi Iwaiee423812005-11-17 14:21:36 +0100465static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200466AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
467AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
468};
469
Takashi Iwaiee423812005-11-17 14:21:36 +0100470static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200473 * Randolph Bentson <bentson@holmsjoen.com>
474 * WM9703/9707/9708/9717
475 */
476 int err, i;
477
478 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
479 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
480 return err;
481 }
482 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return 0;
484}
Liam Girdwood3998b702005-07-29 11:41:55 +0200485
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100486static const struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200487 .build_specific = patch_wolfson_wm9703_specific,
488};
489
Takashi Iwaiac519022007-02-22 12:58:27 +0100490static int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200491{
492 ac97->build_ops = &patch_wolfson_wm9703_ops;
493 return 0;
494}
495
Takashi Iwaiee423812005-11-17 14:21:36 +0100496static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200497AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
498AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
499AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
500AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
501AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
502AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
503};
504
Takashi Iwaiee423812005-11-17 14:21:36 +0100505static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200506{
507 int err, i;
508 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
509 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
510 return err;
511 }
512 /* patch for DVD noise */
513 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
514 return 0;
515}
516
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100517static const struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200518 .build_specific = patch_wolfson_wm9704_specific,
519};
520
Takashi Iwaiac519022007-02-22 12:58:27 +0100521static int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
Liam Girdwood3998b702005-07-29 11:41:55 +0200523 /* WM9704M/9704Q */
524 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 return 0;
526}
Liam Girdwood3998b702005-07-29 11:41:55 +0200527
Takashi Iwaiac519022007-02-22 12:58:27 +0100528static int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Liam Girdwood3998b702005-07-29 11:41:55 +0200530 /* WM9705, WM9710 */
Krzysztof Heltdd3533e2010-01-01 19:05:43 +0100531 ac97->build_ops = &patch_wolfson_wm9703_ops;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200532#ifdef CONFIG_TOUCHSCREEN_WM9705
533 /* WM9705 touchscreen uses AUX and VIDEO for touch */
Liam Girdwood8f888202006-09-07 18:07:46 +0200534 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200535#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 return 0;
537}
538
Liam Girdwood3998b702005-07-29 11:41:55 +0200539static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
540static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
541static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
542static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
543static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
544static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
545static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
546static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
547static const char* wm9711_rec_sel[] =
548 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
549static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
550
551static const struct ac97_enum wm9711_enum[] = {
552AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
553AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
554AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
555AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
556AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
557AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
558AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
559AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
560AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
561AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
562};
563
Takashi Iwaiee423812005-11-17 14:21:36 +0100564static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200565AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
566AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
567AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
568AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
569AC97_ENUM("ALC Function", wm9711_enum[0]),
570AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
571AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
572AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
573AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
574AC97_ENUM("ALC NG Type", wm9711_enum[9]),
575AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
576
577AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
578AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
579AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
580AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
581
582AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200583AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200584AC97_ENUM("Out3 Mux", wm9711_enum[2]),
585AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
586AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
587
588AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
589AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
590AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
591AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
592AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
593AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
594
595AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
596AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
597AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
598AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
599AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
600AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
601
602AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
603AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
604
605AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
606AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
607AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
608
609AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
610AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
611AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
612
613AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
614AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
615AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
616AC97_ENUM("Capture Select", wm9711_enum[8]),
617
618AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
619AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
620
621AC97_ENUM("Bass Control", wm9711_enum[5]),
622AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
623AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
624AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
625
626AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
627AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200628AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200629AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
630
631AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
632AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
633AC97_ENUM("Mic Select Source", wm9711_enum[7]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200634AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
635AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100636AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200637
Juergen Beisert0264b3b2008-06-06 17:02:57 +0200638AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200639AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
640AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
641AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
642};
643
Takashi Iwaiee423812005-11-17 14:21:36 +0100644static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200645{
646 int err, i;
647
648 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
649 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
650 return err;
651 }
652 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
653 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
654 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
655 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
656 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
657 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
658 return 0;
659}
660
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100661static const struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200662 .build_specific = patch_wolfson_wm9711_specific,
663};
664
Takashi Iwaiac519022007-02-22 12:58:27 +0100665static int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Liam Girdwood3998b702005-07-29 11:41:55 +0200667 /* WM9711, WM9712 */
668 ac97->build_ops = &patch_wolfson_wm9711_ops;
669
670 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
671 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 return 0;
674}
675
Liam Girdwood3998b702005-07-29 11:41:55 +0200676static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200678static const char* wm9713_rec_src[] =
679 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
680 "Mono Mix", "Zh"};
681static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
682static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
683static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
684static const char* wm9713_spk_pga[] =
685 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
686static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
687static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
688static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
689static const char* wm9713_dac_inv[] =
690 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
691 "Headphone Mix Mono", "NC", "Vmid"};
692static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
693static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695static const struct ac97_enum wm9713_enum[] = {
696AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
697AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
698AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200699AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
700AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
701AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
702AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
703AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
704AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
705AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
706AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
707AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
708AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
709AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710};
711
Takashi Iwaiee423812005-11-17 14:21:36 +0100712static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200714AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
715AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
716AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
717
718AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
719AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
720AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
721AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
722
723AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
724AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
725AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
726AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100727AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200728AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
729AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
730
731AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
732AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
733AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
734AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
735
736AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
737AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
738AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
739AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
740AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
741AC97_ENUM("Capture Select", wm9713_enum[3]),
742
743AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
744AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
745AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
746AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
747AC97_ENUM("ALC Function", wm9713_enum[5]),
748AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
749AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
750AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
751AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
752AC97_ENUM("ALC NG Type", wm9713_enum[13]),
753AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
754
755AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
756AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
757AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
758AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
759AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
760AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
761
762AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
763AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
764AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
765AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
766AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
767AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
768
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +0100769AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
770AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
771AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
772AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
773AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
774AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200775
776AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
777AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
778AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
779AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
780AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
781AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
782
783AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
784AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
785AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
786AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
787AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
788AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
789
790AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
791AC97_ENUM("Master Input Mux", wm9713_enum[7]),
792AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
793AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
794AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
795
796AC97_ENUM("Bass Control", wm9713_enum[12]),
797AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
798AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
799AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
800AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
801AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802};
803
Takashi Iwaiee423812005-11-17 14:21:36 +0100804static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200805AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
806AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
807AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
808AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809};
810
Takashi Iwaiee423812005-11-17 14:21:36 +0100811static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200812{
813 int err, i;
814
815 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
816 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
817 return err;
818 }
819 return 0;
820}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Takashi Iwaiee423812005-11-17 14:21:36 +0100822static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 int err, i;
825
Liam Girdwood3998b702005-07-29 11:41:55 +0200826 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
827 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 -0700828 return err;
829 }
830 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
833 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
836 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return 0;
838}
839
840#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100841static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
843 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
844 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
845}
846
Takashi Iwaiee423812005-11-17 14:21:36 +0100847static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
850 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
851 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
852}
853#endif
854
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100855static const struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200857 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858#ifdef CONFIG_PM
859 .suspend = patch_wolfson_wm9713_suspend,
860 .resume = patch_wolfson_wm9713_resume
861#endif
862};
863
Takashi Iwaiac519022007-02-22 12:58:27 +0100864static int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Liam Girdwood3998b702005-07-29 11:41:55 +0200866 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 ac97->build_ops = &patch_wolfson_wm9713_ops;
868
869 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200870 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
871 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200872 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
875 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
876 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
877
878 return 0;
879}
880
881/*
882 * Tritech codec
883 */
Takashi Iwaiac519022007-02-22 12:58:27 +0100884static int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 snd_ac97_write_cache(ac97, 0x26, 0x0300);
887 snd_ac97_write_cache(ac97, 0x26, 0x0000);
888 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
889 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
890 return 0;
891}
892
893/*
894 * Sigmatel STAC97xx codecs
895 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100896static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Takashi Iwaiee423812005-11-17 14:21:36 +0100898 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 int err;
900
901 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
902 return err;
903 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
904 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
905 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
906 return 0;
907}
908
Takashi Iwaiee423812005-11-17 14:21:36 +0100909static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Takashi Iwaiee423812005-11-17 14:21:36 +0100911 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 int err;
913
914 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
915 return err;
916 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
917 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
918 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
919 return err;
920 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
921 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
922 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
923 return 0;
924}
925
Takashi Iwaiee423812005-11-17 14:21:36 +0100926static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200927AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch",
928 AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200930/* "Sigmatel " removed due to excessive name length: */
Takashi Iwaiee423812005-11-17 14:21:36 +0100931static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Andreas Mohrafe6d7e2009-05-22 17:48:58 +0200932AC97_SINGLE("Surround Phase Inversion Playback Switch",
933 AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Takashi Iwaiee423812005-11-17 14:21:36 +0100935static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
937AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
938};
939
Takashi Iwaiee423812005-11-17 14:21:36 +0100940static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
942 int err;
943
944 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
945 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
946 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
947 return err;
948 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
949 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
950 return err;
951 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
952 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
953 return err;
954 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
955 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
956 return err;
957 return 0;
958}
959
Hanno Boeck3e8b3b92011-01-14 19:14:47 +0100960static const struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 .build_3d = patch_sigmatel_stac9700_3d,
962 .build_specific = patch_sigmatel_stac97xx_specific
963};
964
Takashi Iwaiac519022007-02-22 12:58:27 +0100965static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 ac97->build_ops = &patch_sigmatel_stac9700_ops;
968 return 0;
969}
970
Takashi Iwaiee423812005-11-17 14:21:36 +0100971static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Takashi Iwaiee423812005-11-17 14:21:36 +0100973 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 int err;
975
Ingo Molnar62932df2006-01-16 16:34:20 +0100976 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
978 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
979 (ucontrol->value.integer.value[0] & 1) << 4);
980 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100981 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 return err;
983}
984
Takashi Iwaiee423812005-11-17 14:21:36 +0100985static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
987 .name = "Sigmatel Output Bias Switch",
988 .info = snd_ac97_info_volsw,
989 .get = snd_ac97_get_volsw,
990 .put = snd_ac97_stac9708_put_bias,
991 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
992};
993
Takashi Iwaiee423812005-11-17 14:21:36 +0100994static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 int err;
997
James C Georgase4c3bf02006-12-19 11:09:41 +0100998 /* the register bit is writable, but the function is not implemented: */
999 snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
1000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
1002 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
1003 return err;
1004 return patch_sigmatel_stac97xx_specific(ac97);
1005}
1006
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001007static const struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 .build_3d = patch_sigmatel_stac9708_3d,
1009 .build_specific = patch_sigmatel_stac9708_specific
1010};
1011
Takashi Iwaiac519022007-02-22 12:58:27 +01001012static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 unsigned int codec72, codec6c;
1015
1016 ac97->build_ops = &patch_sigmatel_stac9708_ops;
1017 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
1018
1019 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
1020 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
1021
1022 if ((codec72==0) && (codec6c==0)) {
1023 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1024 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
1025 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1026 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
1027 } else if ((codec72==0x8000) && (codec6c==0)) {
1028 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1029 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
1030 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
1031 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
1032 /* nothing */
1033 }
1034 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1035 return 0;
1036}
1037
Takashi Iwaiac519022007-02-22 12:58:27 +01001038static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
1040 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1041 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1042 // patch for SigmaTel
1043 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1044 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1045 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1046 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1047 }
1048 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1049 return 0;
1050}
1051
Takashi Iwaiac519022007-02-22 12:58:27 +01001052static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
1054 // patch for SigmaTel
1055 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1056 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1057 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1058 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1059 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1060 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1061 return 0;
1062}
1063
Takashi Iwaiac519022007-02-22 12:58:27 +01001064static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
1066 // patch for SigmaTel
1067 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1068 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1069 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1070 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1071 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1072 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1073 return 0;
1074}
1075
Takashi Iwaiee423812005-11-17 14:21:36 +01001076static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001078 static const char * const texts[5] = {
1079 "Input/Disabled", "Front Output",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 "Rear Output", "Center/LFE Output", "Mixer Output" };
1081
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001082 return snd_ctl_enum_info(uinfo, 1, 5, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Takashi Iwaiee423812005-11-17 14:21:36 +01001085static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Takashi Iwaiee423812005-11-17 14:21:36 +01001087 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 int shift = kcontrol->private_value;
1089 unsigned short val;
1090
1091 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1092 if (!(val & 4))
1093 ucontrol->value.enumerated.item[0] = 0;
1094 else
1095 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1096 return 0;
1097}
1098
Takashi Iwaiee423812005-11-17 14:21:36 +01001099static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Takashi Iwaiee423812005-11-17 14:21:36 +01001101 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 int shift = kcontrol->private_value;
1103 unsigned short val;
1104
1105 if (ucontrol->value.enumerated.item[0] > 4)
1106 return -EINVAL;
1107 if (ucontrol->value.enumerated.item[0] == 0)
1108 val = 0;
1109 else
1110 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1111 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1112 7 << shift, val << shift, 0);
1113}
1114
Takashi Iwaiee423812005-11-17 14:21:36 +01001115static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001117 static const char * const texts[7] = {
1118 "Mic2 Jack", "Mic1 Jack", "Line In Jack",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1120
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001121 return snd_ctl_enum_info(uinfo, 1, 7, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Takashi Iwaiee423812005-11-17 14:21:36 +01001124static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Takashi Iwaiee423812005-11-17 14:21:36 +01001126 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 int shift = kcontrol->private_value;
1128 unsigned short val;
1129
1130 val = ac97->regs[AC97_SIGMATEL_INSEL];
1131 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1132 return 0;
1133}
1134
Takashi Iwaiee423812005-11-17 14:21:36 +01001135static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Takashi Iwaiee423812005-11-17 14:21:36 +01001137 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 int shift = kcontrol->private_value;
1139
1140 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1141 ucontrol->value.enumerated.item[0] << shift, 0);
1142}
1143
Takashi Iwaiee423812005-11-17 14:21:36 +01001144static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001146 static const char * const texts[3] = {
1147 "None", "Front Jack", "Rear Jack"
1148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001150 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Takashi Iwaiee423812005-11-17 14:21:36 +01001153static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Takashi Iwaiee423812005-11-17 14:21:36 +01001155 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1158 return 0;
1159}
1160
Takashi Iwaiee423812005-11-17 14:21:36 +01001161static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Takashi Iwaiee423812005-11-17 14:21:36 +01001163 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1166 ucontrol->value.enumerated.item[0], 0);
1167}
1168
1169#define STAC9758_OUTPUT_JACK(xname, shift) \
1170{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1171 .info = snd_ac97_stac9758_output_jack_info, \
1172 .get = snd_ac97_stac9758_output_jack_get, \
1173 .put = snd_ac97_stac9758_output_jack_put, \
1174 .private_value = shift }
1175#define STAC9758_INPUT_JACK(xname, shift) \
1176{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1177 .info = snd_ac97_stac9758_input_jack_info, \
1178 .get = snd_ac97_stac9758_input_jack_get, \
1179 .put = snd_ac97_stac9758_input_jack_put, \
1180 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001181static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1183 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1184 STAC9758_OUTPUT_JACK("Front Jack", 7),
1185 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1186 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1187 STAC9758_INPUT_JACK("Mic Input Source", 0),
1188 STAC9758_INPUT_JACK("Line Input Source", 8),
1189 {
1190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1191 .name = "Headphone Amp",
1192 .info = snd_ac97_stac9758_phonesel_info,
1193 .get = snd_ac97_stac9758_phonesel_get,
1194 .put = snd_ac97_stac9758_phonesel_put
1195 },
1196 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1197 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1198};
1199
Takashi Iwaiee423812005-11-17 14:21:36 +01001200static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
1202 int err;
1203
1204 err = patch_sigmatel_stac97xx_specific(ac97);
1205 if (err < 0)
1206 return err;
1207 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1208 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1209 if (err < 0)
1210 return err;
1211 /* DAC-A direct */
1212 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1213 /* DAC-A to Mix = PCM */
1214 /* DAC-B direct = Surround */
1215 /* DAC-B to Mix */
1216 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1217 /* DAC-C direct = Center/LFE */
1218
1219 return 0;
1220}
1221
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001222static const struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .build_3d = patch_sigmatel_stac9700_3d,
1224 .build_specific = patch_sigmatel_stac9758_specific
1225};
1226
Takashi Iwaiac519022007-02-22 12:58:27 +01001227static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
1229 static unsigned short regs[4] = {
1230 AC97_SIGMATEL_OUTSEL,
1231 AC97_SIGMATEL_IOMISC,
1232 AC97_SIGMATEL_INSEL,
1233 AC97_SIGMATEL_VARIOUS
1234 };
1235 static unsigned short def_regs[4] = {
1236 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1237 /* IOMISC */ 0x2001,
1238 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1239 /* VARIOUS */ 0x0040
1240 };
1241 static unsigned short m675_regs[4] = {
1242 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1243 /* IOMISC */ 0x2102, /* HP amp on */
1244 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1245 /* VARIOUS */ 0x0041 /* stereo mic */
1246 };
1247 unsigned short *pregs = def_regs;
1248 int i;
1249
1250 /* Gateway M675 notebook */
1251 if (ac97->pci &&
1252 ac97->subsystem_vendor == 0x107b &&
1253 ac97->subsystem_device == 0x0601)
1254 pregs = m675_regs;
1255
1256 // patch for SigmaTel
1257 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1258 /* FIXME: assume only page 0 for writing cache */
1259 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1260 for (i = 0; i < 4; i++)
1261 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1262
1263 ac97->flags |= AC97_STEREO_MUTES;
1264 return 0;
1265}
1266
1267/*
1268 * Cirrus Logic CS42xx codecs
1269 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001270static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1272 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1273};
1274
Takashi Iwaiee423812005-11-17 14:21:36 +01001275static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 int err;
1278
1279 /* con mask, pro mask, default */
1280 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1281 return err;
1282 /* switch, spsa */
1283 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1284 return err;
1285 switch (ac97->id & AC97_ID_CS_MASK) {
1286 case AC97_ID_CS4205:
1287 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1288 return err;
1289 break;
1290 }
1291 /* set default PCM S/PDIF params */
1292 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1293 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1294 return 0;
1295}
1296
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001297static const struct snd_ac97_build_ops patch_cirrus_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 .build_spdif = patch_cirrus_build_spdif
1299};
1300
Takashi Iwaiac519022007-02-22 12:58:27 +01001301static int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1304 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1305 - sp/dif EA ID is not set, but sp/dif is always present.
1306 - enable/disable is spdif register bit 15.
1307 - sp/dif control register is 0x68. differs from AC97:
1308 - valid is bit 14 (vs 15)
1309 - no DRS
1310 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1311 - sp/dif ssource select is in 0x5e bits 0,1.
1312 */
1313
1314 ac97->build_ops = &patch_cirrus_ops;
1315 ac97->flags |= AC97_CS_SPDIF;
1316 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1317 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1318 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1319 return 0;
1320}
1321
Takashi Iwaiac519022007-02-22 12:58:27 +01001322static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
1324 /* force the detection of PC Beep */
1325 ac97->flags |= AC97_HAS_PC_BEEP;
1326
1327 return patch_cirrus_spdif(ac97);
1328}
1329
1330/*
1331 * Conexant codecs
1332 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001333static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1335};
1336
Takashi Iwaiee423812005-11-17 14:21:36 +01001337static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
1339 int err;
1340
1341 /* con mask, pro mask, default */
1342 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1343 return err;
1344 /* switch */
1345 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1346 return err;
1347 /* set default PCM S/PDIF params */
1348 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1349 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1350 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1351 return 0;
1352}
1353
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001354static const struct snd_ac97_build_ops patch_conexant_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .build_spdif = patch_conexant_build_spdif
1356};
1357
Takashi Iwaiac519022007-02-22 12:58:27 +01001358static int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
1360 ac97->build_ops = &patch_conexant_ops;
1361 ac97->flags |= AC97_CX_SPDIF;
1362 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1363 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1364 return 0;
1365}
1366
Takashi Iwaiac519022007-02-22 12:58:27 +01001367static int patch_cx20551(struct snd_ac97 *ac97)
Takashi Iwai9e292c02007-02-09 12:42:03 +01001368{
1369 snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
1370 return 0;
1371}
1372
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373/*
1374 * Analog Device AD18xx, AD19xx codecs
1375 */
1376#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001377static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 static unsigned short setup_regs[] = {
1380 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1381 };
1382 int i, codec;
1383
1384 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1385 unsigned short reg = setup_regs[i];
1386 if (test_bit(reg, ac97->reg_accessed)) {
1387 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1388 snd_ac97_read(ac97, reg);
1389 }
1390 }
1391
1392 if (! (ac97->flags & AC97_AD_MULTI))
1393 /* normal restore */
1394 snd_ac97_restore_status(ac97);
1395 else {
1396 /* restore the AD18xx codec configurations */
1397 for (codec = 0; codec < 3; codec++) {
1398 if (! ac97->spec.ad18xx.id[codec])
1399 continue;
1400 /* select single codec */
1401 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1402 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1403 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1404 }
1405 /* select all codecs */
1406 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1407
1408 /* restore status */
1409 for (i = 2; i < 0x7c ; i += 2) {
1410 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1411 continue;
1412 if (test_bit(i, ac97->reg_accessed)) {
1413 /* handle multi codecs for AD18xx */
1414 if (i == AC97_PCM) {
1415 for (codec = 0; codec < 3; codec++) {
1416 if (! ac97->spec.ad18xx.id[codec])
1417 continue;
1418 /* select single codec */
1419 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1420 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1421 /* update PCM bits */
1422 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1423 }
1424 /* select all codecs */
1425 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1426 continue;
1427 } else if (i == AC97_AD_TEST ||
1428 i == AC97_AD_CODEC_CFG ||
1429 i == AC97_AD_SERIAL_CFG)
1430 continue; /* ignore */
1431 }
1432 snd_ac97_write(ac97, i, ac97->regs[i]);
1433 snd_ac97_read(ac97, i);
1434 }
1435 }
1436
1437 snd_ac97_restore_iec958(ac97);
1438}
Jaya Kumar1561f092006-06-19 15:06:14 +02001439
1440static void ad1888_resume(struct snd_ac97 *ac97)
1441{
1442 ad18xx_resume(ac97);
1443 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1444}
1445
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#endif
1447
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001448static const struct snd_ac97_res_table ad1819_restbl[] = {
1449 { AC97_PHONE, 0x9f1f },
1450 { AC97_MIC, 0x9f1f },
1451 { AC97_LINE, 0x9f1f },
1452 { AC97_CD, 0x9f1f },
1453 { AC97_VIDEO, 0x9f1f },
1454 { AC97_AUX, 0x9f1f },
1455 { AC97_PCM, 0x9f1f },
1456 { } /* terminator */
1457};
1458
Takashi Iwaiac519022007-02-22 12:58:27 +01001459static int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
1461 unsigned short scfg;
1462
1463 // patch for Analog Devices
1464 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1465 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001466 ac97->res_table = ad1819_restbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 return 0;
1468}
1469
Takashi Iwaiee423812005-11-17 14:21:36 +01001470static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
1472 unsigned short val;
1473
1474 // test for unchained codec
1475 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1476 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1477 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1478 if ((val & 0xff40) != 0x5340)
1479 return 0;
1480 ac97->spec.ad18xx.unchained[idx] = mask;
1481 ac97->spec.ad18xx.id[idx] = val;
1482 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1483 return mask;
1484}
1485
Takashi Iwaiee423812005-11-17 14:21:36 +01001486static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
1488 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1489 unsigned short val;
1490
1491 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1492 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1493 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1494 if ((val & 0xff40) != 0x5340)
1495 return 0;
1496 if (codec_bits)
1497 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1498 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1499 ac97->spec.ad18xx.id[idx] = val;
1500 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1501 return 1;
1502}
1503
Takashi Iwaiee423812005-11-17 14:21:36 +01001504static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
1506 // already detected?
1507 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1508 cidx1 = -1;
1509 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1510 cidx2 = -1;
1511 if (cidx1 < 0 && cidx2 < 0)
1512 return;
1513 // test for chained codecs
1514 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1515 ac97->spec.ad18xx.unchained[unchained_idx]);
1516 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1517 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1518 if (cidx1 >= 0) {
Takashi Iwaic19bcdc2006-11-08 15:48:43 +01001519 if (cidx2 < 0)
1520 patch_ad1881_chained1(ac97, cidx1, 0);
1521 else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 patch_ad1881_chained1(ac97, cidx2, 0);
1523 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1524 patch_ad1881_chained1(ac97, cidx1, 0);
1525 } else if (cidx2 >= 0) {
1526 patch_ad1881_chained1(ac97, cidx2, 0);
1527 }
1528}
1529
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001530static const struct snd_ac97_build_ops patch_ad1881_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531#ifdef CONFIG_PM
1532 .resume = ad18xx_resume
1533#endif
1534};
1535
Takashi Iwaiac519022007-02-22 12:58:27 +01001536static int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
1538 static const char cfg_idxs[3][2] = {
1539 {2, 1},
1540 {0, 2},
1541 {0, 1}
1542 };
1543
1544 // patch for Analog Devices
1545 unsigned short codecs[3];
1546 unsigned short val;
1547 int idx, num;
1548
1549 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1550 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1551 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1552 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1553 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1554
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001555 if (! (codecs[0] || codecs[1] || codecs[2]))
1556 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 for (idx = 0; idx < 3; idx++)
1559 if (ac97->spec.ad18xx.unchained[idx])
1560 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1561
1562 if (ac97->spec.ad18xx.id[1]) {
1563 ac97->flags |= AC97_AD_MULTI;
1564 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1565 }
1566 if (ac97->spec.ad18xx.id[2]) {
1567 ac97->flags |= AC97_AD_MULTI;
1568 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1569 }
1570
1571 __end:
1572 /* select all codecs */
1573 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1574 /* check if only one codec is present */
1575 for (idx = num = 0; idx < 3; idx++)
1576 if (ac97->spec.ad18xx.id[idx])
1577 num++;
1578 if (num == 1) {
1579 /* ok, deselect all ID bits */
1580 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1581 ac97->spec.ad18xx.codec_cfg[0] =
1582 ac97->spec.ad18xx.codec_cfg[1] =
1583 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1584 }
1585 /* required for AD1886/AD1885 combination */
1586 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1587 if (ac97->spec.ad18xx.id[0]) {
1588 ac97->id &= 0xffff0000;
1589 ac97->id |= ac97->spec.ad18xx.id[0];
1590 }
1591 ac97->build_ops = &patch_ad1881_build_ops;
1592 return 0;
1593}
1594
Takashi Iwaiee423812005-11-17 14:21:36 +01001595static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1597 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1598 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1599 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1600 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1601 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1602};
1603
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001604static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001605
Takashi Iwaiee423812005-11-17 14:21:36 +01001606static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
1608 int err;
1609
1610 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1611 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001612 reset_tlv(ac97, "Headphone Playback Volume",
1613 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 return 0;
1615}
1616
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001617static const struct snd_ac97_build_ops patch_ad1885_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 .build_specific = &patch_ad1885_specific,
1619#ifdef CONFIG_PM
1620 .resume = ad18xx_resume
1621#endif
1622};
1623
Takashi Iwaiac519022007-02-22 12:58:27 +01001624static int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
1626 patch_ad1881(ac97);
1627 /* This is required to deal with the Intel D815EEAL2 */
1628 /* i.e. Line out is actually headphone out from codec */
1629
1630 /* set default */
1631 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1632
1633 ac97->build_ops = &patch_ad1885_build_ops;
1634 return 0;
1635}
1636
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001637static int patch_ad1886_specific(struct snd_ac97 * ac97)
1638{
1639 reset_tlv(ac97, "Headphone Playback Volume",
1640 db_scale_6bit_6db_max);
1641 return 0;
1642}
1643
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001644static const struct snd_ac97_build_ops patch_ad1886_build_ops = {
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001645 .build_specific = &patch_ad1886_specific,
1646#ifdef CONFIG_PM
1647 .resume = ad18xx_resume
1648#endif
1649};
1650
Takashi Iwaiac519022007-02-22 12:58:27 +01001651static int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
1653 patch_ad1881(ac97);
1654 /* Presario700 workaround */
1655 /* for Jack Sense/SPDIF Register misetting causing */
1656 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001657 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 return 0;
1659}
1660
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001661/* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662#define AC97_AD198X_MBC 0x0003 /* mic boost */
1663#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1664#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1665#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1666#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
Randy Cushman6428ea12006-12-21 19:17:29 +01001667#define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1668#define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1669#define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1670#define AC97_AD198X_VREF_SHIFT 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1672#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1673#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1674#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
Randy Cushman6428ea12006-12-21 19:17:29 +01001675#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1676 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1678#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1679#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1680#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1681#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1682#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1683#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1684
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001685/* MISC 1 bits (AD1986 register 0x76) */
1686#define AC97_AD1986_MBC 0x0003 /* mic boost */
1687#define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1688#define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1689#define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1690#define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1691#define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1692#define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1693#define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1694#define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1695#define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1696#define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1697#define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1698#define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1699#define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1700#define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1701 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1702#define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1703#define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1704#define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1705#define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1706#define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1707#define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1708
1709/* MISC 2 bits (AD1986 register 0x70) */
1710#define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1711
1712#define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1713#define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1714#define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1715#define AC97_AD1986_CVREF_MASK \
1716 (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1717#define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1718#define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1719#define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1720#define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1721#define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1722#define AC97_AD1986_MVREF_MASK \
1723 (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1724
1725/* MISC 3 bits (AD1986 register 0x7a) */
1726#define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1727
1728#define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1729#define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1730#define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1731#define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1732#define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1733#define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1734#define AC97_AD1986_LVREF_MASK \
1735 (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1736#define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1737#define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1738#define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1739 /* input select Surround DACs */
1740#define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1741 /* select C/LFE DACs */
1742#define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1743
1744/* Serial Config bits (AD1986 register 0x74) (incomplete) */
1745#define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1746#define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1747#define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1748#define AC97_AD1986_OMS_MASK \
1749 (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1750#define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1751#define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1752#define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1753#define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1754 /* are MIC sources */
1755#define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1756 /* are MIC sources */
1757#define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1758 /* are MIC sources */
1759#define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1760 /* are MIC sources */
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Takashi Iwaiee423812005-11-17 14:21:36 +01001763static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001765 static const char * const texts[2] = { "AC-Link", "A/D Converter" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001767 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Takashi Iwaiee423812005-11-17 14:21:36 +01001770static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
Takashi Iwaiee423812005-11-17 14:21:36 +01001772 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 unsigned short val;
1774
1775 val = ac97->regs[AC97_AD_SERIAL_CFG];
1776 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1777 return 0;
1778}
1779
Takashi Iwaiee423812005-11-17 14:21:36 +01001780static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
Takashi Iwaiee423812005-11-17 14:21:36 +01001782 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 unsigned short val;
1784
1785 if (ucontrol->value.enumerated.item[0] > 1)
1786 return -EINVAL;
1787 val = ucontrol->value.enumerated.item[0] << 2;
1788 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1789}
1790
Takashi Iwaiee423812005-11-17 14:21:36 +01001791static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1793 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1794 .info = snd_ac97_ad198x_spdif_source_info,
1795 .get = snd_ac97_ad198x_spdif_source_get,
1796 .put = snd_ac97_ad198x_spdif_source_put,
1797};
1798
Takashi Iwaiee423812005-11-17 14:21:36 +01001799static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
1801 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1802}
1803
Takashi Iwaiee423812005-11-17 14:21:36 +01001804static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1806 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1807};
1808
Takashi Iwai128a46a2006-01-11 18:15:43 +01001809/* black list to avoid HP/Line jack-sense controls
1810 * (SS vendor << 16 | device)
1811 */
1812static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia31e8c72007-02-22 12:47:25 +01001813 0x10140523, /* Thinkpad R40 */
1814 0x10140534, /* Thinkpad X31 */
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001815 0x10140537, /* Thinkpad T41p */
Daniel T Chene1f7f022010-03-25 22:38:15 -07001816 0x1014053e, /* Thinkpad R40e */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001817 0x10140554, /* Thinkpad T42p/R50p */
Daniel T Chen8286c532007-05-15 11:46:23 +02001818 0x10140567, /* Thinkpad T43p 2668-G7U */
1819 0x10140581, /* Thinkpad X41-2527 */
Daniel T Chenaf9a75d2010-01-09 01:22:29 -05001820 0x10280160, /* Dell Dimension 2400 */
Daniel T Chen8286c532007-05-15 11:46:23 +02001821 0x104380b0, /* Asus A7V8X-MX */
1822 0x11790241, /* Toshiba Satellite A-15 S127 */
Daniel Chen5cd165e2010-03-28 13:32:34 -07001823 0x1179ff10, /* Toshiba P500 */
Daniel T Chen8286c532007-05-15 11:46:23 +02001824 0x144dc01a, /* Samsung NP-X20C004/SEG */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001825 0 /* end */
1826};
1827
1828static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1829{
1830 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1831 for (; *list; list++)
1832 if (*list == subid)
1833 return 1;
1834 return 0;
1835}
1836
Takashi Iwaiee423812005-11-17 14:21:36 +01001837static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001839 if (check_list(ac97, ad1981_jacks_blacklist))
1840 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1842 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1843}
1844
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001845static const struct snd_ac97_build_ops patch_ad1981a_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 .build_post_spdif = patch_ad198x_post_spdif,
1847 .build_specific = patch_ad1981a_specific,
1848#ifdef CONFIG_PM
1849 .resume = ad18xx_resume
1850#endif
1851};
1852
Takashi Iwai128a46a2006-01-11 18:15:43 +01001853/* white list to enable HP jack-sense bits
1854 * (SS vendor << 16 | device)
1855 */
1856static unsigned int ad1981_jacks_whitelist[] = {
1857 0x0e11005a, /* HP nc4000/4010 */
1858 0x103c0890, /* HP nc6000 */
1859 0x103c0938, /* HP nc4220 */
1860 0x103c099c, /* HP nx6110 */
1861 0x103c0944, /* HP nc6220 */
1862 0x103c0934, /* HP nc8220 */
1863 0x103c006d, /* HP nx9105 */
Daniel T Cheneade7b22011-08-14 22:43:01 -04001864 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001865 0x17340088, /* FSC Scenic-W */
1866 0 /* end */
1867};
1868
Takashi Iwaiee423812005-11-17 14:21:36 +01001869static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001871 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 /* enable headphone jack sense */
1873 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}
1875
Takashi Iwaiac519022007-02-22 12:58:27 +01001876static int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
1878 patch_ad1881(ac97);
1879 ac97->build_ops = &patch_ad1981a_build_ops;
1880 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1881 ac97->flags |= AC97_STEREO_MUTES;
1882 check_ad1981_hp_jack_sense(ac97);
1883 return 0;
1884}
1885
Takashi Iwaiee423812005-11-17 14:21:36 +01001886static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1888
Takashi Iwaiee423812005-11-17 14:21:36 +01001889static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 int err;
1892
1893 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1894 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001895 if (check_list(ac97, ad1981_jacks_blacklist))
1896 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1898 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1899}
1900
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01001901static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 .build_post_spdif = patch_ad198x_post_spdif,
1903 .build_specific = patch_ad1981b_specific,
1904#ifdef CONFIG_PM
1905 .resume = ad18xx_resume
1906#endif
1907};
1908
Takashi Iwaiac519022007-02-22 12:58:27 +01001909static int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
1911 patch_ad1881(ac97);
1912 ac97->build_ops = &patch_ad1981b_build_ops;
1913 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1914 ac97->flags |= AC97_STEREO_MUTES;
1915 check_ad1981_hp_jack_sense(ac97);
1916 return 0;
1917}
1918
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001919#define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Takashi Iwaiee423812005-11-17 14:21:36 +01001921static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
Takashi Iwaiee423812005-11-17 14:21:36 +01001923 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 unsigned short val;
1925
1926 val = ac97->regs[AC97_AD_MISC];
1927 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001928 if (ac97->spec.ad18xx.lo_as_master)
1929 ucontrol->value.integer.value[0] =
1930 !ucontrol->value.integer.value[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 return 0;
1932}
1933
Takashi Iwaiee423812005-11-17 14:21:36 +01001934static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
Takashi Iwaiee423812005-11-17 14:21:36 +01001936 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 unsigned short val;
1938
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001939 val = !ucontrol->value.integer.value[0];
1940 if (ac97->spec.ad18xx.lo_as_master)
1941 val = !val;
1942 val = val ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1944 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1945}
1946
Takashi Iwaiee423812005-11-17 14:21:36 +01001947static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001949 static const char * const texts[3] = {"Off", "6 -> 4", "6 -> 2"};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02001951 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952}
1953
Takashi Iwaiee423812005-11-17 14:21:36 +01001954static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955{
Takashi Iwaiee423812005-11-17 14:21:36 +01001956 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 unsigned short val;
1958
1959 val = ac97->regs[AC97_AD_MISC];
1960 if (!(val & AC97_AD198X_DMIX1))
1961 ucontrol->value.enumerated.item[0] = 0;
1962 else
1963 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1964 return 0;
1965}
1966
Takashi Iwaiee423812005-11-17 14:21:36 +01001967static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Takashi Iwaiee423812005-11-17 14:21:36 +01001969 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 unsigned short val;
1971
1972 if (ucontrol->value.enumerated.item[0] > 2)
1973 return -EINVAL;
1974 if (ucontrol->value.enumerated.item[0] == 0)
1975 val = 0;
1976 else
1977 val = AC97_AD198X_DMIX1 |
1978 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1979 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1980 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1981}
1982
Takashi Iwaiee423812005-11-17 14:21:36 +01001983static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001984{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001985 unsigned short val = 0;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001986 /* clear LODIS if shared jack is to be used for Surround out */
Takashi Iwaie48d6d92008-05-29 08:16:56 +02001987 if (!ac97->spec.ad18xx.lo_as_master && is_shared_linein(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001988 val |= (1 << 12);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001989 /* clear CLDIS if shared jack is to be used for C/LFE out */
1990 if (is_shared_micin(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001991 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001992 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001993 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001994}
1995
Takashi Iwaiee423812005-11-17 14:21:36 +01001996static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 {
1998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1999 .name = "Exchange Front/Surround",
2000 .info = snd_ac97_ad1888_lohpsel_info,
2001 .get = snd_ac97_ad1888_lohpsel_get,
2002 .put = snd_ac97_ad1888_lohpsel_put
2003 },
Andres Salomon0bed7b22008-11-05 17:29:53 -05002004 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, AC97_AD_VREFD_SHIFT, 1, 1),
2005 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2,
2006 AC97_AD_HPFD_SHIFT, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
2008 {
2009 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2010 .name = "Downmix",
2011 .info = snd_ac97_ad1888_downmix_info,
2012 .get = snd_ac97_ad1888_downmix_get,
2013 .put = snd_ac97_ad1888_downmix_put
2014 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002015 AC97_SURROUND_JACK_MODE_CTL,
2016 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02002017
2018 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2019 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020};
2021
Takashi Iwaiee423812005-11-17 14:21:36 +01002022static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023{
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002024 if (!ac97->spec.ad18xx.lo_as_master) {
2025 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2026 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2027 "Master Surround Playback");
2028 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback",
2029 "Master Playback");
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
2032}
2033
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002034static const struct snd_ac97_build_ops patch_ad1888_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 .build_post_spdif = patch_ad198x_post_spdif,
2036 .build_specific = patch_ad1888_specific,
2037#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02002038 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002040 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041};
2042
Takashi Iwaiac519022007-02-22 12:58:27 +01002043static int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 unsigned short misc;
2046
2047 patch_ad1881(ac97);
2048 ac97->build_ops = &patch_ad1888_build_ops;
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002049
2050 /*
2051 * LO can be used as a real line-out on some devices,
2052 * and we need to revert the front/surround mixer switches
2053 */
2054 if (ac97->subsystem_vendor == 0x1043 &&
2055 ac97->subsystem_device == 0x1193) /* ASUS A9T laptop */
2056 ac97->spec.ad18xx.lo_as_master = 1;
2057
2058 misc = snd_ac97_read(ac97, AC97_AD_MISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 /* AD-compatible mode */
2060 /* Stereo mutes enabled */
Takashi Iwaie48d6d92008-05-29 08:16:56 +02002061 misc |= AC97_AD198X_MSPLT | AC97_AD198X_AC97NC;
2062 if (!ac97->spec.ad18xx.lo_as_master)
2063 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2064 /* it seems that most vendors connect line-out connector to
2065 * headphone out of AC'97
2066 */
2067 misc |= AC97_AD198X_LOSEL | AC97_AD198X_HPSEL;
2068
2069 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 ac97->flags |= AC97_STEREO_MUTES;
2071 return 0;
2072}
2073
Takashi Iwaiee423812005-11-17 14:21:36 +01002074static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 int err;
2077
2078 if ((err = patch_ad1888_specific(ac97)) < 0)
2079 return err;
2080 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2081}
2082
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002083static const struct snd_ac97_build_ops patch_ad1980_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 .build_post_spdif = patch_ad198x_post_spdif,
2085 .build_specific = patch_ad1980_specific,
2086#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002087 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02002089 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090};
2091
Takashi Iwaiac519022007-02-22 12:58:27 +01002092static int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
2094 patch_ad1888(ac97);
2095 ac97->build_ops = &patch_ad1980_build_ops;
2096 return 0;
2097}
2098
Randy Cushman6428ea12006-12-21 19:17:29 +01002099static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2100 struct snd_ctl_elem_info *uinfo)
2101{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002102 static const char * const texts[4] = {
2103 "High-Z", "3.7 V", "2.25 V", "0 V"
2104 };
Randy Cushman6428ea12006-12-21 19:17:29 +01002105
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002106 return snd_ctl_enum_info(uinfo, 1, 4, texts);
Randy Cushman6428ea12006-12-21 19:17:29 +01002107}
2108
2109static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
2110 struct snd_ctl_elem_value *ucontrol)
2111{
2112 static const int reg2ctrl[4] = {2, 0, 1, 3};
2113 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2114 unsigned short val;
2115 val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
2116 >> AC97_AD198X_VREF_SHIFT;
2117 ucontrol->value.enumerated.item[0] = reg2ctrl[val];
2118 return 0;
2119}
2120
2121static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
2122 struct snd_ctl_elem_value *ucontrol)
2123{
2124 static const int ctrl2reg[4] = {1, 2, 0, 3};
2125 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2126 unsigned short val;
2127
Takashi Iwai4e98d6a2007-11-15 15:58:13 +01002128 if (ucontrol->value.enumerated.item[0] > 3)
Randy Cushman6428ea12006-12-21 19:17:29 +01002129 return -EINVAL;
2130 val = ctrl2reg[ucontrol->value.enumerated.item[0]]
2131 << AC97_AD198X_VREF_SHIFT;
2132 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
2133 AC97_AD198X_VREF_MASK, val);
2134}
2135
Takashi Iwaiee423812005-11-17 14:21:36 +01002136static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Randy Cushman6428ea12006-12-21 19:17:29 +01002137 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2138 {
2139 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2140 .name = "Exchange Front/Surround",
2141 .info = snd_ac97_ad1888_lohpsel_info,
2142 .get = snd_ac97_ad1888_lohpsel_get,
2143 .put = snd_ac97_ad1888_lohpsel_put
2144 },
2145 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
2146 AC97_SINGLE("Spread Front to Surround and Center/LFE",
2147 AC97_AD_MISC, 7, 1, 0),
2148 {
2149 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2150 .name = "Downmix",
2151 .info = snd_ac97_ad1888_downmix_info,
2152 .get = snd_ac97_ad1888_downmix_get,
2153 .put = snd_ac97_ad1888_downmix_put
2154 },
2155 {
2156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2157 .name = "V_REFOUT",
2158 .info = snd_ac97_ad1985_vrefout_info,
2159 .get = snd_ac97_ad1985_vrefout_get,
2160 .put = snd_ac97_ad1985_vrefout_put
2161 },
2162 AC97_SURROUND_JACK_MODE_CTL,
2163 AC97_CHANNEL_MODE_CTL,
2164
2165 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2166 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167};
2168
Takashi Iwaiee423812005-11-17 14:21:36 +01002169static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002170{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002171 ad1888_update_jacks(ac97);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002172 /* clear OMS if shared jack is to be used for C/LFE out */
Takashi Iwaifc232c62005-05-27 10:42:45 +02002173 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002174 is_shared_micin(ac97) ? 1 << 9 : 0);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002175}
2176
Takashi Iwaiee423812005-11-17 14:21:36 +01002177static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 int err;
2180
Randy Cushman6428ea12006-12-21 19:17:29 +01002181 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2182 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2183 "Master Surround Playback");
2184 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2185
2186 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 return err;
Randy Cushman6428ea12006-12-21 19:17:29 +01002188
2189 return patch_build_controls(ac97, snd_ac97_ad1985_controls,
2190 ARRAY_SIZE(snd_ac97_ad1985_controls));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002193static const struct snd_ac97_build_ops patch_ad1985_build_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 .build_post_spdif = patch_ad198x_post_spdif,
2195 .build_specific = patch_ad1985_specific,
2196#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002197 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002199 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200};
2201
Takashi Iwaiac519022007-02-22 12:58:27 +01002202static int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
2204 unsigned short misc;
2205
2206 patch_ad1881(ac97);
2207 ac97->build_ops = &patch_ad1985_build_ops;
2208 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2209 /* switch front/surround line-out/hp-out */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 /* AD-compatible mode */
2211 /* Stereo mutes enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 AC97_AD198X_LOSEL |
2214 AC97_AD198X_HPSEL |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 AC97_AD198X_MSPLT |
2216 AC97_AD198X_AC97NC);
2217 ac97->flags |= AC97_STEREO_MUTES;
Randy Cushman6428ea12006-12-21 19:17:29 +01002218
2219 /* update current jack configuration */
2220 ad1985_update_jacks(ac97);
2221
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2223 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2224 return 0;
2225}
2226
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002227#define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002228
2229static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
2230 struct snd_ctl_elem_value *ucontrol)
2231{
2232 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2233 unsigned short val;
2234
2235 val = ac97->regs[AC97_AD_MISC3];
2236 ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
2237 return 0;
2238}
2239
2240static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
2241 struct snd_ctl_elem_value *ucontrol)
2242{
2243 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2244 int ret0;
2245 int ret1;
2246 int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
2247
2248 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
2249 ucontrol->value.integer.value[0] != 0
2250 ? AC97_AD1986_LOSEL : 0);
2251 if (ret0 < 0)
2252 return ret0;
2253
2254 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2255 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2256 (ucontrol->value.integer.value[0] != 0
2257 || sprd)
2258 ? AC97_AD1986_SOSEL : 0);
2259 if (ret1 < 0)
2260 return ret1;
2261
2262 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2263}
2264
2265static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
2266 struct snd_ctl_elem_value *ucontrol)
2267{
2268 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2269 unsigned short val;
2270
2271 val = ac97->regs[AC97_AD_MISC];
2272 ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
2273 return 0;
2274}
2275
2276static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
2277 struct snd_ctl_elem_value *ucontrol)
2278{
2279 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2280 int ret0;
2281 int ret1;
2282 int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
2283
2284 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
2285 ucontrol->value.integer.value[0] != 0
2286 ? AC97_AD1986_SPRD : 0);
2287 if (ret0 < 0)
2288 return ret0;
2289
2290 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2291 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2292 (ucontrol->value.integer.value[0] != 0
2293 || sprd)
2294 ? AC97_AD1986_SOSEL : 0);
2295 if (ret1 < 0)
2296 return ret1;
2297
2298 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2299}
2300
2301static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
2302 struct snd_ctl_elem_value *ucontrol)
2303{
2304 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2305
2306 ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
2307 return 0;
2308}
2309
2310static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
2311 struct snd_ctl_elem_value *ucontrol)
2312{
2313 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2314 unsigned char swap = ucontrol->value.integer.value[0] != 0;
2315
2316 if (swap != ac97->spec.ad18xx.swap_mic_linein) {
2317 ac97->spec.ad18xx.swap_mic_linein = swap;
2318 if (ac97->build_ops->update_jacks)
2319 ac97->build_ops->update_jacks(ac97);
2320 return 1;
2321 }
2322 return 0;
2323}
2324
2325static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
2326 struct snd_ctl_elem_value *ucontrol)
2327{
2328 /* Use MIC_1/2 V_REFOUT as the "get" value */
2329 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2330 unsigned short val;
2331 unsigned short reg = ac97->regs[AC97_AD_MISC2];
2332 if ((reg & AC97_AD1986_MVREF0) != 0)
2333 val = 2;
2334 else if ((reg & AC97_AD1986_MVREF1) != 0)
2335 val = 3;
2336 else if ((reg & AC97_AD1986_MVREF2) != 0)
2337 val = 1;
2338 else
2339 val = 0;
2340 ucontrol->value.enumerated.item[0] = val;
2341 return 0;
2342}
2343
2344static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
2345 struct snd_ctl_elem_value *ucontrol)
2346{
2347 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2348 unsigned short cval;
2349 unsigned short lval;
2350 unsigned short mval;
2351 int cret;
2352 int lret;
2353 int mret;
2354
2355 switch (ucontrol->value.enumerated.item[0])
2356 {
2357 case 0: /* High-Z */
2358 cval = 0;
2359 lval = 0;
2360 mval = 0;
2361 break;
2362 case 1: /* 3.7 V */
2363 cval = AC97_AD1986_CVREF2;
2364 lval = AC97_AD1986_LVREF2;
2365 mval = AC97_AD1986_MVREF2;
2366 break;
2367 case 2: /* 2.25 V */
2368 cval = AC97_AD1986_CVREF0;
2369 lval = AC97_AD1986_LVREF0;
2370 mval = AC97_AD1986_MVREF0;
2371 break;
2372 case 3: /* 0 V */
2373 cval = AC97_AD1986_CVREF1;
2374 lval = AC97_AD1986_LVREF1;
2375 mval = AC97_AD1986_MVREF1;
2376 break;
2377 default:
2378 return -EINVAL;
2379 }
2380
2381 cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2382 AC97_AD1986_CVREF_MASK, cval);
2383 if (cret < 0)
2384 return cret;
2385 lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
2386 AC97_AD1986_LVREF_MASK, lval);
2387 if (lret < 0)
2388 return lret;
2389 mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2390 AC97_AD1986_MVREF_MASK, mval);
2391 if (mret < 0)
2392 return mret;
2393
2394 return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
2395}
2396
2397static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
2398 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2399 {
2400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2401 .name = "Exchange Front/Surround",
2402 .info = snd_ac97_ad1986_bool_info,
2403 .get = snd_ac97_ad1986_lososel_get,
2404 .put = snd_ac97_ad1986_lososel_put
2405 },
2406 {
2407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2408 .name = "Exchange Mic/Line In",
2409 .info = snd_ac97_ad1986_bool_info,
2410 .get = snd_ac97_ad1986_miclisel_get,
2411 .put = snd_ac97_ad1986_miclisel_put
2412 },
2413 {
2414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2415 .name = "Spread Front to Surround and Center/LFE",
2416 .info = snd_ac97_ad1986_bool_info,
2417 .get = snd_ac97_ad1986_spread_get,
2418 .put = snd_ac97_ad1986_spread_put
2419 },
2420 {
2421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2422 .name = "Downmix",
2423 .info = snd_ac97_ad1888_downmix_info,
2424 .get = snd_ac97_ad1888_downmix_get,
2425 .put = snd_ac97_ad1888_downmix_put
2426 },
2427 {
2428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2429 .name = "V_REFOUT",
2430 .info = snd_ac97_ad1985_vrefout_info,
2431 .get = snd_ac97_ad1986_vrefout_get,
2432 .put = snd_ac97_ad1986_vrefout_put
2433 },
2434 AC97_SURROUND_JACK_MODE_CTL,
2435 AC97_CHANNEL_MODE_CTL,
2436
2437 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2438 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
2439};
2440
2441static void ad1986_update_jacks(struct snd_ac97 *ac97)
2442{
2443 unsigned short misc_val = 0;
2444 unsigned short ser_val;
2445
2446 /* disable SURROUND and CENTER/LFE if not surround mode */
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002447 if (!is_surround_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002448 misc_val |= AC97_AD1986_SODIS;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002449 if (!is_clfe_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002450 misc_val |= AC97_AD1986_CLDIS;
2451
2452 /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2453 if (is_shared_linein(ac97))
2454 misc_val |= AC97_AD1986_LISEL_SURR;
2455 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2456 misc_val |= AC97_AD1986_LISEL_MIC;
2457 snd_ac97_update_bits(ac97, AC97_AD_MISC,
2458 AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
2459 AC97_AD1986_LISEL_MASK,
2460 misc_val);
2461
2462 /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2463 if (is_shared_micin(ac97))
2464 ser_val = AC97_AD1986_OMS_C;
2465 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2466 ser_val = AC97_AD1986_OMS_L;
2467 else
2468 ser_val = AC97_AD1986_OMS_M;
2469 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
2470 AC97_AD1986_OMS_MASK,
2471 ser_val);
2472}
2473
2474static int patch_ad1986_specific(struct snd_ac97 *ac97)
2475{
2476 int err;
2477
2478 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2479 return err;
2480
2481 return patch_build_controls(ac97, snd_ac97_ad1986_controls,
2482 ARRAY_SIZE(snd_ac97_ad1985_controls));
2483}
2484
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002485static const struct snd_ac97_build_ops patch_ad1986_build_ops = {
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002486 .build_post_spdif = patch_ad198x_post_spdif,
2487 .build_specific = patch_ad1986_specific,
2488#ifdef CONFIG_PM
2489 .resume = ad18xx_resume,
2490#endif
2491 .update_jacks = ad1986_update_jacks,
2492};
2493
Takashi Iwaiac519022007-02-22 12:58:27 +01002494static int patch_ad1986(struct snd_ac97 * ac97)
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002495{
2496 patch_ad1881(ac97);
2497 ac97->build_ops = &patch_ad1986_build_ops;
2498 ac97->flags |= AC97_STEREO_MUTES;
2499
2500 /* update current jack configuration */
2501 ad1986_update_jacks(ac97);
2502
2503 return 0;
2504}
2505
Takashi Iwai8f4f4ef2008-08-05 15:45:45 +02002506/*
2507 * realtek ALC203: use mono-out for pin 37
2508 */
2509static int patch_alc203(struct snd_ac97 *ac97)
2510{
2511 snd_ac97_update_bits(ac97, 0x7a, 0x400, 0x400);
2512 return 0;
2513}
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515/*
2516 * realtek ALC65x/850 codecs
2517 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002518static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002520 int shared;
2521
Randy Cushman831466f2006-12-19 18:42:16 +01002522 /* shared Line-In / Surround Out */
2523 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002524 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2525 shared ? (1 << 9) : 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002526 /* update shared Mic In / Center/LFE Out */
2527 shared = is_shared_clfeout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002528 /* disable/enable vref */
2529 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2530 shared ? (1 << 12) : 0);
2531 /* turn on/off center-on-mic */
2532 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2533 shared ? (1 << 10) : 0);
2534 /* GPIO0 high for mic */
2535 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2536 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
2538
Takashi Iwai833a4932012-08-03 17:59:36 +02002539static int alc650_swap_surround_put(struct snd_kcontrol *kcontrol,
2540 struct snd_ctl_elem_value *ucontrol)
2541{
2542 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2543 struct snd_pcm_chmap *map = ac97->chmaps[SNDRV_PCM_STREAM_PLAYBACK];
2544
2545 if (map) {
2546 if (ucontrol->value.integer.value[0])
2547 map->chmap = snd_pcm_std_chmaps;
2548 else
2549 map->chmap = snd_pcm_alt_chmaps;
2550 }
2551 return snd_ac97_put_volsw(kcontrol, ucontrol);
2552}
2553
Takashi Iwaiee423812005-11-17 14:21:36 +01002554static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2556 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2557 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2558 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2559 /* 4: Analog Input To Surround */
2560 /* 5: Analog Input To Center/LFE */
2561 /* 6: Independent Master Volume Right */
2562 /* 7: Independent Master Volume Left */
2563 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002564 /* 9: Line-In/Surround share */
2565 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 /* 11-13: in IEC958 controls */
Takashi Iwai833a4932012-08-03 17:59:36 +02002567 {
2568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2569 .name = "Swap Surround Slot",
2570 .info = snd_ac97_info_volsw,
2571 .get = snd_ac97_get_volsw,
2572 .put = alc650_swap_surround_put,
2573 .private_value = AC97_SINGLE_VALUE(AC97_ALC650_MULTICH, 14, 1, 0),
2574 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575#if 0 /* always set in patch_alc650 */
2576 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2577 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2578 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2579 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2580 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2581 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2582#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002583 AC97_SURROUND_JACK_MODE_CTL,
2584 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585};
2586
Takashi Iwaiee423812005-11-17 14:21:36 +01002587static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002588 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2590 /* disable this controls since it doesn't work as expected */
2591 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2592};
2593
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01002594static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002595
Takashi Iwaiee423812005-11-17 14:21:36 +01002596static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
2598 int err;
2599
2600 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2601 return err;
2602 if (ac97->ext_id & AC97_EI_SPDIF) {
2603 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2604 return err;
2605 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002606 if (ac97->id != AC97_ID_ALC650F)
2607 reset_tlv(ac97, "Master Playback Volume",
2608 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 return 0;
2610}
2611
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002612static const struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002613 .build_specific = patch_alc650_specific,
2614 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615};
2616
Takashi Iwaiac519022007-02-22 12:58:27 +01002617static int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
2619 unsigned short val;
2620
2621 ac97->build_ops = &patch_alc650_ops;
2622
2623 /* determine the revision */
2624 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2625 if (val < 3)
2626 ac97->id = 0x414c4720; /* Old version */
2627 else if (val < 0x10)
2628 ac97->id = 0x414c4721; /* D version */
2629 else if (val < 0x20)
2630 ac97->id = 0x414c4722; /* E version */
2631 else if (val < 0x30)
2632 ac97->id = 0x414c4723; /* F version */
2633
2634 /* revision E or F */
2635 /* FIXME: what about revision D ? */
2636 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2637 ac97->id == 0x414c4723);
2638
2639 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2640 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2641 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2642
2643 /* Enable SPDIF-IN only on Rev.E and above */
2644 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2645 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002646 if (ac97->spec.dev_flags &&
2647 /* ASUS A6KM requires EAPD */
2648 ! (ac97->subsystem_vendor == 0x1043 &&
2649 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 val |= 0x03; /* enable */
2651 else
2652 val &= ~0x03; /* disable */
2653 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2654
2655 /* set default: slot 3,4,7,8,6,9
2656 spdif-in monitor off, analog-spdif off, spdif-in off
2657 center on mic off, surround on line-in off
2658 downmix off, duplicate front off
2659 */
2660 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2661
2662 /* set GPIO0 for mic bias */
2663 /* GPIO0 pin output, no interrupt, high */
2664 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2665 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2666 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2667 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2668
2669 /* full DAC volume */
2670 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2671 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2672 return 0;
2673}
2674
Takashi Iwaiee423812005-11-17 14:21:36 +01002675static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002677 int shared;
2678
Randy Cushman831466f2006-12-19 18:42:16 +01002679 /* shared Line-In / Surround Out */
2680 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002681 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2682 shared ? (1 << 9) : 0, 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002683 /* update shared Mic In / Center/LFE Out */
2684 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 /* misc control; vrefout disable */
2686 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002687 shared ? (1 << 12) : 0);
2688 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2689 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690}
2691
Takashi Iwaiee423812005-11-17 14:21:36 +01002692static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002694 AC97_SURROUND_JACK_MODE_CTL,
2695 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696};
2697
Takashi Iwaiee423812005-11-17 14:21:36 +01002698static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002700 static const char * const texts_655[3] = {
2701 "PCM", "Analog In", "IEC958 In"
2702 };
2703 static const char * const texts_658[4] = {
2704 "PCM", "Analog1 In", "Analog2 In", "IEC958 In"
2705 };
Takashi Iwaiee423812005-11-17 14:21:36 +01002706 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002708 if (ac97->spec.dev_flags)
2709 return snd_ctl_enum_info(uinfo, 1, 4, texts_658);
2710 else
2711 return snd_ctl_enum_info(uinfo, 1, 3, texts_655);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712}
2713
Takashi Iwaiee423812005-11-17 14:21:36 +01002714static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715{
Takashi Iwaiee423812005-11-17 14:21:36 +01002716 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 unsigned short val;
2718
2719 val = ac97->regs[AC97_ALC650_MULTICH];
2720 val = (val >> 12) & 3;
2721 if (ac97->spec.dev_flags && val == 3)
2722 val = 0;
2723 ucontrol->value.enumerated.item[0] = val;
2724 return 0;
2725}
2726
Takashi Iwaiee423812005-11-17 14:21:36 +01002727static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Takashi Iwaiee423812005-11-17 14:21:36 +01002729 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
2731 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2732 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2733 0);
2734}
2735
Takashi Iwaiee423812005-11-17 14:21:36 +01002736static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002737 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 /* disable this controls since it doesn't work as expected */
2739 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2740 {
2741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002742 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 .info = alc655_iec958_route_info,
2744 .get = alc655_iec958_route_get,
2745 .put = alc655_iec958_route_put,
2746 },
2747};
2748
Takashi Iwaiee423812005-11-17 14:21:36 +01002749static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750{
2751 int err;
2752
2753 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2754 return err;
2755 if (ac97->ext_id & AC97_EI_SPDIF) {
2756 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2757 return err;
2758 }
2759 return 0;
2760}
2761
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002762static const struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002763 .build_specific = patch_alc655_specific,
2764 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765};
2766
Takashi Iwaiac519022007-02-22 12:58:27 +01002767static int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
2769 unsigned int val;
2770
Takashi Iwaia5022b02005-09-02 14:03:05 +02002771 if (ac97->id == AC97_ID_ALC658) {
2772 ac97->spec.dev_flags = 1; /* ALC658 */
2773 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2774 ac97->id = AC97_ID_ALC658D;
2775 ac97->spec.dev_flags = 2;
2776 }
2777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
2779 ac97->build_ops = &patch_alc655_ops;
2780
2781 /* assume only page 0 for writing cache */
2782 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2783
2784 /* adjust default values */
2785 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002786 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002788 else { /* ALC655 */
2789 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002790 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
Jaroslav Kyselae7d24f02006-10-05 09:30:36 +02002791 ac97->subsystem_device == 0x0161 || /* LG K1 Express */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002792 ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
Takashi Iwai592a82e2007-03-12 11:33:32 +01002793 ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002794 ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002795 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2796 else
2797 val |= (1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaic872e8c2008-08-12 13:39:01 +02002798 /* this seems missing on some hardwares */
2799 ac97->ext_id |= AC97_EI_SPDIF;
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 val &= ~(1 << 12); /* vref enable */
2802 snd_ac97_write_cache(ac97, 0x7a, val);
2803 /* set default: spdif-in enabled,
2804 spdif-in monitor off, spdif-in PCM off
2805 center on mic off, surround on line-in off
2806 duplicate front off
2807 */
2808 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2809
2810 /* full DAC volume */
2811 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2812 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002813
2814 /* update undocumented bit... */
2815 if (ac97->id == AC97_ID_ALC658D)
2816 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2817
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 return 0;
2819}
2820
2821
2822#define AC97_ALC850_JACK_SELECT 0x76
2823#define AC97_ALC850_MISC1 0x7a
Takashi Iwai4235a312008-02-18 12:23:13 +01002824#define AC97_ALC850_MULTICH 0x6a
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
Takashi Iwaiee423812005-11-17 14:21:36 +01002826static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002828 int shared;
Takashi Iwai4235a312008-02-18 12:23:13 +01002829 int aux_is_back_surround;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002830
Randy Cushman831466f2006-12-19 18:42:16 +01002831 /* shared Line-In / Surround Out */
2832 shared = is_shared_surrout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 /* SURR 1kOhm (bit4), Amp (bit5) */
2834 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002835 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002837 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2838 shared ? (2<<12) : (0<<12));
Randy Cushman831466f2006-12-19 18:42:16 +01002839 /* update shared Mic In / Center/LFE Out */
2840 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 /* Vref disable (bit12), 1kOhm (bit13) */
2842 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002843 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002844 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002845 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002846 shared ? (5<<4) : (1<<4));
Takashi Iwai4235a312008-02-18 12:23:13 +01002847
2848 aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2849 /* Aux is Back Surround */
2850 snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2851 aux_is_back_surround ? (1<<10) : (0<<10));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852}
2853
Takashi Iwaiee423812005-11-17 14:21:36 +01002854static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002856 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002857 AC97_SURROUND_JACK_MODE_CTL,
Takashi Iwai4235a312008-02-18 12:23:13 +01002858 AC97_CHANNEL_MODE_8CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859};
2860
Takashi Iwaiee423812005-11-17 14:21:36 +01002861static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862{
2863 int err;
2864
2865 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2866 return err;
2867 if (ac97->ext_id & AC97_EI_SPDIF) {
2868 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2869 return err;
2870 }
2871 return 0;
2872}
2873
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002874static const struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002875 .build_specific = patch_alc850_specific,
2876 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877};
2878
Takashi Iwaiac519022007-02-22 12:58:27 +01002879static int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880{
2881 ac97->build_ops = &patch_alc850_ops;
2882
2883 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
Takashi Iwai4235a312008-02-18 12:23:13 +01002884 ac97->flags |= AC97_HAS_8CH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886 /* assume only page 0 for writing cache */
2887 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2888
2889 /* adjust default values */
2890 /* set default: spdif-in enabled,
2891 spdif-in monitor off, spdif-in PCM off
2892 center on mic off, surround on line-in off
2893 duplicate front off
Takashi Iwai4235a312008-02-18 12:23:13 +01002894 NB default bit 10=0 = Aux is Capture, not Back Surround
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 */
2896 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2897 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2898 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2899 */
2900 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2901 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2902 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2903 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2904 */
2905 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2906 (1<<11)|(0<<12)|(1<<15));
2907
2908 /* full DAC volume */
2909 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2910 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2911 return 0;
2912}
2913
Andreas Mohr6ba92562011-02-19 00:49:48 +01002914static int patch_aztech_azf3328_specific(struct snd_ac97 *ac97)
2915{
2916 struct snd_kcontrol *kctl_3d_center =
2917 snd_ac97_find_mixer_ctl(ac97, "3D Control - Center");
2918 struct snd_kcontrol *kctl_3d_depth =
2919 snd_ac97_find_mixer_ctl(ac97, "3D Control - Depth");
2920
2921 /*
2922 * 3D register is different from AC97 standard layout
2923 * (also do some renaming, to resemble Windows driver naming)
2924 */
2925 if (kctl_3d_center) {
2926 kctl_3d_center->private_value =
2927 AC97_SINGLE_VALUE(AC97_3D_CONTROL, 1, 0x07, 0);
2928 snd_ac97_rename_vol_ctl(ac97,
2929 "3D Control - Center", "3D Control - Width"
2930 );
2931 }
2932 if (kctl_3d_depth)
2933 kctl_3d_depth->private_value =
2934 AC97_SINGLE_VALUE(AC97_3D_CONTROL, 8, 0x03, 0);
2935
2936 /* Aztech Windows driver calls the
2937 equivalent control "Modem Playback", thus rename it: */
2938 snd_ac97_rename_vol_ctl(ac97,
2939 "Master Mono Playback", "Modem Playback"
2940 );
2941 snd_ac97_rename_vol_ctl(ac97,
2942 "Headphone Playback", "FM Synth Playback"
2943 );
2944
2945 return 0;
2946}
2947
2948static const struct snd_ac97_build_ops patch_aztech_azf3328_ops = {
2949 .build_specific = patch_aztech_azf3328_specific
2950};
2951
2952static int patch_aztech_azf3328(struct snd_ac97 *ac97)
2953{
2954 ac97->build_ops = &patch_aztech_azf3328_ops;
2955 return 0;
2956}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
2958/*
2959 * C-Media CM97xx codecs
2960 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002961static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002962{
Randy Cushman831466f2006-12-19 18:42:16 +01002963 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002964 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002965 is_shared_surrout(ac97) ? (1 << 10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002966}
2967
Takashi Iwaiee423812005-11-17 14:21:36 +01002968static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002970 AC97_SURROUND_JACK_MODE_CTL,
2971 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972};
2973
Takashi Iwaiee423812005-11-17 14:21:36 +01002974static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975{
2976 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2977}
2978
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01002979static const struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002980 .build_specific = patch_cm9738_specific,
2981 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982};
2983
Takashi Iwaiac519022007-02-22 12:58:27 +01002984static int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985{
2986 ac97->build_ops = &patch_cm9738_ops;
2987 /* FIXME: can anyone confirm below? */
2988 /* CM9738 has no PCM volume although the register reacts */
2989 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2990 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2991
2992 return 0;
2993}
2994
Takashi Iwaiee423812005-11-17 14:21:36 +01002995static 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 -07002996{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002997 static const char * const texts[] = { "Analog", "Digital" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02002999 return snd_ctl_enum_info(uinfo, 1, 2, texts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000}
3001
Takashi Iwaiee423812005-11-17 14:21:36 +01003002static 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 -07003003{
Takashi Iwaiee423812005-11-17 14:21:36 +01003004 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 unsigned short val;
3006
3007 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
3008 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
3009 return 0;
3010}
3011
Takashi Iwaiee423812005-11-17 14:21:36 +01003012static 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 -07003013{
Takashi Iwaiee423812005-11-17 14:21:36 +01003014 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
3016 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
3017 0x01 << 1,
3018 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
3019}
3020
Takashi Iwaiee423812005-11-17 14:21:36 +01003021static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 /* BIT 0: SPDI_EN - always true */
3023 { /* BIT 1: SPDIFS */
3024 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3025 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3026 .info = snd_ac97_cmedia_spdif_playback_source_info,
3027 .get = snd_ac97_cmedia_spdif_playback_source_get,
3028 .put = snd_ac97_cmedia_spdif_playback_source_put,
3029 },
3030 /* BIT 2: IG_SPIV */
3031 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
3032 /* BIT 3: SPI2F */
3033 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
3034 /* BIT 4: SPI2SDI */
3035 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
3036 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
3037};
3038
Takashi Iwaiee423812005-11-17 14:21:36 +01003039static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040{
Randy Cushman831466f2006-12-19 18:42:16 +01003041 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003042 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01003043 is_shared_surrout(ac97) ? (1 << 10) : 0);
3044 /* shared Mic In / Center/LFE Out **/
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003045 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
Randy Cushman831466f2006-12-19 18:42:16 +01003046 is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047}
3048
Takashi Iwaiee423812005-11-17 14:21:36 +01003049static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003050 AC97_SURROUND_JACK_MODE_CTL,
3051 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052};
3053
Takashi Iwaiee423812005-11-17 14:21:36 +01003054static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055{
3056 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
3057}
3058
Takashi Iwaiee423812005-11-17 14:21:36 +01003059static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
3061 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
3062}
3063
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003064static const struct snd_ac97_build_ops patch_cm9739_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003066 .build_post_spdif = patch_cm9739_post_spdif,
3067 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068};
3069
Takashi Iwaiac519022007-02-22 12:58:27 +01003070static int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071{
3072 unsigned short val;
3073
3074 ac97->build_ops = &patch_cm9739_ops;
3075
3076 /* CM9739/A has no Master and PCM volume although the register reacts */
3077 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
3078 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
3079 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
3080
3081 /* check spdif */
3082 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
3083 if (val & AC97_EA_SPCV) {
3084 /* enable spdif in */
3085 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3086 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
3087 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3088 } else {
3089 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
3090 ac97->rates[AC97_RATES_SPDIF] = 0;
3091 }
3092
3093 /* set-up multi channel */
3094 /* bit 14: 0 = SPDIF, 1 = EAPD */
3095 /* bit 13: enable internal vref output for mic */
Masahiro Yamada08a7e622017-02-27 14:28:41 -08003096 /* bit 12: disable center/lfe (switchable) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 /* bit 10: disable surround/line (switchable) */
3098 /* bit 9: mix 2 surround off */
3099 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
3100 /* bit 3: undocumented; surround? */
3101 /* bit 0: dB */
3102 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
3103 val |= (1 << 3);
3104 val |= (1 << 13);
3105 if (! (ac97->ext_id & AC97_EI_SPDIF))
3106 val |= (1 << 14);
3107 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
3108
3109 /* FIXME: set up GPIO */
3110 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3111 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3112 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3113 if (ac97->pci &&
3114 ac97->subsystem_vendor == 0x1043 &&
3115 ac97->subsystem_device == 0x1843) {
3116 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3117 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
3118 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
3119 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
3120 }
3121
3122 return 0;
3123}
3124
3125#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003126#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127#define AC97_CM9761_SPDIF_CTRL 0x6c
3128
Takashi Iwaiee423812005-11-17 14:21:36 +01003129static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003131 /* FIXME: check the bits for each model
3132 * model 83 is confirmed to work
3133 */
3134 static unsigned short surr_on[3][2] = {
3135 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3136 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3137 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003139 static unsigned short clfe_on[3][2] = {
3140 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3141 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3142 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003144 static unsigned short surr_shared[3][2] = {
3145 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3146 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3147 { 0x0000, 0x0400 }, /* 9761-83 */
3148 };
3149 static unsigned short clfe_shared[3][2] = {
3150 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3151 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3152 { 0x2000, 0x0800 }, /* 9761-83 */
3153 };
3154 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003155
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003156 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
3157 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
Randy Cushman831466f2006-12-19 18:42:16 +01003158 val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3159 val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003160
3161 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162}
3163
Takashi Iwaiee423812005-11-17 14:21:36 +01003164static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003165 AC97_SURROUND_JACK_MODE_CTL,
3166 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167};
3168
Takashi Iwaiee423812005-11-17 14:21:36 +01003169static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003170{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003171 static const char * const texts[] = { "AC-Link", "ADC", "SPDIF-In" };
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003172
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003173 return snd_ctl_enum_info(uinfo, 1, 3, texts);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003174}
3175
Takashi Iwaiee423812005-11-17 14:21:36 +01003176static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003177{
Takashi Iwaiee423812005-11-17 14:21:36 +01003178 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003179
3180 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
3181 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
3182 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
3183 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
3184 else
3185 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
3186 return 0;
3187}
3188
Takashi Iwaiee423812005-11-17 14:21:36 +01003189static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003190{
Takashi Iwaiee423812005-11-17 14:21:36 +01003191 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003192
3193 if (ucontrol->value.enumerated.item[0] == 2)
3194 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
3195 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
3196 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
3197 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3198}
3199
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003200static const char * const cm9761_dac_clock[] = {
3201 "AC-Link", "SPDIF-In", "Both"
3202};
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003203static const struct ac97_enum cm9761_dac_clock_enum =
3204 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3205
Takashi Iwaiee423812005-11-17 14:21:36 +01003206static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003207 { /* BIT 1: SPDIFS */
3208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3209 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3210 .info = cm9761_spdif_out_source_info,
3211 .get = cm9761_spdif_out_source_get,
3212 .put = cm9761_spdif_out_source_put,
3213 },
3214 /* BIT 2: IG_SPIV */
3215 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
3216 /* BIT 3: SPI2F */
3217 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
3218 /* BIT 4: SPI2SDI */
3219 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
3220 /* BIT 9-10: DAC_CTL */
3221 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
3222};
3223
Takashi Iwaiee423812005-11-17 14:21:36 +01003224static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003225{
3226 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
3227}
3228
Takashi Iwaiee423812005-11-17 14:21:36 +01003229static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230{
3231 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
3232}
3233
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003234static const struct snd_ac97_build_ops patch_cm9761_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003236 .build_post_spdif = patch_cm9761_post_spdif,
3237 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238};
3239
Takashi Iwaiac519022007-02-22 12:58:27 +01003240static int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241{
3242 unsigned short val;
3243
3244 /* CM9761 has no PCM volume although the register reacts */
3245 /* Master volume seems to have _some_ influence on the analog
3246 * input sounds
3247 */
3248 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
3249 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
3250 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
3251
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003252 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 if (ac97->id == AC97_ID_CM9761_82) {
3254 unsigned short tmp;
3255 /* check page 1, reg 0x60 */
3256 val = snd_ac97_read(ac97, AC97_INT_PAGING);
3257 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
3258 tmp = snd_ac97_read(ac97, 0x60);
3259 ac97->spec.dev_flags = tmp & 1; /* revision B? */
3260 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003261 } else if (ac97->id == AC97_ID_CM9761_83)
3262 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 ac97->build_ops = &patch_cm9761_ops;
3265
3266 /* enable spdif */
3267 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3268 ac97->ext_id |= AC97_EI_SPDIF;
3269 /* to be sure: we overwrite the ext status bits */
3270 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
3271 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003272 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3274
3275 /* set-up multi channel */
3276 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003277 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003279 * bit 12: CLFE control (reverted on rev B)
3280 * bit 11: Mic/center share (reverted on rev B)
3281 * bit 10: suddound/line share
3282 * bit 9: Analog-in mix -> surround
3283 * bit 8: Analog-in mix -> CLFE
3284 * bit 7: Mic/LFE share (mic/center/lfe)
3285 * bit 5: vref select (9761A)
3286 * bit 4: front control
3287 * bit 3: surround control (revereted with rev B)
3288 * bit 2: front mic
3289 * bit 1: stereo mic
3290 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 */
3292
3293#if 0
3294 if (ac97->spec.dev_flags)
3295 val = 0x0214;
3296 else
3297 val = 0x321c;
3298#endif
3299 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
3300 val |= (1 << 4); /* front on */
3301 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
3302
3303 /* FIXME: set up GPIO */
3304 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3305 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3306
3307 return 0;
3308}
3309
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003310#define AC97_CM9780_SIDE 0x60
3311#define AC97_CM9780_JACK 0x62
3312#define AC97_CM9780_MIXER 0x64
3313#define AC97_CM9780_MULTI_CHAN 0x66
3314#define AC97_CM9780_SPDIF 0x6c
3315
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003316static const char * const cm9780_ch_select[] = {
3317 "Front", "Side", "Center/LFE", "Rear"
3318};
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003319static const struct ac97_enum cm9780_ch_select_enum =
3320 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01003321static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003322 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
3323 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
3324 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
3325};
3326
Takashi Iwaiee423812005-11-17 14:21:36 +01003327static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003328{
3329 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
3330}
3331
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003332static const struct snd_ac97_build_ops patch_cm9780_ops = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003333 .build_specific = patch_cm9780_specific,
3334 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
3335};
3336
Takashi Iwaiac519022007-02-22 12:58:27 +01003337static int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003338{
3339 unsigned short val;
3340
3341 ac97->build_ops = &patch_cm9780_ops;
3342
3343 /* enable spdif */
3344 if (ac97->ext_id & AC97_EI_SPDIF) {
3345 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3346 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
3347 val |= 0x1; /* SPDI_EN */
3348 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
3349 }
3350
3351 return 0;
3352}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
3354/*
Maciej S. Szmigierod6482282015-03-06 16:59:00 +01003355 * VIA VT1613 codec
3356 */
3357static const struct snd_kcontrol_new snd_ac97_controls_vt1613[] = {
3358AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3359};
3360
3361static int patch_vt1613_specific(struct snd_ac97 *ac97)
3362{
Fabio Estevam5371fc02015-03-06 13:41:42 -03003363 return patch_build_controls(ac97, &snd_ac97_controls_vt1613[0],
3364 ARRAY_SIZE(snd_ac97_controls_vt1613));
Maciej S. Szmigierod6482282015-03-06 16:59:00 +01003365};
3366
3367static const struct snd_ac97_build_ops patch_vt1613_ops = {
3368 .build_specific = patch_vt1613_specific
3369};
3370
3371static int patch_vt1613(struct snd_ac97 *ac97)
3372{
3373 ac97->build_ops = &patch_vt1613_ops;
3374
3375 ac97->flags |= AC97_HAS_NO_VIDEO;
3376 ac97->caps |= AC97_BC_HEADPHONE;
3377
3378 return 0;
3379}
3380
3381/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 * VIA VT1616 codec
3383 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003384static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3386AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3387AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3388AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3389};
3390
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003391static const char * const slave_vols_vt1616[] = {
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003392 "Front Playback Volume",
3393 "Surround Playback Volume",
3394 "Center Playback Volume",
3395 "LFE Playback Volume",
3396 NULL
3397};
3398
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003399static const char * const slave_sws_vt1616[] = {
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003400 "Front Playback Switch",
3401 "Surround Playback Switch",
3402 "Center Playback Switch",
3403 "LFE Playback Switch",
3404 NULL
3405};
3406
3407/* find a mixer control element with the given name */
3408static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
3409 const char *name)
3410{
3411 struct snd_ctl_elem_id id;
3412 memset(&id, 0, sizeof(id));
3413 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
3414 strcpy(id.name, name);
3415 return snd_ctl_find_id(ac97->bus->card, &id);
3416}
3417
3418/* create a virtual master control and add slaves */
Adrian Bunk13c21082008-07-22 20:21:32 +03003419static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003420 const unsigned int *tlv,
3421 const char * const *slaves)
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003422{
3423 struct snd_kcontrol *kctl;
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003424 const char * const *s;
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003425 int err;
3426
3427 kctl = snd_ctl_make_virtual_master(name, tlv);
3428 if (!kctl)
3429 return -ENOMEM;
3430 err = snd_ctl_add(ac97->bus->card, kctl);
3431 if (err < 0)
3432 return err;
3433
3434 for (s = slaves; *s; s++) {
3435 struct snd_kcontrol *sctl;
3436
3437 sctl = snd_ac97_find_mixer_ctl(ac97, *s);
3438 if (!sctl) {
Takashi Iwai38c16e32014-02-25 15:37:50 +01003439 dev_dbg(ac97->bus->card->dev,
3440 "Cannot find slave %s, skipped\n", *s);
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003441 continue;
3442 }
3443 err = snd_ctl_add_slave(kctl, sctl);
3444 if (err < 0)
3445 return err;
3446 }
3447 return 0;
3448}
3449
Takashi Iwaiee423812005-11-17 14:21:36 +01003450static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003452 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 int err;
3454
3455 if (snd_ac97_try_bit(ac97, 0x5a, 9))
3456 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
3457 return err;
3458 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
3459 return err;
Daniel Jacobowitz87af38d2008-05-07 12:05:10 +02003460
3461 /* There is already a misnamed master switch. Rename it. */
3462 kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
3463 if (!kctl)
3464 return -EINVAL;
3465
3466 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
3467
3468 err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
3469 kctl->tlv.p, slave_vols_vt1616);
3470 if (err < 0)
3471 return err;
3472
3473 err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
3474 NULL, slave_sws_vt1616);
3475 if (err < 0)
3476 return err;
3477
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 return 0;
3479}
3480
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003481static const struct snd_ac97_build_ops patch_vt1616_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 .build_specific = patch_vt1616_specific
3483};
3484
Takashi Iwaiac519022007-02-22 12:58:27 +01003485static int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486{
3487 ac97->build_ops = &patch_vt1616_ops;
3488 return 0;
3489}
3490
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003491/*
Philip Prindeville4b499482005-08-12 16:46:17 +02003492 * VT1617A codec
3493 */
John Utze9024cc2007-03-12 12:30:06 +01003494
3495/*
3496 * unfortunately, the vt1617a stashes the twiddlers required for
John L. Utz III9e285e12008-08-28 16:04:40 +02003497 * noodling the i/o jacks on 2 different regs. that means that we can't
John Utze9024cc2007-03-12 12:30:06 +01003498 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3499 * are own funcs.
3500 *
3501 * NB: this is absolutely and utterly different from the vt1618. dunno
3502 * about the 1616.
3503 */
3504
3505/* copied from ac97_surround_jack_mode_info() */
3506static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3507 struct snd_ctl_elem_info *uinfo)
Philip Prindeville4b499482005-08-12 16:46:17 +02003508{
John Utze9024cc2007-03-12 12:30:06 +01003509 /* ordering in this list reflects vt1617a docs for Reg 20 and
3510 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3511 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3512 * counter-intuitive */
3513
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003514 static const char * const texts[] = {"LineIn Mic1", "LineIn Mic1 Mic3",
John Utze9024cc2007-03-12 12:30:06 +01003515 "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3516 "LineIn Mic2", "LineIn Mic2 Mic1",
3517 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003518
3519 return snd_ctl_enum_info(uinfo, 1, 8, texts);
John Utze9024cc2007-03-12 12:30:06 +01003520}
3521
3522static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3523 struct snd_ctl_elem_value *ucontrol)
3524{
3525 ushort usSM51, usMS;
3526
3527 struct snd_ac97 *pac97;
3528
3529 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3530
John L. Utz III9e285e12008-08-28 16:04:40 +02003531 /* grab our desired bits, then mash them together in a manner
John Utze9024cc2007-03-12 12:30:06 +01003532 * consistent with Table 6 on page 17 in the 1617a docs */
3533
3534 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3535 usMS = snd_ac97_read(pac97, 0x20) >> 8;
3536
3537 ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3538
3539 return 0;
3540}
3541
3542static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3543 struct snd_ctl_elem_value *ucontrol)
3544{
3545 ushort usSM51, usMS, usReg;
3546
3547 struct snd_ac97 *pac97;
3548
3549 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3550
3551 usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3552 usMS = ucontrol->value.enumerated.item[0] & 1;
3553
3554 /* push our values into the register - consider that things will be left
3555 * in a funky state if the write fails */
3556
3557 usReg = snd_ac97_read(pac97, 0x7a);
3558 snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3559 usReg = snd_ac97_read(pac97, 0x20);
3560 snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
3561
3562 return 0;
3563}
3564
3565static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3566
3567 AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3568 /*
3569 * These are used to enable/disable surround sound on motherboards
3570 * that have 3 bidirectional analog jacks
3571 */
3572 {
3573 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3574 .name = "Smart 5.1 Select",
3575 .info = snd_ac97_vt1617a_smart51_info,
3576 .get = snd_ac97_vt1617a_smart51_get,
3577 .put = snd_ac97_vt1617a_smart51_put,
3578 },
3579};
3580
Harvey Harrisonb03671a2008-08-29 13:32:00 -07003581static int patch_vt1617a(struct snd_ac97 * ac97)
John Utze9024cc2007-03-12 12:30:06 +01003582{
3583 int err = 0;
Takashi Iwai2e75d052008-05-03 18:46:56 +02003584 int val;
John Utze9024cc2007-03-12 12:30:06 +01003585
3586 /* we choose to not fail out at this point, but we tell the
3587 caller when we return */
3588
3589 err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3590 ARRAY_SIZE(snd_ac97_controls_vt1617a));
3591
3592 /* bring analog power consumption to normal by turning off the
3593 * headphone amplifier, like WinXP driver for EPIA SP
Andrey Liakhovets9f458e72006-08-28 16:52:41 +02003594 */
Takashi Iwai2e75d052008-05-03 18:46:56 +02003595 /* We need to check the bit before writing it.
3596 * On some (many?) hardwares, setting bit actually clears it!
3597 */
3598 val = snd_ac97_read(ac97, 0x5c);
3599 if (!(val & 0x20))
3600 snd_ac97_write_cache(ac97, 0x5c, 0x20);
3601
Philip Prindeville4b499482005-08-12 16:46:17 +02003602 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3603 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
Daniel Jacobowitz9f428172007-01-12 19:11:47 +01003604 ac97->build_ops = &patch_vt1616_ops;
John Utze9024cc2007-03-12 12:30:06 +01003605
3606 return err;
Philip Prindeville4b499482005-08-12 16:46:17 +02003607}
3608
John L. Utz III9e285e12008-08-28 16:04:40 +02003609/* VIA VT1618 8 CHANNEL AC97 CODEC
3610 *
3611 * VIA implements 'Smart 5.1' completely differently on the 1618 than
3612 * it does on the 1617a. awesome! They seem to have sourced this
3613 * particular revision of the technology from somebody else, it's
3614 * called Universal Audio Jack and it shows up on some other folk's chips
3615 * as well.
3616 *
3617 * ordering in this list reflects vt1618 docs for Reg 60h and
3618 * the block diagram, DACs are as follows:
3619 *
3620 * OUT_O -> Front,
3621 * OUT_1 -> Surround,
3622 * OUT_2 -> C/LFE
3623 *
3624 * Unlike the 1617a, each OUT has a consistent set of mappings
3625 * for all bitpatterns other than 00:
3626 *
3627 * 01 Unmixed Output
3628 * 10 Line In
3629 * 11 Mic In
3630 *
3631 * Special Case of 00:
3632 *
3633 * OUT_0 Mixed Output
3634 * OUT_1 Reserved
3635 * OUT_2 Reserved
3636 *
3637 * I have no idea what the hell Reserved does, but on an MSI
3638 * CN700T, i have to set it to get 5.1 output - YMMV, bad
3639 * shit may happen.
3640 *
3641 * If other chips use Universal Audio Jack, then this code might be applicable
3642 * to them.
3643 */
3644
3645struct vt1618_uaj_item {
3646 unsigned short mask;
3647 unsigned short shift;
Takashi Iwai1bc10bb2014-10-21 08:51:45 +02003648 const char * const items[4];
John L. Utz III9e285e12008-08-28 16:04:40 +02003649};
3650
3651/* This list reflects the vt1618 docs for Vendor Defined Register 0x60. */
3652
3653static struct vt1618_uaj_item vt1618_uaj[3] = {
3654 {
3655 /* speaker jack */
3656 .mask = 0x03,
3657 .shift = 0,
3658 .items = {
3659 "Speaker Out", "DAC Unmixed Out", "Line In", "Mic In"
3660 }
3661 },
3662 {
3663 /* line jack */
3664 .mask = 0x0c,
3665 .shift = 2,
3666 .items = {
3667 "Surround Out", "DAC Unmixed Out", "Line In", "Mic In"
3668 }
3669 },
3670 {
3671 /* mic jack */
3672 .mask = 0x30,
3673 .shift = 4,
3674 .items = {
3675 "Center LFE Out", "DAC Unmixed Out", "Line In", "Mic In"
3676 },
3677 },
3678};
3679
3680static int snd_ac97_vt1618_UAJ_info(struct snd_kcontrol *kcontrol,
3681 struct snd_ctl_elem_info *uinfo)
3682{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003683 return snd_ctl_enum_info(uinfo, 1, 4,
3684 vt1618_uaj[kcontrol->private_value].items);
John L. Utz III9e285e12008-08-28 16:04:40 +02003685}
3686
3687/* All of the vt1618 Universal Audio Jack twiddlers are on
3688 * Vendor Defined Register 0x60, page 0. The bits, and thus
3689 * the mask, are the only thing that changes
3690 */
3691static int snd_ac97_vt1618_UAJ_get(struct snd_kcontrol *kcontrol,
3692 struct snd_ctl_elem_value *ucontrol)
3693{
3694 unsigned short datpag, uaj;
3695 struct snd_ac97 *pac97 = snd_kcontrol_chip(kcontrol);
3696
3697 mutex_lock(&pac97->page_mutex);
3698
3699 datpag = snd_ac97_read(pac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
3700 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, 0);
3701
3702 uaj = snd_ac97_read(pac97, 0x60) &
3703 vt1618_uaj[kcontrol->private_value].mask;
3704
3705 snd_ac97_update_bits(pac97, AC97_INT_PAGING, AC97_PAGE_MASK, datpag);
3706 mutex_unlock(&pac97->page_mutex);
3707
3708 ucontrol->value.enumerated.item[0] = uaj >>
3709 vt1618_uaj[kcontrol->private_value].shift;
3710
3711 return 0;
3712}
3713
3714static int snd_ac97_vt1618_UAJ_put(struct snd_kcontrol *kcontrol,
3715 struct snd_ctl_elem_value *ucontrol)
3716{
3717 return ac97_update_bits_page(snd_kcontrol_chip(kcontrol), 0x60,
3718 vt1618_uaj[kcontrol->private_value].mask,
3719 ucontrol->value.enumerated.item[0]<<
3720 vt1618_uaj[kcontrol->private_value].shift,
3721 0);
3722}
3723
3724/* config aux in jack - not found on 3 jack motherboards or soundcards */
3725
3726static int snd_ac97_vt1618_aux_info(struct snd_kcontrol *kcontrol,
3727 struct snd_ctl_elem_info *uinfo)
3728{
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003729 static const char * const txt_aux[] = {"Aux In", "Back Surr Out"};
John L. Utz III9e285e12008-08-28 16:04:40 +02003730
Takashi Iwai3b7a00d2014-10-20 18:15:36 +02003731 return snd_ctl_enum_info(uinfo, 1, 2, txt_aux);
John L. Utz III9e285e12008-08-28 16:04:40 +02003732}
3733
3734static int snd_ac97_vt1618_aux_get(struct snd_kcontrol *kcontrol,
3735 struct snd_ctl_elem_value *ucontrol)
3736{
3737 ucontrol->value.enumerated.item[0] =
3738 (snd_ac97_read(snd_kcontrol_chip(kcontrol), 0x5c) & 0x0008)>>3;
3739 return 0;
3740}
3741
3742static int snd_ac97_vt1618_aux_put(struct snd_kcontrol *kcontrol,
3743 struct snd_ctl_elem_value *ucontrol)
3744{
3745 /* toggle surround rear dac power */
3746
3747 snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x5c, 0x0008,
3748 ucontrol->value.enumerated.item[0] << 3);
3749
3750 /* toggle aux in surround rear out jack */
3751
3752 return snd_ac97_update_bits(snd_kcontrol_chip(kcontrol), 0x76, 0x0008,
3753 ucontrol->value.enumerated.item[0] << 3);
3754}
3755
3756static const struct snd_kcontrol_new snd_ac97_controls_vt1618[] = {
3757 AC97_SINGLE("Exchange Center/LFE", 0x5a, 8, 1, 0),
3758 AC97_SINGLE("DC Offset", 0x5a, 10, 1, 0),
3759 AC97_SINGLE("Soft Mute", 0x5c, 0, 1, 1),
3760 AC97_SINGLE("Headphone Amp", 0x5c, 5, 1, 1),
3761 AC97_DOUBLE("Back Surr Volume", 0x5e, 8, 0, 31, 1),
3762 AC97_SINGLE("Back Surr Switch", 0x5e, 15, 1, 1),
3763 {
3764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3765 .name = "Speaker Jack Mode",
3766 .info = snd_ac97_vt1618_UAJ_info,
3767 .get = snd_ac97_vt1618_UAJ_get,
3768 .put = snd_ac97_vt1618_UAJ_put,
3769 .private_value = 0
3770 },
3771 {
3772 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3773 .name = "Line Jack Mode",
3774 .info = snd_ac97_vt1618_UAJ_info,
3775 .get = snd_ac97_vt1618_UAJ_get,
3776 .put = snd_ac97_vt1618_UAJ_put,
3777 .private_value = 1
3778 },
3779 {
3780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3781 .name = "Mic Jack Mode",
3782 .info = snd_ac97_vt1618_UAJ_info,
3783 .get = snd_ac97_vt1618_UAJ_get,
3784 .put = snd_ac97_vt1618_UAJ_put,
3785 .private_value = 2
3786 },
3787 {
3788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3789 .name = "Aux Jack Mode",
3790 .info = snd_ac97_vt1618_aux_info,
3791 .get = snd_ac97_vt1618_aux_get,
3792 .put = snd_ac97_vt1618_aux_put,
3793 }
3794};
3795
Harvey Harrisonb03671a2008-08-29 13:32:00 -07003796static int patch_vt1618(struct snd_ac97 *ac97)
John L. Utz III9e285e12008-08-28 16:04:40 +02003797{
3798 return patch_build_controls(ac97, snd_ac97_controls_vt1618,
3799 ARRAY_SIZE(snd_ac97_controls_vt1618));
3800}
3801
Philip Prindeville4b499482005-08-12 16:46:17 +02003802/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003803 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003804static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003805{
Randy Cushman831466f2006-12-19 18:42:16 +01003806 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003807 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
Randy Cushman831466f2006-12-19 18:42:16 +01003808 is_shared_surrout(ac97) ? (1<<9) : 0);
3809 /* shared Mic / Center/LFE Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003810 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01003811 is_shared_clfeout(ac97) ? (1<<10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003812}
3813
Takashi Iwaiee423812005-11-17 14:21:36 +01003814static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003815 AC97_SURROUND_JACK_MODE_CTL,
3816 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817};
3818
Takashi Iwaiee423812005-11-17 14:21:36 +01003819static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02003820 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3822 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3823};
3824
Takashi Iwaiee423812005-11-17 14:21:36 +01003825static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826{
3827 int err;
3828 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
3829 return err;
3830 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
3831 return err;
3832 return 0;
3833}
3834
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003835static const struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003836 .build_specific = patch_it2646_specific,
3837 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838};
3839
Takashi Iwaiac519022007-02-22 12:58:27 +01003840static int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841{
3842 ac97->build_ops = &patch_it2646_ops;
3843 /* full DAC volume */
3844 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
3845 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
3846 return 0;
3847}
3848
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003849/*
3850 * Si3036 codec
3851 */
3852
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003854#define AC97_SI3036_LINE_CFG 0x5c
3855
Takashi Iwaiee423812005-11-17 14:21:36 +01003856static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003857AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3858};
3859
Takashi Iwaiee423812005-11-17 14:21:36 +01003860static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003861{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02003862 int idx, err;
3863 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
3864 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
3865 return err;
3866 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003867}
3868
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003869static const struct snd_ac97_build_ops patch_si3036_ops = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003870 .build_specific = patch_si3036_specific,
3871};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
Takashi Iwaiac519022007-02-22 12:58:27 +01003873static int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003875 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
3877 snd_ac97_write_cache(ac97, 0x68, 0);
3878 return 0;
3879}
Charl Coetzeeba224292006-02-09 11:48:21 +01003880
3881/*
3882 * LM 4550 Codec
3883 *
3884 * We use a static resolution table since LM4550 codec cannot be
3885 * properly autoprobed to determine the resolution via
3886 * check_volume_resolution().
3887 */
3888
3889static struct snd_ac97_res_table lm4550_restbl[] = {
3890 { AC97_MASTER, 0x1f1f },
3891 { AC97_HEADPHONE, 0x1f1f },
3892 { AC97_MASTER_MONO, 0x001f },
3893 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
3894 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01003895 { AC97_MIC, 0x001f },
3896 { AC97_LINE, 0x1f1f },
3897 { AC97_CD, 0x1f1f },
3898 { AC97_VIDEO, 0x1f1f },
3899 { AC97_AUX, 0x1f1f },
3900 { AC97_PCM, 0x1f1f },
3901 { AC97_REC_GAIN, 0x0f0f },
3902 { } /* terminator */
3903};
3904
Takashi Iwaiac519022007-02-22 12:58:27 +01003905static int patch_lm4550(struct snd_ac97 *ac97)
Charl Coetzeeba224292006-02-09 11:48:21 +01003906{
3907 ac97->res_table = lm4550_restbl;
3908 return 0;
3909}
Mike Rapoport82466ad2006-06-29 17:15:33 +02003910
3911/*
3912 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3913 */
3914static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
3915/* enable/disable headphone driver which allows direct connection to
3916 stereo headphone without the use of external DC blocking
3917 capacitors */
3918AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3919/* Filter used to compensate the DC offset is added in the ADC to remove idle
3920 tones from the audio band. */
3921AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3922/* Control smart-low-power mode feature. Allows automatic power down
3923 of unused blocks in the ADC analog front end and the PLL. */
3924AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3925};
3926
3927static int patch_ucb1400_specific(struct snd_ac97 * ac97)
3928{
3929 int idx, err;
3930 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
3931 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
3932 return err;
3933 return 0;
3934}
3935
Hanno Boeck3e8b3b92011-01-14 19:14:47 +01003936static const struct snd_ac97_build_ops patch_ucb1400_ops = {
Mike Rapoport82466ad2006-06-29 17:15:33 +02003937 .build_specific = patch_ucb1400_specific,
3938};
3939
Takashi Iwaiac519022007-02-22 12:58:27 +01003940static int patch_ucb1400(struct snd_ac97 * ac97)
Mike Rapoport82466ad2006-06-29 17:15:33 +02003941{
3942 ac97->build_ops = &patch_ucb1400_ops;
3943 /* enable headphone driver and smart low power mode by default */
Mike Rapoport25552e82008-07-02 13:19:23 +03003944 snd_ac97_write_cache(ac97, 0x6a, 0x0050);
3945 snd_ac97_write_cache(ac97, 0x6c, 0x0030);
Mike Rapoport82466ad2006-06-29 17:15:33 +02003946 return 0;
3947}