blob: 075ac4e14bcb96bd0c5392a5c42deec5379786bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * 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/*
30 * Chip specific initialization
31 */
32
Takashi Iwaiee423812005-11-17 14:21:36 +010033static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 int idx, err;
36
37 for (idx = 0; idx < count; idx++)
38 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
39 return err;
40 return 0;
41}
42
Takashi Iwai2f3482f2006-08-21 18:44:31 +020043/* replace with a new TLV */
44static void reset_tlv(struct snd_ac97 *ac97, const char *name,
Takashi Iwai0cb29ea2007-01-29 15:33:49 +010045 const unsigned int *tlv)
Takashi Iwai2f3482f2006-08-21 18:44:31 +020046{
47 struct snd_ctl_elem_id sid;
48 struct snd_kcontrol *kctl;
49 memset(&sid, 0, sizeof(sid));
50 strcpy(sid.name, name);
51 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
52 kctl = snd_ctl_find_id(ac97->bus->card, &sid);
53 if (kctl && kctl->tlv.p)
54 kctl->tlv.p = tlv;
55}
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* set to the page, update bits and restore the page */
Takashi Iwaiee423812005-11-17 14:21:36 +010058static 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 -070059{
60 unsigned short page_save;
61 int ret;
62
Ingo Molnar62932df2006-01-16 16:34:20 +010063 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
65 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
66 ret = snd_ac97_update_bits(ac97, reg, mask, value);
67 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
Ingo Molnar62932df2006-01-16 16:34:20 +010068 mutex_unlock(&ac97->page_mutex); /* unlock paging */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return ret;
70}
71
Takashi Iwaieb8caf32005-04-13 14:32:57 +020072/*
73 * shared line-in/mic controls
74 */
Takashi Iwaiee423812005-11-17 14:21:36 +010075static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
Takashi Iwaieb8caf32005-04-13 14:32:57 +020076 const char **texts, unsigned int nums)
77{
78 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
79 uinfo->count = 1;
80 uinfo->value.enumerated.items = nums;
81 if (uinfo->value.enumerated.item > nums - 1)
82 uinfo->value.enumerated.item = nums - 1;
83 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
84 return 0;
85}
86
Takashi Iwaiee423812005-11-17 14:21:36 +010087static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020088{
89 static const char *texts[] = { "Shared", "Independent" };
90 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
91}
92
Takashi Iwaiee423812005-11-17 14:21:36 +010093static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020094{
Takashi Iwaiee423812005-11-17 14:21:36 +010095 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020096
97 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
98 return 0;
99}
100
Takashi Iwaiee423812005-11-17 14:21:36 +0100101static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200102{
Takashi Iwaiee423812005-11-17 14:21:36 +0100103 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200104 unsigned char indep = !!ucontrol->value.enumerated.item[0];
105
106 if (indep != ac97->indep_surround) {
107 ac97->indep_surround = indep;
108 if (ac97->build_ops->update_jacks)
109 ac97->build_ops->update_jacks(ac97);
110 return 1;
111 }
112 return 0;
113}
114
Takashi Iwaiee423812005-11-17 14:21:36 +0100115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200116{
117 static const char *texts[] = { "2ch", "4ch", "6ch" };
118 if (kcontrol->private_value)
119 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
120 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
121}
122
Takashi Iwaiee423812005-11-17 14:21:36 +0100123static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200124{
Takashi Iwaiee423812005-11-17 14:21:36 +0100125 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200126
127 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
128 return 0;
129}
130
Takashi Iwaiee423812005-11-17 14:21:36 +0100131static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200132{
Takashi Iwaiee423812005-11-17 14:21:36 +0100133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200134 unsigned char mode = ucontrol->value.enumerated.item[0];
135
136 if (mode != ac97->channel_mode) {
137 ac97->channel_mode = mode;
138 if (ac97->build_ops->update_jacks)
139 ac97->build_ops->update_jacks(ac97);
140 return 1;
141 }
142 return 0;
143}
144
145#define AC97_SURROUND_JACK_MODE_CTL \
146 { \
147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
148 .name = "Surround Jack Mode", \
149 .info = ac97_surround_jack_mode_info, \
150 .get = ac97_surround_jack_mode_get, \
151 .put = ac97_surround_jack_mode_put, \
152 }
153#define AC97_CHANNEL_MODE_CTL \
154 { \
155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
156 .name = "Channel Mode", \
157 .info = ac97_channel_mode_info, \
158 .get = ac97_channel_mode_get, \
159 .put = ac97_channel_mode_put, \
160 }
161#define AC97_CHANNEL_MODE_4CH_CTL \
162 { \
163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
164 .name = "Channel Mode", \
165 .info = ac97_channel_mode_info, \
166 .get = ac97_channel_mode_get, \
167 .put = ac97_channel_mode_put, \
168 .private_value = 1, \
169 }
170
Takashi Iwaiee423812005-11-17 14:21:36 +0100171static inline int is_surround_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200172{
173 return ac97->channel_mode >= 1;
174}
175
Takashi Iwaiee423812005-11-17 14:21:36 +0100176static inline int is_clfe_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200177{
Takashi Iwaieb9b4142005-09-13 18:39:21 +0200178 return ac97->channel_mode >= 2;
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200179}
180
Randy Cushman831466f2006-12-19 18:42:16 +0100181/* system has shared jacks with surround out enabled */
182static inline int is_shared_surrout(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200183{
Randy Cushman831466f2006-12-19 18:42:16 +0100184 return !ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200185}
186
Randy Cushman831466f2006-12-19 18:42:16 +0100187/* system has shared jacks with center/lfe out enabled */
188static inline int is_shared_clfeout(struct snd_ac97 *ac97)
189{
190 return !ac97->indep_surround && is_clfe_on(ac97);
191}
192
193/* system has shared jacks with line in enabled */
194static inline int is_shared_linein(struct snd_ac97 *ac97)
195{
196 return !ac97->indep_surround && !is_surround_on(ac97);
197}
198
199/* system has shared jacks with mic in enabled */
Takashi Iwaiee423812005-11-17 14:21:36 +0100200static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200201{
Randy Cushman831466f2006-12-19 18:42:16 +0100202 return !ac97->indep_surround && !is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200203}
204
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
207
Keita Maehara13043982007-09-19 14:27:38 +0200208/* It is possible to indicate to the Yamaha YMF7x3 the type of
209 speakers being used. */
210
211static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
214 static char *texts[3] = {
215 "Standard", "Small", "Smaller"
216 };
217
218 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
219 uinfo->count = 1;
220 uinfo->value.enumerated.items = 3;
221 if (uinfo->value.enumerated.item > 2)
222 uinfo->value.enumerated.item = 2;
223 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
224 return 0;
225}
226
Keita Maehara13043982007-09-19 14:27:38 +0200227static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Takashi Iwaiee423812005-11-17 14:21:36 +0100230 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 unsigned short val;
232
Keita Maehara13043982007-09-19 14:27:38 +0200233 val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 val = (val >> 10) & 3;
235 if (val > 0) /* 0 = invalid */
236 val--;
237 ucontrol->value.enumerated.item[0] = val;
238 return 0;
239}
240
Keita Maehara13043982007-09-19 14:27:38 +0200241static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
242 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Takashi Iwaiee423812005-11-17 14:21:36 +0100244 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 unsigned short val;
246
247 if (ucontrol->value.enumerated.item[0] > 2)
248 return -EINVAL;
249 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
Keita Maehara13043982007-09-19 14:27:38 +0200250 return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
Keita Maehara13043982007-09-19 14:27:38 +0200253static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
256 .name = "3D Control - Speaker",
Keita Maehara13043982007-09-19 14:27:38 +0200257 .info = snd_ac97_ymf7x3_info_speaker,
258 .get = snd_ac97_ymf7x3_get_speaker,
259 .put = snd_ac97_ymf7x3_put_speaker,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Keita Maehara13043982007-09-19 14:27:38 +0200262/* It is possible to indicate to the Yamaha YMF7x3 the source to
263 direct to the S/PDIF output. */
264static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
267 static char *texts[2] = { "AC-Link", "A/D Converter" };
268
269 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
270 uinfo->count = 1;
271 uinfo->value.enumerated.items = 2;
272 if (uinfo->value.enumerated.item > 1)
273 uinfo->value.enumerated.item = 1;
274 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
275 return 0;
276}
277
Keita Maehara13043982007-09-19 14:27:38 +0200278static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Takashi Iwaiee423812005-11-17 14:21:36 +0100281 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 unsigned short val;
283
Keita Maehara13043982007-09-19 14:27:38 +0200284 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
286 return 0;
287}
288
Keita Maehara13043982007-09-19 14:27:38 +0200289static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Takashi Iwaiee423812005-11-17 14:21:36 +0100292 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 unsigned short val;
294
295 if (ucontrol->value.enumerated.item[0] > 1)
296 return -EINVAL;
297 val = ucontrol->value.enumerated.item[0] << 1;
Keita Maehara13043982007-09-19 14:27:38 +0200298 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
301/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
302 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
303 By default, no output pin is selected, and the S/PDIF signal is not output.
304 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100305static 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 -0700306{
307 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
308
309 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
310 uinfo->count = 1;
311 uinfo->value.enumerated.items = 3;
312 if (uinfo->value.enumerated.item > 2)
313 uinfo->value.enumerated.item = 2;
314 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
315 return 0;
316}
317
Takashi Iwaiee423812005-11-17 14:21:36 +0100318static 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 -0700319{
Takashi Iwaiee423812005-11-17 14:21:36 +0100320 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 unsigned short val;
322
Keita Maehara13043982007-09-19 14:27:38 +0200323 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
325 return 0;
326}
327
Takashi Iwaiee423812005-11-17 14:21:36 +0100328static 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 -0700329{
Takashi Iwaiee423812005-11-17 14:21:36 +0100330 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 unsigned short val;
332
333 if (ucontrol->value.enumerated.item[0] > 2)
334 return -EINVAL;
335 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
336 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
Keita Maehara13043982007-09-19 14:27:38 +0200337 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
339 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
340}
341
Takashi Iwaiee423812005-11-17 14:21:36 +0100342static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 {
344 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
345 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Keita Maehara13043982007-09-19 14:27:38 +0200346 .info = snd_ac97_ymf7x3_spdif_source_info,
347 .get = snd_ac97_ymf7x3_spdif_source_get,
348 .put = snd_ac97_ymf7x3_spdif_source_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 },
350 {
351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
352 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
353 .info = snd_ac97_ymf753_spdif_output_pin_info,
354 .get = snd_ac97_ymf753_spdif_output_pin_get,
355 .put = snd_ac97_ymf753_spdif_output_pin_put,
356 },
Keita Maehara13043982007-09-19 14:27:38 +0200357 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
358 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
Keita Maehara13043982007-09-19 14:27:38 +0200361static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Takashi Iwaiee423812005-11-17 14:21:36 +0100363 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 int err;
365
Keita Maehara13043982007-09-19 14:27:38 +0200366 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
367 err = snd_ctl_add(ac97->bus->card, kctl);
368 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return err;
370 strcpy(kctl->id.name, "3D Control - Wide");
371 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
372 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
Keita Maehara13043982007-09-19 14:27:38 +0200373
374 err = snd_ctl_add(ac97->bus->card,
375 snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
376 ac97));
377 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return err;
Keita Maehara13043982007-09-19 14:27:38 +0200379 snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return 0;
381}
382
Takashi Iwaiee423812005-11-17 14:21:36 +0100383static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 int err;
386
387 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
388 return err;
389 return 0;
390}
391
392static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
Keita Maehara13043982007-09-19 14:27:38 +0200393 .build_3d = patch_yamaha_ymf7x3_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 .build_post_spdif = patch_yamaha_ymf753_post_spdif
395};
396
Takashi Iwaiac519022007-02-22 12:58:27 +0100397static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
400 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
401 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
402 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
403 By default, no output pin is selected, and the S/PDIF signal is not output.
404 There is also a bit to mute S/PDIF output in a vendor-specific register.
405 */
406 ac97->build_ops = &patch_yamaha_ymf753_ops;
407 ac97->caps |= AC97_BC_BASS_TREBLE;
408 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
409 return 0;
410}
411
412/*
413 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
414 * removed broken wolfson00 patch.
415 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
416 */
417
Takashi Iwaiee423812005-11-17 14:21:36 +0100418static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200419AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
420AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
421};
422
Takashi Iwaiee423812005-11-17 14:21:36 +0100423static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200426 * Randolph Bentson <bentson@holmsjoen.com>
427 * WM9703/9707/9708/9717
428 */
429 int err, i;
430
431 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
432 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
433 return err;
434 }
435 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
437}
Liam Girdwood3998b702005-07-29 11:41:55 +0200438
439static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
440 .build_specific = patch_wolfson_wm9703_specific,
441};
442
Takashi Iwaiac519022007-02-22 12:58:27 +0100443static int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200444{
445 ac97->build_ops = &patch_wolfson_wm9703_ops;
446 return 0;
447}
448
Takashi Iwaiee423812005-11-17 14:21:36 +0100449static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200450AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
451AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
452AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
453AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
454AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
455AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
456};
457
Takashi Iwaiee423812005-11-17 14:21:36 +0100458static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200459{
460 int err, i;
461 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
462 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
463 return err;
464 }
465 /* patch for DVD noise */
466 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
467 return 0;
468}
469
470static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
471 .build_specific = patch_wolfson_wm9704_specific,
472};
473
Takashi Iwaiac519022007-02-22 12:58:27 +0100474static int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Liam Girdwood3998b702005-07-29 11:41:55 +0200476 /* WM9704M/9704Q */
477 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return 0;
479}
Liam Girdwood3998b702005-07-29 11:41:55 +0200480
Takashi Iwaiee423812005-11-17 14:21:36 +0100481static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200482{
483 int err, i;
484 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
485 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
486 return err;
487 }
488 snd_ac97_write_cache(ac97, 0x72, 0x0808);
489 return 0;
490}
491
492static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
493 .build_specific = patch_wolfson_wm9705_specific,
494};
495
Takashi Iwaiac519022007-02-22 12:58:27 +0100496static int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Liam Girdwood3998b702005-07-29 11:41:55 +0200498 /* WM9705, WM9710 */
499 ac97->build_ops = &patch_wolfson_wm9705_ops;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200500#ifdef CONFIG_TOUCHSCREEN_WM9705
501 /* WM9705 touchscreen uses AUX and VIDEO for touch */
Liam Girdwood8f888202006-09-07 18:07:46 +0200502 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200503#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return 0;
505}
506
Liam Girdwood3998b702005-07-29 11:41:55 +0200507static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
508static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
509static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
510static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
511static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
512static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
513static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
514static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
515static const char* wm9711_rec_sel[] =
516 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
517static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
518
519static const struct ac97_enum wm9711_enum[] = {
520AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
521AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
522AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
523AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
524AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
525AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
526AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
527AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
528AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
529AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
530};
531
Takashi Iwaiee423812005-11-17 14:21:36 +0100532static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200533AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
534AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
535AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
536AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
537AC97_ENUM("ALC Function", wm9711_enum[0]),
538AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
539AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
540AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
541AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
542AC97_ENUM("ALC NG Type", wm9711_enum[9]),
543AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
544
545AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
546AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
547AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
548AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
549
550AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200551AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200552AC97_ENUM("Out3 Mux", wm9711_enum[2]),
553AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
554AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
555
556AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
557AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
558AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
559AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
560AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
561AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
562
563AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
564AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
565AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
566AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
567AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
568AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
569
570AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
571AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
572
573AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
574AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
575AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
576
577AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
578AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
579AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
580
581AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
582AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
583AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
584AC97_ENUM("Capture Select", wm9711_enum[8]),
585
586AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
587AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
588
589AC97_ENUM("Bass Control", wm9711_enum[5]),
590AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
591AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
592AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
593
594AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
595AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200596AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200597AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
598
599AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
600AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
601AC97_ENUM("Mic Select Source", wm9711_enum[7]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200602AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
603AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100604AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200605
606AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
607AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
608AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
609};
610
Takashi Iwaiee423812005-11-17 14:21:36 +0100611static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200612{
613 int err, i;
614
615 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
616 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
617 return err;
618 }
619 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
620 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
621 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
622 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
623 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
624 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
625 return 0;
626}
627
628static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
629 .build_specific = patch_wolfson_wm9711_specific,
630};
631
Takashi Iwaiac519022007-02-22 12:58:27 +0100632static int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Liam Girdwood3998b702005-07-29 11:41:55 +0200634 /* WM9711, WM9712 */
635 ac97->build_ops = &patch_wolfson_wm9711_ops;
636
637 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
638 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return 0;
641}
642
Liam Girdwood3998b702005-07-29 11:41:55 +0200643static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200645static const char* wm9713_rec_src[] =
646 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
647 "Mono Mix", "Zh"};
648static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
649static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
650static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
651static const char* wm9713_spk_pga[] =
652 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
653static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
654static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
655static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
656static const char* wm9713_dac_inv[] =
657 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
658 "Headphone Mix Mono", "NC", "Vmid"};
659static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
660static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662static const struct ac97_enum wm9713_enum[] = {
663AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
664AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
665AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200666AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
667AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
668AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
669AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
670AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
671AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
672AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
673AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
674AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
675AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
676AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677};
678
Takashi Iwaiee423812005-11-17 14:21:36 +0100679static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200681AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
682AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
683AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
684
685AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
686AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
687AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
688AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
689
690AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
691AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
692AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
693AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100694AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200695AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
696AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
697
698AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
699AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
700AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
701AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
702
703AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
704AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
705AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
706AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
707AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
708AC97_ENUM("Capture Select", wm9713_enum[3]),
709
710AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
711AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
712AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
713AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
714AC97_ENUM("ALC Function", wm9713_enum[5]),
715AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
716AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
717AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
718AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
719AC97_ENUM("ALC NG Type", wm9713_enum[13]),
720AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
721
722AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
723AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
724AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
725AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
726AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
727AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
728
729AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
730AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
731AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
732AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
733AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
734AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
735
736AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
737AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
738AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
739AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
740AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
741AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
742
743AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
744AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
745AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
746AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
747AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
748AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
749
750AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
751AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
752AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
753AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
754AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
755AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
756
757AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
758AC97_ENUM("Master Input Mux", wm9713_enum[7]),
759AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
760AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
761AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
762
763AC97_ENUM("Bass Control", wm9713_enum[12]),
764AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
765AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
766AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
767AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
768AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769};
770
Takashi Iwaiee423812005-11-17 14:21:36 +0100771static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200772AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
773AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
774AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
775AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776};
777
Takashi Iwaiee423812005-11-17 14:21:36 +0100778static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200779{
780 int err, i;
781
782 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
783 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
784 return err;
785 }
786 return 0;
787}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Takashi Iwaiee423812005-11-17 14:21:36 +0100789static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 int err, i;
792
Liam Girdwood3998b702005-07-29 11:41:55 +0200793 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
794 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 -0700795 return err;
796 }
797 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
800 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
803 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return 0;
805}
806
807#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100808static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
811 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
812}
813
Takashi Iwaiee423812005-11-17 14:21:36 +0100814static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
816 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
817 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
818 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
819}
820#endif
821
822static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
823 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200824 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825#ifdef CONFIG_PM
826 .suspend = patch_wolfson_wm9713_suspend,
827 .resume = patch_wolfson_wm9713_resume
828#endif
829};
830
Takashi Iwaiac519022007-02-22 12:58:27 +0100831static int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Liam Girdwood3998b702005-07-29 11:41:55 +0200833 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 ac97->build_ops = &patch_wolfson_wm9713_ops;
835
836 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200837 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
838 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200839 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
842 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
843 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
844
845 return 0;
846}
847
848/*
849 * Tritech codec
850 */
Takashi Iwaiac519022007-02-22 12:58:27 +0100851static int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 snd_ac97_write_cache(ac97, 0x26, 0x0300);
854 snd_ac97_write_cache(ac97, 0x26, 0x0000);
855 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
856 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
857 return 0;
858}
859
860/*
861 * Sigmatel STAC97xx codecs
862 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100863static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Takashi Iwaiee423812005-11-17 14:21:36 +0100865 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 int err;
867
868 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
869 return err;
870 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
871 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
872 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
873 return 0;
874}
875
Takashi Iwaiee423812005-11-17 14:21:36 +0100876static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Takashi Iwaiee423812005-11-17 14:21:36 +0100878 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 int err;
880
881 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
882 return err;
883 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
884 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
885 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
886 return err;
887 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
888 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
889 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
890 return 0;
891}
892
Takashi Iwaiee423812005-11-17 14:21:36 +0100893static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
895
Takashi Iwaiee423812005-11-17 14:21:36 +0100896static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
898
Takashi Iwaiee423812005-11-17 14:21:36 +0100899static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
901AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
902};
903
Takashi Iwaiee423812005-11-17 14:21:36 +0100904static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
906 int err;
907
908 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
909 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
910 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
911 return err;
912 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
913 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
914 return err;
915 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
916 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
917 return err;
918 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
919 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
920 return err;
921 return 0;
922}
923
924static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
925 .build_3d = patch_sigmatel_stac9700_3d,
926 .build_specific = patch_sigmatel_stac97xx_specific
927};
928
Takashi Iwaiac519022007-02-22 12:58:27 +0100929static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 ac97->build_ops = &patch_sigmatel_stac9700_ops;
932 return 0;
933}
934
Takashi Iwaiee423812005-11-17 14:21:36 +0100935static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Takashi Iwaiee423812005-11-17 14:21:36 +0100937 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 int err;
939
Ingo Molnar62932df2006-01-16 16:34:20 +0100940 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
942 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
943 (ucontrol->value.integer.value[0] & 1) << 4);
944 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100945 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 return err;
947}
948
Takashi Iwaiee423812005-11-17 14:21:36 +0100949static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
951 .name = "Sigmatel Output Bias Switch",
952 .info = snd_ac97_info_volsw,
953 .get = snd_ac97_get_volsw,
954 .put = snd_ac97_stac9708_put_bias,
955 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
956};
957
Takashi Iwaiee423812005-11-17 14:21:36 +0100958static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
960 int err;
961
James C Georgase4c3bf02006-12-19 11:09:41 +0100962 /* the register bit is writable, but the function is not implemented: */
963 snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
966 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
967 return err;
968 return patch_sigmatel_stac97xx_specific(ac97);
969}
970
971static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
972 .build_3d = patch_sigmatel_stac9708_3d,
973 .build_specific = patch_sigmatel_stac9708_specific
974};
975
Takashi Iwaiac519022007-02-22 12:58:27 +0100976static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
978 unsigned int codec72, codec6c;
979
980 ac97->build_ops = &patch_sigmatel_stac9708_ops;
981 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
982
983 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
984 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
985
986 if ((codec72==0) && (codec6c==0)) {
987 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
988 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
991 } else if ((codec72==0x8000) && (codec6c==0)) {
992 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
993 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
994 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
995 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
996 /* nothing */
997 }
998 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
999 return 0;
1000}
1001
Takashi Iwaiac519022007-02-22 12:58:27 +01001002static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1005 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1006 // patch for SigmaTel
1007 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1008 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1009 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1010 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1011 }
1012 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1013 return 0;
1014}
1015
Takashi Iwaiac519022007-02-22 12:58:27 +01001016static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
1018 // patch for SigmaTel
1019 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1020 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1021 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1022 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1023 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1024 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1025 return 0;
1026}
1027
Takashi Iwaiac519022007-02-22 12:58:27 +01001028static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029{
1030 // patch for SigmaTel
1031 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1032 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1033 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1034 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1035 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1036 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1037 return 0;
1038}
1039
Takashi Iwaiee423812005-11-17 14:21:36 +01001040static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 static char *texts[5] = { "Input/Disabled", "Front Output",
1043 "Rear Output", "Center/LFE Output", "Mixer Output" };
1044
1045 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1046 uinfo->count = 1;
1047 uinfo->value.enumerated.items = 5;
1048 if (uinfo->value.enumerated.item > 4)
1049 uinfo->value.enumerated.item = 4;
1050 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1051 return 0;
1052}
1053
Takashi Iwaiee423812005-11-17 14:21:36 +01001054static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Takashi Iwaiee423812005-11-17 14:21:36 +01001056 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 int shift = kcontrol->private_value;
1058 unsigned short val;
1059
1060 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1061 if (!(val & 4))
1062 ucontrol->value.enumerated.item[0] = 0;
1063 else
1064 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1065 return 0;
1066}
1067
Takashi Iwaiee423812005-11-17 14:21:36 +01001068static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Takashi Iwaiee423812005-11-17 14:21:36 +01001070 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 int shift = kcontrol->private_value;
1072 unsigned short val;
1073
1074 if (ucontrol->value.enumerated.item[0] > 4)
1075 return -EINVAL;
1076 if (ucontrol->value.enumerated.item[0] == 0)
1077 val = 0;
1078 else
1079 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1080 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1081 7 << shift, val << shift, 0);
1082}
1083
Takashi Iwaiee423812005-11-17 14:21:36 +01001084static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
1086 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1087 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1088
1089 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1090 uinfo->count = 1;
1091 uinfo->value.enumerated.items = 7;
1092 if (uinfo->value.enumerated.item > 6)
1093 uinfo->value.enumerated.item = 6;
1094 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1095 return 0;
1096}
1097
Takashi Iwaiee423812005-11-17 14:21:36 +01001098static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Takashi Iwaiee423812005-11-17 14:21:36 +01001100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 int shift = kcontrol->private_value;
1102 unsigned short val;
1103
1104 val = ac97->regs[AC97_SIGMATEL_INSEL];
1105 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1106 return 0;
1107}
1108
Takashi Iwaiee423812005-11-17 14:21:36 +01001109static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Takashi Iwaiee423812005-11-17 14:21:36 +01001111 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 int shift = kcontrol->private_value;
1113
1114 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1115 ucontrol->value.enumerated.item[0] << shift, 0);
1116}
1117
Takashi Iwaiee423812005-11-17 14:21:36 +01001118static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
1120 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1121
1122 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1123 uinfo->count = 1;
1124 uinfo->value.enumerated.items = 3;
1125 if (uinfo->value.enumerated.item > 2)
1126 uinfo->value.enumerated.item = 2;
1127 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1128 return 0;
1129}
1130
Takashi Iwaiee423812005-11-17 14:21:36 +01001131static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Takashi Iwaiee423812005-11-17 14:21:36 +01001133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1136 return 0;
1137}
1138
Takashi Iwaiee423812005-11-17 14:21:36 +01001139static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Takashi Iwaiee423812005-11-17 14:21:36 +01001141 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1144 ucontrol->value.enumerated.item[0], 0);
1145}
1146
1147#define STAC9758_OUTPUT_JACK(xname, shift) \
1148{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1149 .info = snd_ac97_stac9758_output_jack_info, \
1150 .get = snd_ac97_stac9758_output_jack_get, \
1151 .put = snd_ac97_stac9758_output_jack_put, \
1152 .private_value = shift }
1153#define STAC9758_INPUT_JACK(xname, shift) \
1154{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1155 .info = snd_ac97_stac9758_input_jack_info, \
1156 .get = snd_ac97_stac9758_input_jack_get, \
1157 .put = snd_ac97_stac9758_input_jack_put, \
1158 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001159static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1161 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1162 STAC9758_OUTPUT_JACK("Front Jack", 7),
1163 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1164 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1165 STAC9758_INPUT_JACK("Mic Input Source", 0),
1166 STAC9758_INPUT_JACK("Line Input Source", 8),
1167 {
1168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169 .name = "Headphone Amp",
1170 .info = snd_ac97_stac9758_phonesel_info,
1171 .get = snd_ac97_stac9758_phonesel_get,
1172 .put = snd_ac97_stac9758_phonesel_put
1173 },
1174 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1175 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1176};
1177
Takashi Iwaiee423812005-11-17 14:21:36 +01001178static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
1180 int err;
1181
1182 err = patch_sigmatel_stac97xx_specific(ac97);
1183 if (err < 0)
1184 return err;
1185 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1186 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1187 if (err < 0)
1188 return err;
1189 /* DAC-A direct */
1190 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1191 /* DAC-A to Mix = PCM */
1192 /* DAC-B direct = Surround */
1193 /* DAC-B to Mix */
1194 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1195 /* DAC-C direct = Center/LFE */
1196
1197 return 0;
1198}
1199
1200static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1201 .build_3d = patch_sigmatel_stac9700_3d,
1202 .build_specific = patch_sigmatel_stac9758_specific
1203};
1204
Takashi Iwaiac519022007-02-22 12:58:27 +01001205static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
1207 static unsigned short regs[4] = {
1208 AC97_SIGMATEL_OUTSEL,
1209 AC97_SIGMATEL_IOMISC,
1210 AC97_SIGMATEL_INSEL,
1211 AC97_SIGMATEL_VARIOUS
1212 };
1213 static unsigned short def_regs[4] = {
1214 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1215 /* IOMISC */ 0x2001,
1216 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1217 /* VARIOUS */ 0x0040
1218 };
1219 static unsigned short m675_regs[4] = {
1220 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1221 /* IOMISC */ 0x2102, /* HP amp on */
1222 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1223 /* VARIOUS */ 0x0041 /* stereo mic */
1224 };
1225 unsigned short *pregs = def_regs;
1226 int i;
1227
1228 /* Gateway M675 notebook */
1229 if (ac97->pci &&
1230 ac97->subsystem_vendor == 0x107b &&
1231 ac97->subsystem_device == 0x0601)
1232 pregs = m675_regs;
1233
1234 // patch for SigmaTel
1235 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1236 /* FIXME: assume only page 0 for writing cache */
1237 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1238 for (i = 0; i < 4; i++)
1239 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1240
1241 ac97->flags |= AC97_STEREO_MUTES;
1242 return 0;
1243}
1244
1245/*
1246 * Cirrus Logic CS42xx codecs
1247 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001248static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1250 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1251};
1252
Takashi Iwaiee423812005-11-17 14:21:36 +01001253static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
1255 int err;
1256
1257 /* con mask, pro mask, default */
1258 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1259 return err;
1260 /* switch, spsa */
1261 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1262 return err;
1263 switch (ac97->id & AC97_ID_CS_MASK) {
1264 case AC97_ID_CS4205:
1265 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1266 return err;
1267 break;
1268 }
1269 /* set default PCM S/PDIF params */
1270 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1271 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1272 return 0;
1273}
1274
1275static struct snd_ac97_build_ops patch_cirrus_ops = {
1276 .build_spdif = patch_cirrus_build_spdif
1277};
1278
Takashi Iwaiac519022007-02-22 12:58:27 +01001279static int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
1281 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1282 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1283 - sp/dif EA ID is not set, but sp/dif is always present.
1284 - enable/disable is spdif register bit 15.
1285 - sp/dif control register is 0x68. differs from AC97:
1286 - valid is bit 14 (vs 15)
1287 - no DRS
1288 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1289 - sp/dif ssource select is in 0x5e bits 0,1.
1290 */
1291
1292 ac97->build_ops = &patch_cirrus_ops;
1293 ac97->flags |= AC97_CS_SPDIF;
1294 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1295 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1296 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1297 return 0;
1298}
1299
Takashi Iwaiac519022007-02-22 12:58:27 +01001300static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 /* force the detection of PC Beep */
1303 ac97->flags |= AC97_HAS_PC_BEEP;
1304
1305 return patch_cirrus_spdif(ac97);
1306}
1307
1308/*
1309 * Conexant codecs
1310 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001311static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1313};
1314
Takashi Iwaiee423812005-11-17 14:21:36 +01001315static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 int err;
1318
1319 /* con mask, pro mask, default */
1320 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1321 return err;
1322 /* switch */
1323 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1324 return err;
1325 /* set default PCM S/PDIF params */
1326 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1327 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1328 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1329 return 0;
1330}
1331
1332static struct snd_ac97_build_ops patch_conexant_ops = {
1333 .build_spdif = patch_conexant_build_spdif
1334};
1335
Takashi Iwaiac519022007-02-22 12:58:27 +01001336static int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
1338 ac97->build_ops = &patch_conexant_ops;
1339 ac97->flags |= AC97_CX_SPDIF;
1340 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1341 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1342 return 0;
1343}
1344
Takashi Iwaiac519022007-02-22 12:58:27 +01001345static int patch_cx20551(struct snd_ac97 *ac97)
Takashi Iwai9e292c02007-02-09 12:42:03 +01001346{
1347 snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
1348 return 0;
1349}
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351/*
1352 * Analog Device AD18xx, AD19xx codecs
1353 */
1354#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001355static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
1357 static unsigned short setup_regs[] = {
1358 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1359 };
1360 int i, codec;
1361
1362 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1363 unsigned short reg = setup_regs[i];
1364 if (test_bit(reg, ac97->reg_accessed)) {
1365 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1366 snd_ac97_read(ac97, reg);
1367 }
1368 }
1369
1370 if (! (ac97->flags & AC97_AD_MULTI))
1371 /* normal restore */
1372 snd_ac97_restore_status(ac97);
1373 else {
1374 /* restore the AD18xx codec configurations */
1375 for (codec = 0; codec < 3; codec++) {
1376 if (! ac97->spec.ad18xx.id[codec])
1377 continue;
1378 /* select single codec */
1379 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1380 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1381 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1382 }
1383 /* select all codecs */
1384 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1385
1386 /* restore status */
1387 for (i = 2; i < 0x7c ; i += 2) {
1388 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1389 continue;
1390 if (test_bit(i, ac97->reg_accessed)) {
1391 /* handle multi codecs for AD18xx */
1392 if (i == AC97_PCM) {
1393 for (codec = 0; codec < 3; codec++) {
1394 if (! ac97->spec.ad18xx.id[codec])
1395 continue;
1396 /* select single codec */
1397 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1398 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1399 /* update PCM bits */
1400 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1401 }
1402 /* select all codecs */
1403 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1404 continue;
1405 } else if (i == AC97_AD_TEST ||
1406 i == AC97_AD_CODEC_CFG ||
1407 i == AC97_AD_SERIAL_CFG)
1408 continue; /* ignore */
1409 }
1410 snd_ac97_write(ac97, i, ac97->regs[i]);
1411 snd_ac97_read(ac97, i);
1412 }
1413 }
1414
1415 snd_ac97_restore_iec958(ac97);
1416}
Jaya Kumar1561f092006-06-19 15:06:14 +02001417
1418static void ad1888_resume(struct snd_ac97 *ac97)
1419{
1420 ad18xx_resume(ac97);
1421 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1422}
1423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424#endif
1425
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001426static const struct snd_ac97_res_table ad1819_restbl[] = {
1427 { AC97_PHONE, 0x9f1f },
1428 { AC97_MIC, 0x9f1f },
1429 { AC97_LINE, 0x9f1f },
1430 { AC97_CD, 0x9f1f },
1431 { AC97_VIDEO, 0x9f1f },
1432 { AC97_AUX, 0x9f1f },
1433 { AC97_PCM, 0x9f1f },
1434 { } /* terminator */
1435};
1436
Takashi Iwaiac519022007-02-22 12:58:27 +01001437static int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
1439 unsigned short scfg;
1440
1441 // patch for Analog Devices
1442 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1443 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001444 ac97->res_table = ad1819_restbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return 0;
1446}
1447
Takashi Iwaiee423812005-11-17 14:21:36 +01001448static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
1450 unsigned short val;
1451
1452 // test for unchained codec
1453 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1454 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1455 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1456 if ((val & 0xff40) != 0x5340)
1457 return 0;
1458 ac97->spec.ad18xx.unchained[idx] = mask;
1459 ac97->spec.ad18xx.id[idx] = val;
1460 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1461 return mask;
1462}
1463
Takashi Iwaiee423812005-11-17 14:21:36 +01001464static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
1466 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1467 unsigned short val;
1468
1469 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1470 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1471 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1472 if ((val & 0xff40) != 0x5340)
1473 return 0;
1474 if (codec_bits)
1475 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1476 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1477 ac97->spec.ad18xx.id[idx] = val;
1478 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1479 return 1;
1480}
1481
Takashi Iwaiee423812005-11-17 14:21:36 +01001482static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
1484 // already detected?
1485 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1486 cidx1 = -1;
1487 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1488 cidx2 = -1;
1489 if (cidx1 < 0 && cidx2 < 0)
1490 return;
1491 // test for chained codecs
1492 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1493 ac97->spec.ad18xx.unchained[unchained_idx]);
1494 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1495 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1496 if (cidx1 >= 0) {
Takashi Iwaic19bcdc2006-11-08 15:48:43 +01001497 if (cidx2 < 0)
1498 patch_ad1881_chained1(ac97, cidx1, 0);
1499 else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 patch_ad1881_chained1(ac97, cidx2, 0);
1501 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1502 patch_ad1881_chained1(ac97, cidx1, 0);
1503 } else if (cidx2 >= 0) {
1504 patch_ad1881_chained1(ac97, cidx2, 0);
1505 }
1506}
1507
1508static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1509#ifdef CONFIG_PM
1510 .resume = ad18xx_resume
1511#endif
1512};
1513
Takashi Iwaiac519022007-02-22 12:58:27 +01001514static int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 static const char cfg_idxs[3][2] = {
1517 {2, 1},
1518 {0, 2},
1519 {0, 1}
1520 };
1521
1522 // patch for Analog Devices
1523 unsigned short codecs[3];
1524 unsigned short val;
1525 int idx, num;
1526
1527 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1528 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1529 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1530 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1531 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1532
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001533 if (! (codecs[0] || codecs[1] || codecs[2]))
1534 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 for (idx = 0; idx < 3; idx++)
1537 if (ac97->spec.ad18xx.unchained[idx])
1538 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1539
1540 if (ac97->spec.ad18xx.id[1]) {
1541 ac97->flags |= AC97_AD_MULTI;
1542 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1543 }
1544 if (ac97->spec.ad18xx.id[2]) {
1545 ac97->flags |= AC97_AD_MULTI;
1546 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1547 }
1548
1549 __end:
1550 /* select all codecs */
1551 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1552 /* check if only one codec is present */
1553 for (idx = num = 0; idx < 3; idx++)
1554 if (ac97->spec.ad18xx.id[idx])
1555 num++;
1556 if (num == 1) {
1557 /* ok, deselect all ID bits */
1558 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1559 ac97->spec.ad18xx.codec_cfg[0] =
1560 ac97->spec.ad18xx.codec_cfg[1] =
1561 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1562 }
1563 /* required for AD1886/AD1885 combination */
1564 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1565 if (ac97->spec.ad18xx.id[0]) {
1566 ac97->id &= 0xffff0000;
1567 ac97->id |= ac97->spec.ad18xx.id[0];
1568 }
1569 ac97->build_ops = &patch_ad1881_build_ops;
1570 return 0;
1571}
1572
Takashi Iwaiee423812005-11-17 14:21:36 +01001573static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1575 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1576 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1577 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1578 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1579 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1580};
1581
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001582static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001583
Takashi Iwaiee423812005-11-17 14:21:36 +01001584static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
1586 int err;
1587
1588 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1589 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001590 reset_tlv(ac97, "Headphone Playback Volume",
1591 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return 0;
1593}
1594
1595static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1596 .build_specific = &patch_ad1885_specific,
1597#ifdef CONFIG_PM
1598 .resume = ad18xx_resume
1599#endif
1600};
1601
Takashi Iwaiac519022007-02-22 12:58:27 +01001602static int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
1604 patch_ad1881(ac97);
1605 /* This is required to deal with the Intel D815EEAL2 */
1606 /* i.e. Line out is actually headphone out from codec */
1607
1608 /* set default */
1609 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1610
1611 ac97->build_ops = &patch_ad1885_build_ops;
1612 return 0;
1613}
1614
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001615static int patch_ad1886_specific(struct snd_ac97 * ac97)
1616{
1617 reset_tlv(ac97, "Headphone Playback Volume",
1618 db_scale_6bit_6db_max);
1619 return 0;
1620}
1621
1622static struct snd_ac97_build_ops patch_ad1886_build_ops = {
1623 .build_specific = &patch_ad1886_specific,
1624#ifdef CONFIG_PM
1625 .resume = ad18xx_resume
1626#endif
1627};
1628
Takashi Iwaiac519022007-02-22 12:58:27 +01001629static int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630{
1631 patch_ad1881(ac97);
1632 /* Presario700 workaround */
1633 /* for Jack Sense/SPDIF Register misetting causing */
1634 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001635 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 return 0;
1637}
1638
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001639/* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640#define AC97_AD198X_MBC 0x0003 /* mic boost */
1641#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1642#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1643#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1644#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
Randy Cushman6428ea12006-12-21 19:17:29 +01001645#define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1646#define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1647#define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1648#define AC97_AD198X_VREF_SHIFT 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1650#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1651#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1652#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
Randy Cushman6428ea12006-12-21 19:17:29 +01001653#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1654 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1656#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1657#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1658#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1659#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1660#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1661#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1662
Randy Cushman67e9f4b2006-12-22 12:44:25 +01001663/* MISC 1 bits (AD1986 register 0x76) */
1664#define AC97_AD1986_MBC 0x0003 /* mic boost */
1665#define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1666#define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1667#define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1668#define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1669#define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1670#define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1671#define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1672#define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1673#define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1674#define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1675#define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1676#define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1677#define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1678#define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1679 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1680#define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1681#define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1682#define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1683#define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1684#define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1685#define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1686
1687/* MISC 2 bits (AD1986 register 0x70) */
1688#define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1689
1690#define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1691#define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1692#define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1693#define AC97_AD1986_CVREF_MASK \
1694 (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1695#define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1696#define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1697#define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1698#define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1699#define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1700#define AC97_AD1986_MVREF_MASK \
1701 (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1702
1703/* MISC 3 bits (AD1986 register 0x7a) */
1704#define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1705
1706#define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1707#define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1708#define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1709#define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1710#define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1711#define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1712#define AC97_AD1986_LVREF_MASK \
1713 (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1714#define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1715#define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1716#define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1717 /* input select Surround DACs */
1718#define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1719 /* select C/LFE DACs */
1720#define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1721
1722/* Serial Config bits (AD1986 register 0x74) (incomplete) */
1723#define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1724#define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1725#define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1726#define AC97_AD1986_OMS_MASK \
1727 (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1728#define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1729#define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1730#define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1731#define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1732 /* are MIC sources */
1733#define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1734 /* are MIC sources */
1735#define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1736 /* are MIC sources */
1737#define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1738 /* are MIC sources */
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Takashi Iwaiee423812005-11-17 14:21:36 +01001741static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
1743 static char *texts[2] = { "AC-Link", "A/D Converter" };
1744
1745 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1746 uinfo->count = 1;
1747 uinfo->value.enumerated.items = 2;
1748 if (uinfo->value.enumerated.item > 1)
1749 uinfo->value.enumerated.item = 1;
1750 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1751 return 0;
1752}
1753
Takashi Iwaiee423812005-11-17 14:21:36 +01001754static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Takashi Iwaiee423812005-11-17 14:21:36 +01001756 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 unsigned short val;
1758
1759 val = ac97->regs[AC97_AD_SERIAL_CFG];
1760 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1761 return 0;
1762}
1763
Takashi Iwaiee423812005-11-17 14:21:36 +01001764static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
Takashi Iwaiee423812005-11-17 14:21:36 +01001766 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 unsigned short val;
1768
1769 if (ucontrol->value.enumerated.item[0] > 1)
1770 return -EINVAL;
1771 val = ucontrol->value.enumerated.item[0] << 2;
1772 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1773}
1774
Takashi Iwaiee423812005-11-17 14:21:36 +01001775static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1778 .info = snd_ac97_ad198x_spdif_source_info,
1779 .get = snd_ac97_ad198x_spdif_source_get,
1780 .put = snd_ac97_ad198x_spdif_source_put,
1781};
1782
Takashi Iwaiee423812005-11-17 14:21:36 +01001783static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1786}
1787
Takashi Iwaiee423812005-11-17 14:21:36 +01001788static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1790 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1791};
1792
Takashi Iwai128a46a2006-01-11 18:15:43 +01001793/* black list to avoid HP/Line jack-sense controls
1794 * (SS vendor << 16 | device)
1795 */
1796static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia31e8c72007-02-22 12:47:25 +01001797 0x10140523, /* Thinkpad R40 */
1798 0x10140534, /* Thinkpad X31 */
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001799 0x10140537, /* Thinkpad T41p */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001800 0x10140554, /* Thinkpad T42p/R50p */
Daniel T Chen8286c532007-05-15 11:46:23 +02001801 0x10140567, /* Thinkpad T43p 2668-G7U */
1802 0x10140581, /* Thinkpad X41-2527 */
1803 0x104380b0, /* Asus A7V8X-MX */
1804 0x11790241, /* Toshiba Satellite A-15 S127 */
1805 0x144dc01a, /* Samsung NP-X20C004/SEG */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001806 0 /* end */
1807};
1808
1809static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1810{
1811 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1812 for (; *list; list++)
1813 if (*list == subid)
1814 return 1;
1815 return 0;
1816}
1817
Takashi Iwaiee423812005-11-17 14:21:36 +01001818static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001820 if (check_list(ac97, ad1981_jacks_blacklist))
1821 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1823 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1824}
1825
1826static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1827 .build_post_spdif = patch_ad198x_post_spdif,
1828 .build_specific = patch_ad1981a_specific,
1829#ifdef CONFIG_PM
1830 .resume = ad18xx_resume
1831#endif
1832};
1833
Takashi Iwai128a46a2006-01-11 18:15:43 +01001834/* white list to enable HP jack-sense bits
1835 * (SS vendor << 16 | device)
1836 */
1837static unsigned int ad1981_jacks_whitelist[] = {
1838 0x0e11005a, /* HP nc4000/4010 */
1839 0x103c0890, /* HP nc6000 */
1840 0x103c0938, /* HP nc4220 */
1841 0x103c099c, /* HP nx6110 */
1842 0x103c0944, /* HP nc6220 */
1843 0x103c0934, /* HP nc8220 */
1844 0x103c006d, /* HP nx9105 */
1845 0x17340088, /* FSC Scenic-W */
1846 0 /* end */
1847};
1848
Takashi Iwaiee423812005-11-17 14:21:36 +01001849static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001851 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* enable headphone jack sense */
1853 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
Takashi Iwaiac519022007-02-22 12:58:27 +01001856static int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
1858 patch_ad1881(ac97);
1859 ac97->build_ops = &patch_ad1981a_build_ops;
1860 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1861 ac97->flags |= AC97_STEREO_MUTES;
1862 check_ad1981_hp_jack_sense(ac97);
1863 return 0;
1864}
1865
Takashi Iwaiee423812005-11-17 14:21:36 +01001866static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1868
Takashi Iwaiee423812005-11-17 14:21:36 +01001869static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
1871 int err;
1872
1873 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1874 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001875 if (check_list(ac97, ad1981_jacks_blacklist))
1876 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1878 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1879}
1880
1881static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1882 .build_post_spdif = patch_ad198x_post_spdif,
1883 .build_specific = patch_ad1981b_specific,
1884#ifdef CONFIG_PM
1885 .resume = ad18xx_resume
1886#endif
1887};
1888
Takashi Iwaiac519022007-02-22 12:58:27 +01001889static int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 patch_ad1881(ac97);
1892 ac97->build_ops = &patch_ad1981b_build_ops;
1893 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1894 ac97->flags |= AC97_STEREO_MUTES;
1895 check_ad1981_hp_jack_sense(ac97);
1896 return 0;
1897}
1898
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001899#define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Takashi Iwaiee423812005-11-17 14:21:36 +01001901static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902{
Takashi Iwaiee423812005-11-17 14:21:36 +01001903 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 unsigned short val;
1905
1906 val = ac97->regs[AC97_AD_MISC];
1907 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1908 return 0;
1909}
1910
Takashi Iwaiee423812005-11-17 14:21:36 +01001911static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
Takashi Iwaiee423812005-11-17 14:21:36 +01001913 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 unsigned short val;
1915
1916 val = !ucontrol->value.integer.value[0]
1917 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1918 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1919 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1920}
1921
Takashi Iwaiee423812005-11-17 14:21:36 +01001922static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
1924 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1925
1926 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1927 uinfo->count = 1;
1928 uinfo->value.enumerated.items = 3;
1929 if (uinfo->value.enumerated.item > 2)
1930 uinfo->value.enumerated.item = 2;
1931 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1932 return 0;
1933}
1934
Takashi Iwaiee423812005-11-17 14:21:36 +01001935static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
Takashi Iwaiee423812005-11-17 14:21:36 +01001937 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 unsigned short val;
1939
1940 val = ac97->regs[AC97_AD_MISC];
1941 if (!(val & AC97_AD198X_DMIX1))
1942 ucontrol->value.enumerated.item[0] = 0;
1943 else
1944 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1945 return 0;
1946}
1947
Takashi Iwaiee423812005-11-17 14:21:36 +01001948static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949{
Takashi Iwaiee423812005-11-17 14:21:36 +01001950 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 unsigned short val;
1952
1953 if (ucontrol->value.enumerated.item[0] > 2)
1954 return -EINVAL;
1955 if (ucontrol->value.enumerated.item[0] == 0)
1956 val = 0;
1957 else
1958 val = AC97_AD198X_DMIX1 |
1959 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1960 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1961 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1962}
1963
Takashi Iwaiee423812005-11-17 14:21:36 +01001964static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001965{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001966 unsigned short val = 0;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001967 /* clear LODIS if shared jack is to be used for Surround out */
1968 if (is_shared_linein(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001969 val |= (1 << 12);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01001970 /* clear CLDIS if shared jack is to be used for C/LFE out */
1971 if (is_shared_micin(ac97))
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001972 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001973 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001974 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001975}
1976
Takashi Iwaiee423812005-11-17 14:21:36 +01001977static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 {
1979 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1980 .name = "Exchange Front/Surround",
1981 .info = snd_ac97_ad1888_lohpsel_info,
1982 .get = snd_ac97_ad1888_lohpsel_get,
1983 .put = snd_ac97_ad1888_lohpsel_put
1984 },
Jaya Kumar02856b52006-06-23 15:18:41 +02001985 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1986 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1988 {
1989 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1990 .name = "Downmix",
1991 .info = snd_ac97_ad1888_downmix_info,
1992 .get = snd_ac97_ad1888_downmix_get,
1993 .put = snd_ac97_ad1888_downmix_put
1994 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001995 AC97_SURROUND_JACK_MODE_CTL,
1996 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001997
1998 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1999 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000};
2001
Takashi Iwaiee423812005-11-17 14:21:36 +01002002static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
2004 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2005 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
2006 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2007 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
2008}
2009
2010static struct snd_ac97_build_ops patch_ad1888_build_ops = {
2011 .build_post_spdif = patch_ad198x_post_spdif,
2012 .build_specific = patch_ad1888_specific,
2013#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02002014 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002016 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017};
2018
Takashi Iwaiac519022007-02-22 12:58:27 +01002019static int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 unsigned short misc;
2022
2023 patch_ad1881(ac97);
2024 ac97->build_ops = &patch_ad1888_build_ops;
2025 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2026 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
2027 /* AD-compatible mode */
2028 /* Stereo mutes enabled */
2029 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2030 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
2031 AC97_AD198X_LOSEL |
2032 AC97_AD198X_HPSEL |
2033 AC97_AD198X_MSPLT |
2034 AC97_AD198X_AC97NC);
2035 ac97->flags |= AC97_STEREO_MUTES;
2036 return 0;
2037}
2038
Takashi Iwaiee423812005-11-17 14:21:36 +01002039static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 int err;
2042
2043 if ((err = patch_ad1888_specific(ac97)) < 0)
2044 return err;
2045 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2046}
2047
2048static struct snd_ac97_build_ops patch_ad1980_build_ops = {
2049 .build_post_spdif = patch_ad198x_post_spdif,
2050 .build_specific = patch_ad1980_specific,
2051#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002052 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02002054 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055};
2056
Takashi Iwaiac519022007-02-22 12:58:27 +01002057static int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
2059 patch_ad1888(ac97);
2060 ac97->build_ops = &patch_ad1980_build_ops;
2061 return 0;
2062}
2063
Randy Cushman6428ea12006-12-21 19:17:29 +01002064static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2065 struct snd_ctl_elem_info *uinfo)
2066{
2067 static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
2068
2069 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2070 uinfo->count = 1;
2071 uinfo->value.enumerated.items = 4;
2072 if (uinfo->value.enumerated.item > 3)
2073 uinfo->value.enumerated.item = 3;
2074 strcpy(uinfo->value.enumerated.name,
2075 texts[uinfo->value.enumerated.item]);
2076 return 0;
2077}
2078
2079static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
2080 struct snd_ctl_elem_value *ucontrol)
2081{
2082 static const int reg2ctrl[4] = {2, 0, 1, 3};
2083 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2084 unsigned short val;
2085 val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
2086 >> AC97_AD198X_VREF_SHIFT;
2087 ucontrol->value.enumerated.item[0] = reg2ctrl[val];
2088 return 0;
2089}
2090
2091static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
2092 struct snd_ctl_elem_value *ucontrol)
2093{
2094 static const int ctrl2reg[4] = {1, 2, 0, 3};
2095 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2096 unsigned short val;
2097
2098 if (ucontrol->value.enumerated.item[0] > 3
2099 || ucontrol->value.enumerated.item[0] < 0)
2100 return -EINVAL;
2101 val = ctrl2reg[ucontrol->value.enumerated.item[0]]
2102 << AC97_AD198X_VREF_SHIFT;
2103 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
2104 AC97_AD198X_VREF_MASK, val);
2105}
2106
Takashi Iwaiee423812005-11-17 14:21:36 +01002107static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Randy Cushman6428ea12006-12-21 19:17:29 +01002108 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2109 {
2110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2111 .name = "Exchange Front/Surround",
2112 .info = snd_ac97_ad1888_lohpsel_info,
2113 .get = snd_ac97_ad1888_lohpsel_get,
2114 .put = snd_ac97_ad1888_lohpsel_put
2115 },
2116 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
2117 AC97_SINGLE("Spread Front to Surround and Center/LFE",
2118 AC97_AD_MISC, 7, 1, 0),
2119 {
2120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2121 .name = "Downmix",
2122 .info = snd_ac97_ad1888_downmix_info,
2123 .get = snd_ac97_ad1888_downmix_get,
2124 .put = snd_ac97_ad1888_downmix_put
2125 },
2126 {
2127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2128 .name = "V_REFOUT",
2129 .info = snd_ac97_ad1985_vrefout_info,
2130 .get = snd_ac97_ad1985_vrefout_get,
2131 .put = snd_ac97_ad1985_vrefout_put
2132 },
2133 AC97_SURROUND_JACK_MODE_CTL,
2134 AC97_CHANNEL_MODE_CTL,
2135
2136 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2137 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138};
2139
Takashi Iwaiee423812005-11-17 14:21:36 +01002140static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002141{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002142 ad1888_update_jacks(ac97);
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002143 /* clear OMS if shared jack is to be used for C/LFE out */
Takashi Iwaifc232c62005-05-27 10:42:45 +02002144 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002145 is_shared_micin(ac97) ? 1 << 9 : 0);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002146}
2147
Takashi Iwaiee423812005-11-17 14:21:36 +01002148static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
2150 int err;
2151
Randy Cushman6428ea12006-12-21 19:17:29 +01002152 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2153 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2154 "Master Surround Playback");
2155 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2156
2157 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 return err;
Randy Cushman6428ea12006-12-21 19:17:29 +01002159
2160 return patch_build_controls(ac97, snd_ac97_ad1985_controls,
2161 ARRAY_SIZE(snd_ac97_ad1985_controls));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164static struct snd_ac97_build_ops patch_ad1985_build_ops = {
2165 .build_post_spdif = patch_ad198x_post_spdif,
2166 .build_specific = patch_ad1985_specific,
2167#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02002168 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02002170 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171};
2172
Takashi Iwaiac519022007-02-22 12:58:27 +01002173static int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
2175 unsigned short misc;
2176
2177 patch_ad1881(ac97);
2178 ac97->build_ops = &patch_ad1985_build_ops;
2179 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2180 /* switch front/surround line-out/hp-out */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 /* AD-compatible mode */
2182 /* Stereo mutes enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 AC97_AD198X_LOSEL |
2185 AC97_AD198X_HPSEL |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 AC97_AD198X_MSPLT |
2187 AC97_AD198X_AC97NC);
2188 ac97->flags |= AC97_STEREO_MUTES;
Randy Cushman6428ea12006-12-21 19:17:29 +01002189
2190 /* update current jack configuration */
2191 ad1985_update_jacks(ac97);
2192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2194 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2195 return 0;
2196}
2197
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002198#define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002199
2200static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
2201 struct snd_ctl_elem_value *ucontrol)
2202{
2203 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2204 unsigned short val;
2205
2206 val = ac97->regs[AC97_AD_MISC3];
2207 ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
2208 return 0;
2209}
2210
2211static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
2212 struct snd_ctl_elem_value *ucontrol)
2213{
2214 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2215 int ret0;
2216 int ret1;
2217 int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
2218
2219 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
2220 ucontrol->value.integer.value[0] != 0
2221 ? AC97_AD1986_LOSEL : 0);
2222 if (ret0 < 0)
2223 return ret0;
2224
2225 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2226 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2227 (ucontrol->value.integer.value[0] != 0
2228 || sprd)
2229 ? AC97_AD1986_SOSEL : 0);
2230 if (ret1 < 0)
2231 return ret1;
2232
2233 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2234}
2235
2236static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
2237 struct snd_ctl_elem_value *ucontrol)
2238{
2239 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2240 unsigned short val;
2241
2242 val = ac97->regs[AC97_AD_MISC];
2243 ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
2244 return 0;
2245}
2246
2247static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
2248 struct snd_ctl_elem_value *ucontrol)
2249{
2250 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2251 int ret0;
2252 int ret1;
2253 int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
2254
2255 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
2256 ucontrol->value.integer.value[0] != 0
2257 ? AC97_AD1986_SPRD : 0);
2258 if (ret0 < 0)
2259 return ret0;
2260
2261 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2262 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2263 (ucontrol->value.integer.value[0] != 0
2264 || sprd)
2265 ? AC97_AD1986_SOSEL : 0);
2266 if (ret1 < 0)
2267 return ret1;
2268
2269 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2270}
2271
2272static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
2273 struct snd_ctl_elem_value *ucontrol)
2274{
2275 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2276
2277 ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
2278 return 0;
2279}
2280
2281static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
2282 struct snd_ctl_elem_value *ucontrol)
2283{
2284 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2285 unsigned char swap = ucontrol->value.integer.value[0] != 0;
2286
2287 if (swap != ac97->spec.ad18xx.swap_mic_linein) {
2288 ac97->spec.ad18xx.swap_mic_linein = swap;
2289 if (ac97->build_ops->update_jacks)
2290 ac97->build_ops->update_jacks(ac97);
2291 return 1;
2292 }
2293 return 0;
2294}
2295
2296static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_value *ucontrol)
2298{
2299 /* Use MIC_1/2 V_REFOUT as the "get" value */
2300 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2301 unsigned short val;
2302 unsigned short reg = ac97->regs[AC97_AD_MISC2];
2303 if ((reg & AC97_AD1986_MVREF0) != 0)
2304 val = 2;
2305 else if ((reg & AC97_AD1986_MVREF1) != 0)
2306 val = 3;
2307 else if ((reg & AC97_AD1986_MVREF2) != 0)
2308 val = 1;
2309 else
2310 val = 0;
2311 ucontrol->value.enumerated.item[0] = val;
2312 return 0;
2313}
2314
2315static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
2316 struct snd_ctl_elem_value *ucontrol)
2317{
2318 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2319 unsigned short cval;
2320 unsigned short lval;
2321 unsigned short mval;
2322 int cret;
2323 int lret;
2324 int mret;
2325
2326 switch (ucontrol->value.enumerated.item[0])
2327 {
2328 case 0: /* High-Z */
2329 cval = 0;
2330 lval = 0;
2331 mval = 0;
2332 break;
2333 case 1: /* 3.7 V */
2334 cval = AC97_AD1986_CVREF2;
2335 lval = AC97_AD1986_LVREF2;
2336 mval = AC97_AD1986_MVREF2;
2337 break;
2338 case 2: /* 2.25 V */
2339 cval = AC97_AD1986_CVREF0;
2340 lval = AC97_AD1986_LVREF0;
2341 mval = AC97_AD1986_MVREF0;
2342 break;
2343 case 3: /* 0 V */
2344 cval = AC97_AD1986_CVREF1;
2345 lval = AC97_AD1986_LVREF1;
2346 mval = AC97_AD1986_MVREF1;
2347 break;
2348 default:
2349 return -EINVAL;
2350 }
2351
2352 cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2353 AC97_AD1986_CVREF_MASK, cval);
2354 if (cret < 0)
2355 return cret;
2356 lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
2357 AC97_AD1986_LVREF_MASK, lval);
2358 if (lret < 0)
2359 return lret;
2360 mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2361 AC97_AD1986_MVREF_MASK, mval);
2362 if (mret < 0)
2363 return mret;
2364
2365 return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
2366}
2367
2368static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
2369 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2370 {
2371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2372 .name = "Exchange Front/Surround",
2373 .info = snd_ac97_ad1986_bool_info,
2374 .get = snd_ac97_ad1986_lososel_get,
2375 .put = snd_ac97_ad1986_lososel_put
2376 },
2377 {
2378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2379 .name = "Exchange Mic/Line In",
2380 .info = snd_ac97_ad1986_bool_info,
2381 .get = snd_ac97_ad1986_miclisel_get,
2382 .put = snd_ac97_ad1986_miclisel_put
2383 },
2384 {
2385 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2386 .name = "Spread Front to Surround and Center/LFE",
2387 .info = snd_ac97_ad1986_bool_info,
2388 .get = snd_ac97_ad1986_spread_get,
2389 .put = snd_ac97_ad1986_spread_put
2390 },
2391 {
2392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2393 .name = "Downmix",
2394 .info = snd_ac97_ad1888_downmix_info,
2395 .get = snd_ac97_ad1888_downmix_get,
2396 .put = snd_ac97_ad1888_downmix_put
2397 },
2398 {
2399 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2400 .name = "V_REFOUT",
2401 .info = snd_ac97_ad1985_vrefout_info,
2402 .get = snd_ac97_ad1986_vrefout_get,
2403 .put = snd_ac97_ad1986_vrefout_put
2404 },
2405 AC97_SURROUND_JACK_MODE_CTL,
2406 AC97_CHANNEL_MODE_CTL,
2407
2408 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2409 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
2410};
2411
2412static void ad1986_update_jacks(struct snd_ac97 *ac97)
2413{
2414 unsigned short misc_val = 0;
2415 unsigned short ser_val;
2416
2417 /* disable SURROUND and CENTER/LFE if not surround mode */
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002418 if (!is_surround_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002419 misc_val |= AC97_AD1986_SODIS;
Randy Cushmanc26a8de2007-03-09 11:32:22 +01002420 if (!is_clfe_on(ac97))
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002421 misc_val |= AC97_AD1986_CLDIS;
2422
2423 /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2424 if (is_shared_linein(ac97))
2425 misc_val |= AC97_AD1986_LISEL_SURR;
2426 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2427 misc_val |= AC97_AD1986_LISEL_MIC;
2428 snd_ac97_update_bits(ac97, AC97_AD_MISC,
2429 AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
2430 AC97_AD1986_LISEL_MASK,
2431 misc_val);
2432
2433 /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2434 if (is_shared_micin(ac97))
2435 ser_val = AC97_AD1986_OMS_C;
2436 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2437 ser_val = AC97_AD1986_OMS_L;
2438 else
2439 ser_val = AC97_AD1986_OMS_M;
2440 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
2441 AC97_AD1986_OMS_MASK,
2442 ser_val);
2443}
2444
2445static int patch_ad1986_specific(struct snd_ac97 *ac97)
2446{
2447 int err;
2448
2449 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2450 return err;
2451
2452 return patch_build_controls(ac97, snd_ac97_ad1986_controls,
2453 ARRAY_SIZE(snd_ac97_ad1985_controls));
2454}
2455
2456static struct snd_ac97_build_ops patch_ad1986_build_ops = {
2457 .build_post_spdif = patch_ad198x_post_spdif,
2458 .build_specific = patch_ad1986_specific,
2459#ifdef CONFIG_PM
2460 .resume = ad18xx_resume,
2461#endif
2462 .update_jacks = ad1986_update_jacks,
2463};
2464
Takashi Iwaiac519022007-02-22 12:58:27 +01002465static int patch_ad1986(struct snd_ac97 * ac97)
Randy Cushman67e9f4b2006-12-22 12:44:25 +01002466{
2467 patch_ad1881(ac97);
2468 ac97->build_ops = &patch_ad1986_build_ops;
2469 ac97->flags |= AC97_STEREO_MUTES;
2470
2471 /* update current jack configuration */
2472 ad1986_update_jacks(ac97);
2473
2474 return 0;
2475}
2476
2477
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478/*
2479 * realtek ALC65x/850 codecs
2480 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002481static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002483 int shared;
2484
Randy Cushman831466f2006-12-19 18:42:16 +01002485 /* shared Line-In / Surround Out */
2486 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002487 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2488 shared ? (1 << 9) : 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002489 /* update shared Mic In / Center/LFE Out */
2490 shared = is_shared_clfeout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002491 /* disable/enable vref */
2492 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2493 shared ? (1 << 12) : 0);
2494 /* turn on/off center-on-mic */
2495 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2496 shared ? (1 << 10) : 0);
2497 /* GPIO0 high for mic */
2498 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2499 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500}
2501
Takashi Iwaiee423812005-11-17 14:21:36 +01002502static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2504 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2505 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2506 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2507 /* 4: Analog Input To Surround */
2508 /* 5: Analog Input To Center/LFE */
2509 /* 6: Independent Master Volume Right */
2510 /* 7: Independent Master Volume Left */
2511 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002512 /* 9: Line-In/Surround share */
2513 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 /* 11-13: in IEC958 controls */
2515 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
2516#if 0 /* always set in patch_alc650 */
2517 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2518 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2519 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2520 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2521 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2522 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2523#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002524 AC97_SURROUND_JACK_MODE_CTL,
2525 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526};
2527
Takashi Iwaiee423812005-11-17 14:21:36 +01002528static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002529 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2531 /* disable this controls since it doesn't work as expected */
2532 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2533};
2534
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01002535static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002536
Takashi Iwaiee423812005-11-17 14:21:36 +01002537static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
2539 int err;
2540
2541 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2542 return err;
2543 if (ac97->ext_id & AC97_EI_SPDIF) {
2544 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2545 return err;
2546 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002547 if (ac97->id != AC97_ID_ALC650F)
2548 reset_tlv(ac97, "Master Playback Volume",
2549 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return 0;
2551}
2552
2553static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002554 .build_specific = patch_alc650_specific,
2555 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556};
2557
Takashi Iwaiac519022007-02-22 12:58:27 +01002558static int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
2560 unsigned short val;
2561
2562 ac97->build_ops = &patch_alc650_ops;
2563
2564 /* determine the revision */
2565 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2566 if (val < 3)
2567 ac97->id = 0x414c4720; /* Old version */
2568 else if (val < 0x10)
2569 ac97->id = 0x414c4721; /* D version */
2570 else if (val < 0x20)
2571 ac97->id = 0x414c4722; /* E version */
2572 else if (val < 0x30)
2573 ac97->id = 0x414c4723; /* F version */
2574
2575 /* revision E or F */
2576 /* FIXME: what about revision D ? */
2577 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2578 ac97->id == 0x414c4723);
2579
2580 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2581 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2582 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2583
2584 /* Enable SPDIF-IN only on Rev.E and above */
2585 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2586 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002587 if (ac97->spec.dev_flags &&
2588 /* ASUS A6KM requires EAPD */
2589 ! (ac97->subsystem_vendor == 0x1043 &&
2590 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 val |= 0x03; /* enable */
2592 else
2593 val &= ~0x03; /* disable */
2594 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2595
2596 /* set default: slot 3,4,7,8,6,9
2597 spdif-in monitor off, analog-spdif off, spdif-in off
2598 center on mic off, surround on line-in off
2599 downmix off, duplicate front off
2600 */
2601 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2602
2603 /* set GPIO0 for mic bias */
2604 /* GPIO0 pin output, no interrupt, high */
2605 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2606 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2607 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2608 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2609
2610 /* full DAC volume */
2611 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2612 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2613 return 0;
2614}
2615
Takashi Iwaiee423812005-11-17 14:21:36 +01002616static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002618 int shared;
2619
Randy Cushman831466f2006-12-19 18:42:16 +01002620 /* shared Line-In / Surround Out */
2621 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002622 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2623 shared ? (1 << 9) : 0, 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002624 /* update shared Mic In / Center/LFE Out */
2625 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 /* misc control; vrefout disable */
2627 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002628 shared ? (1 << 12) : 0);
2629 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2630 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631}
2632
Takashi Iwaiee423812005-11-17 14:21:36 +01002633static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002635 AC97_SURROUND_JACK_MODE_CTL,
2636 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637};
2638
Takashi Iwaiee423812005-11-17 14:21:36 +01002639static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640{
2641 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2642 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002643 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2646 uinfo->count = 1;
2647 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2648 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2649 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2650 strcpy(uinfo->value.enumerated.name,
2651 ac97->spec.dev_flags ?
2652 texts_658[uinfo->value.enumerated.item] :
2653 texts_655[uinfo->value.enumerated.item]);
2654 return 0;
2655}
2656
Takashi Iwaiee423812005-11-17 14:21:36 +01002657static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
Takashi Iwaiee423812005-11-17 14:21:36 +01002659 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 unsigned short val;
2661
2662 val = ac97->regs[AC97_ALC650_MULTICH];
2663 val = (val >> 12) & 3;
2664 if (ac97->spec.dev_flags && val == 3)
2665 val = 0;
2666 ucontrol->value.enumerated.item[0] = val;
2667 return 0;
2668}
2669
Takashi Iwaiee423812005-11-17 14:21:36 +01002670static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671{
Takashi Iwaiee423812005-11-17 14:21:36 +01002672 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2675 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2676 0);
2677}
2678
Takashi Iwaiee423812005-11-17 14:21:36 +01002679static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002680 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 /* disable this controls since it doesn't work as expected */
2682 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2683 {
2684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002685 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 .info = alc655_iec958_route_info,
2687 .get = alc655_iec958_route_get,
2688 .put = alc655_iec958_route_put,
2689 },
2690};
2691
Takashi Iwaiee423812005-11-17 14:21:36 +01002692static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693{
2694 int err;
2695
2696 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2697 return err;
2698 if (ac97->ext_id & AC97_EI_SPDIF) {
2699 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2700 return err;
2701 }
2702 return 0;
2703}
2704
2705static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002706 .build_specific = patch_alc655_specific,
2707 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708};
2709
Takashi Iwaiac519022007-02-22 12:58:27 +01002710static int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711{
2712 unsigned int val;
2713
Takashi Iwaia5022b02005-09-02 14:03:05 +02002714 if (ac97->id == AC97_ID_ALC658) {
2715 ac97->spec.dev_flags = 1; /* ALC658 */
2716 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2717 ac97->id = AC97_ID_ALC658D;
2718 ac97->spec.dev_flags = 2;
2719 }
2720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
2722 ac97->build_ops = &patch_alc655_ops;
2723
2724 /* assume only page 0 for writing cache */
2725 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2726
2727 /* adjust default values */
2728 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002729 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002731 else { /* ALC655 */
2732 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002733 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
Jaroslav Kyselae7d24f02006-10-05 09:30:36 +02002734 ac97->subsystem_device == 0x0161 || /* LG K1 Express */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002735 ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
Takashi Iwai592a82e2007-03-12 11:33:32 +01002736 ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002737 ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002738 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2739 else
2740 val |= (1 << 1); /* Pin 47 is spdif input pin */
2741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 val &= ~(1 << 12); /* vref enable */
2743 snd_ac97_write_cache(ac97, 0x7a, val);
2744 /* set default: spdif-in enabled,
2745 spdif-in monitor off, spdif-in PCM off
2746 center on mic off, surround on line-in off
2747 duplicate front off
2748 */
2749 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2750
2751 /* full DAC volume */
2752 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2753 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002754
2755 /* update undocumented bit... */
2756 if (ac97->id == AC97_ID_ALC658D)
2757 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2758
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 return 0;
2760}
2761
2762
2763#define AC97_ALC850_JACK_SELECT 0x76
2764#define AC97_ALC850_MISC1 0x7a
2765
Takashi Iwaiee423812005-11-17 14:21:36 +01002766static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002768 int shared;
2769
Randy Cushman831466f2006-12-19 18:42:16 +01002770 /* shared Line-In / Surround Out */
2771 shared = is_shared_surrout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 /* SURR 1kOhm (bit4), Amp (bit5) */
2773 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002774 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002776 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2777 shared ? (2<<12) : (0<<12));
Randy Cushman831466f2006-12-19 18:42:16 +01002778 /* update shared Mic In / Center/LFE Out */
2779 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 /* Vref disable (bit12), 1kOhm (bit13) */
2781 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002782 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002783 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002784 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002785 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786}
2787
Takashi Iwaiee423812005-11-17 14:21:36 +01002788static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002790 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002791 AC97_SURROUND_JACK_MODE_CTL,
2792 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793};
2794
Takashi Iwaiee423812005-11-17 14:21:36 +01002795static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796{
2797 int err;
2798
2799 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2800 return err;
2801 if (ac97->ext_id & AC97_EI_SPDIF) {
2802 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2803 return err;
2804 }
2805 return 0;
2806}
2807
2808static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002809 .build_specific = patch_alc850_specific,
2810 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811};
2812
Takashi Iwaiac519022007-02-22 12:58:27 +01002813static int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814{
2815 ac97->build_ops = &patch_alc850_ops;
2816
2817 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2818
2819 /* assume only page 0 for writing cache */
2820 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2821
2822 /* adjust default values */
2823 /* set default: spdif-in enabled,
2824 spdif-in monitor off, spdif-in PCM off
2825 center on mic off, surround on line-in off
2826 duplicate front off
2827 */
2828 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2829 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2830 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2831 */
2832 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2833 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2834 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2835 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2836 */
2837 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2838 (1<<11)|(0<<12)|(1<<15));
2839
2840 /* full DAC volume */
2841 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2842 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2843 return 0;
2844}
2845
2846
2847/*
2848 * C-Media CM97xx codecs
2849 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002850static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002851{
Randy Cushman831466f2006-12-19 18:42:16 +01002852 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002853 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002854 is_shared_surrout(ac97) ? (1 << 10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002855}
2856
Takashi Iwaiee423812005-11-17 14:21:36 +01002857static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002859 AC97_SURROUND_JACK_MODE_CTL,
2860 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861};
2862
Takashi Iwaiee423812005-11-17 14:21:36 +01002863static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864{
2865 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2866}
2867
2868static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002869 .build_specific = patch_cm9738_specific,
2870 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871};
2872
Takashi Iwaiac519022007-02-22 12:58:27 +01002873static int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874{
2875 ac97->build_ops = &patch_cm9738_ops;
2876 /* FIXME: can anyone confirm below? */
2877 /* CM9738 has no PCM volume although the register reacts */
2878 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2879 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2880
2881 return 0;
2882}
2883
Takashi Iwaiee423812005-11-17 14:21:36 +01002884static 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 -07002885{
2886 static char *texts[] = { "Analog", "Digital" };
2887
2888 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2889 uinfo->count = 1;
2890 uinfo->value.enumerated.items = 2;
2891 if (uinfo->value.enumerated.item > 1)
2892 uinfo->value.enumerated.item = 1;
2893 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2894 return 0;
2895}
2896
Takashi Iwaiee423812005-11-17 14:21:36 +01002897static 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 -07002898{
Takashi Iwaiee423812005-11-17 14:21:36 +01002899 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 unsigned short val;
2901
2902 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2903 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2904 return 0;
2905}
2906
Takashi Iwaiee423812005-11-17 14:21:36 +01002907static 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 -07002908{
Takashi Iwaiee423812005-11-17 14:21:36 +01002909 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2912 0x01 << 1,
2913 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2914}
2915
Takashi Iwaiee423812005-11-17 14:21:36 +01002916static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 /* BIT 0: SPDI_EN - always true */
2918 { /* BIT 1: SPDIFS */
2919 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2920 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2921 .info = snd_ac97_cmedia_spdif_playback_source_info,
2922 .get = snd_ac97_cmedia_spdif_playback_source_get,
2923 .put = snd_ac97_cmedia_spdif_playback_source_put,
2924 },
2925 /* BIT 2: IG_SPIV */
2926 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2927 /* BIT 3: SPI2F */
2928 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2929 /* BIT 4: SPI2SDI */
2930 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2931 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2932};
2933
Takashi Iwaiee423812005-11-17 14:21:36 +01002934static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935{
Randy Cushman831466f2006-12-19 18:42:16 +01002936 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002937 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002938 is_shared_surrout(ac97) ? (1 << 10) : 0);
2939 /* shared Mic In / Center/LFE Out **/
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002940 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
Randy Cushman831466f2006-12-19 18:42:16 +01002941 is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942}
2943
Takashi Iwaiee423812005-11-17 14:21:36 +01002944static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002945 AC97_SURROUND_JACK_MODE_CTL,
2946 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947};
2948
Takashi Iwaiee423812005-11-17 14:21:36 +01002949static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950{
2951 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2952}
2953
Takashi Iwaiee423812005-11-17 14:21:36 +01002954static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955{
2956 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2957}
2958
2959static struct snd_ac97_build_ops patch_cm9739_ops = {
2960 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002961 .build_post_spdif = patch_cm9739_post_spdif,
2962 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963};
2964
Takashi Iwaiac519022007-02-22 12:58:27 +01002965static int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966{
2967 unsigned short val;
2968
2969 ac97->build_ops = &patch_cm9739_ops;
2970
2971 /* CM9739/A has no Master and PCM volume although the register reacts */
2972 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2973 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2974 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2975
2976 /* check spdif */
2977 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2978 if (val & AC97_EA_SPCV) {
2979 /* enable spdif in */
2980 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2981 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2982 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2983 } else {
2984 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2985 ac97->rates[AC97_RATES_SPDIF] = 0;
2986 }
2987
2988 /* set-up multi channel */
2989 /* bit 14: 0 = SPDIF, 1 = EAPD */
2990 /* bit 13: enable internal vref output for mic */
2991 /* bit 12: disable center/lfe (swithable) */
2992 /* bit 10: disable surround/line (switchable) */
2993 /* bit 9: mix 2 surround off */
2994 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2995 /* bit 3: undocumented; surround? */
2996 /* bit 0: dB */
2997 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2998 val |= (1 << 3);
2999 val |= (1 << 13);
3000 if (! (ac97->ext_id & AC97_EI_SPDIF))
3001 val |= (1 << 14);
3002 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
3003
3004 /* FIXME: set up GPIO */
3005 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3006 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3007 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3008 if (ac97->pci &&
3009 ac97->subsystem_vendor == 0x1043 &&
3010 ac97->subsystem_device == 0x1843) {
3011 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3012 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
3013 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
3014 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
3015 }
3016
3017 return 0;
3018}
3019
3020#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003021#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022#define AC97_CM9761_SPDIF_CTRL 0x6c
3023
Takashi Iwaiee423812005-11-17 14:21:36 +01003024static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003026 /* FIXME: check the bits for each model
3027 * model 83 is confirmed to work
3028 */
3029 static unsigned short surr_on[3][2] = {
3030 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3031 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3032 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003034 static unsigned short clfe_on[3][2] = {
3035 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3036 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3037 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003039 static unsigned short surr_shared[3][2] = {
3040 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3041 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3042 { 0x0000, 0x0400 }, /* 9761-83 */
3043 };
3044 static unsigned short clfe_shared[3][2] = {
3045 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3046 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3047 { 0x2000, 0x0800 }, /* 9761-83 */
3048 };
3049 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003050
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003051 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
3052 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
Randy Cushman831466f2006-12-19 18:42:16 +01003053 val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3054 val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003055
3056 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057}
3058
Takashi Iwaiee423812005-11-17 14:21:36 +01003059static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003060 AC97_SURROUND_JACK_MODE_CTL,
3061 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062};
3063
Takashi Iwaiee423812005-11-17 14:21:36 +01003064static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003065{
3066 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
3067
3068 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3069 uinfo->count = 1;
3070 uinfo->value.enumerated.items = 3;
3071 if (uinfo->value.enumerated.item > 2)
3072 uinfo->value.enumerated.item = 2;
3073 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3074 return 0;
3075}
3076
Takashi Iwaiee423812005-11-17 14:21:36 +01003077static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003078{
Takashi Iwaiee423812005-11-17 14:21:36 +01003079 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003080
3081 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
3082 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
3083 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
3084 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
3085 else
3086 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
3087 return 0;
3088}
3089
Takashi Iwaiee423812005-11-17 14:21:36 +01003090static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003091{
Takashi Iwaiee423812005-11-17 14:21:36 +01003092 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003093
3094 if (ucontrol->value.enumerated.item[0] == 2)
3095 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
3096 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
3097 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
3098 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3099}
3100
3101static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
3102static const struct ac97_enum cm9761_dac_clock_enum =
3103 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3104
Takashi Iwaiee423812005-11-17 14:21:36 +01003105static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003106 { /* BIT 1: SPDIFS */
3107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3108 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3109 .info = cm9761_spdif_out_source_info,
3110 .get = cm9761_spdif_out_source_get,
3111 .put = cm9761_spdif_out_source_put,
3112 },
3113 /* BIT 2: IG_SPIV */
3114 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
3115 /* BIT 3: SPI2F */
3116 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
3117 /* BIT 4: SPI2SDI */
3118 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
3119 /* BIT 9-10: DAC_CTL */
3120 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
3121};
3122
Takashi Iwaiee423812005-11-17 14:21:36 +01003123static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003124{
3125 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
3126}
3127
Takashi Iwaiee423812005-11-17 14:21:36 +01003128static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
3130 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
3131}
3132
3133static struct snd_ac97_build_ops patch_cm9761_ops = {
3134 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003135 .build_post_spdif = patch_cm9761_post_spdif,
3136 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137};
3138
Takashi Iwaiac519022007-02-22 12:58:27 +01003139static int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140{
3141 unsigned short val;
3142
3143 /* CM9761 has no PCM volume although the register reacts */
3144 /* Master volume seems to have _some_ influence on the analog
3145 * input sounds
3146 */
3147 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
3148 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
3149 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
3150
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003151 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if (ac97->id == AC97_ID_CM9761_82) {
3153 unsigned short tmp;
3154 /* check page 1, reg 0x60 */
3155 val = snd_ac97_read(ac97, AC97_INT_PAGING);
3156 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
3157 tmp = snd_ac97_read(ac97, 0x60);
3158 ac97->spec.dev_flags = tmp & 1; /* revision B? */
3159 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02003160 } else if (ac97->id == AC97_ID_CM9761_83)
3161 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163 ac97->build_ops = &patch_cm9761_ops;
3164
3165 /* enable spdif */
3166 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3167 ac97->ext_id |= AC97_EI_SPDIF;
3168 /* to be sure: we overwrite the ext status bits */
3169 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
3170 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003171 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3173
3174 /* set-up multi channel */
3175 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003176 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003178 * bit 12: CLFE control (reverted on rev B)
3179 * bit 11: Mic/center share (reverted on rev B)
3180 * bit 10: suddound/line share
3181 * bit 9: Analog-in mix -> surround
3182 * bit 8: Analog-in mix -> CLFE
3183 * bit 7: Mic/LFE share (mic/center/lfe)
3184 * bit 5: vref select (9761A)
3185 * bit 4: front control
3186 * bit 3: surround control (revereted with rev B)
3187 * bit 2: front mic
3188 * bit 1: stereo mic
3189 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 */
3191
3192#if 0
3193 if (ac97->spec.dev_flags)
3194 val = 0x0214;
3195 else
3196 val = 0x321c;
3197#endif
3198 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
3199 val |= (1 << 4); /* front on */
3200 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
3201
3202 /* FIXME: set up GPIO */
3203 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3204 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3205
3206 return 0;
3207}
3208
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003209#define AC97_CM9780_SIDE 0x60
3210#define AC97_CM9780_JACK 0x62
3211#define AC97_CM9780_MIXER 0x64
3212#define AC97_CM9780_MULTI_CHAN 0x66
3213#define AC97_CM9780_SPDIF 0x6c
3214
3215static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
3216static const struct ac97_enum cm9780_ch_select_enum =
3217 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01003218static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003219 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
3220 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
3221 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
3222};
3223
Takashi Iwaiee423812005-11-17 14:21:36 +01003224static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003225{
3226 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
3227}
3228
3229static struct snd_ac97_build_ops patch_cm9780_ops = {
3230 .build_specific = patch_cm9780_specific,
3231 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
3232};
3233
Takashi Iwaiac519022007-02-22 12:58:27 +01003234static int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02003235{
3236 unsigned short val;
3237
3238 ac97->build_ops = &patch_cm9780_ops;
3239
3240 /* enable spdif */
3241 if (ac97->ext_id & AC97_EI_SPDIF) {
3242 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3243 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
3244 val |= 0x1; /* SPDI_EN */
3245 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
3246 }
3247
3248 return 0;
3249}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
3251/*
3252 * VIA VT1616 codec
3253 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003254static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3256AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3257AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3258AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3259};
3260
Takashi Iwaiee423812005-11-17 14:21:36 +01003261static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262{
3263 int err;
3264
3265 if (snd_ac97_try_bit(ac97, 0x5a, 9))
3266 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
3267 return err;
3268 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
3269 return err;
3270 return 0;
3271}
3272
3273static struct snd_ac97_build_ops patch_vt1616_ops = {
3274 .build_specific = patch_vt1616_specific
3275};
3276
Takashi Iwaiac519022007-02-22 12:58:27 +01003277static int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278{
3279 ac97->build_ops = &patch_vt1616_ops;
3280 return 0;
3281}
3282
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003283/*
Philip Prindeville4b499482005-08-12 16:46:17 +02003284 * VT1617A codec
3285 */
John Utze9024cc2007-03-12 12:30:06 +01003286
3287/*
3288 * unfortunately, the vt1617a stashes the twiddlers required for
3289 * nooding the i/o jacks on 2 different regs. * thameans that we cant
3290 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3291 * are own funcs.
3292 *
3293 * NB: this is absolutely and utterly different from the vt1618. dunno
3294 * about the 1616.
3295 */
3296
3297/* copied from ac97_surround_jack_mode_info() */
3298static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3299 struct snd_ctl_elem_info *uinfo)
Philip Prindeville4b499482005-08-12 16:46:17 +02003300{
John Utze9024cc2007-03-12 12:30:06 +01003301 /* ordering in this list reflects vt1617a docs for Reg 20 and
3302 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3303 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3304 * counter-intuitive */
3305
3306 static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3",
3307 "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3308 "LineIn Mic2", "LineIn Mic2 Mic1",
3309 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
3310 return ac97_enum_text_info(kcontrol, uinfo, texts, 8);
3311}
3312
3313static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3314 struct snd_ctl_elem_value *ucontrol)
3315{
3316 ushort usSM51, usMS;
3317
3318 struct snd_ac97 *pac97;
3319
3320 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3321
3322 /* grab our desirec bits, then mash them together in a manner
3323 * consistent with Table 6 on page 17 in the 1617a docs */
3324
3325 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3326 usMS = snd_ac97_read(pac97, 0x20) >> 8;
3327
3328 ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3329
3330 return 0;
3331}
3332
3333static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3334 struct snd_ctl_elem_value *ucontrol)
3335{
3336 ushort usSM51, usMS, usReg;
3337
3338 struct snd_ac97 *pac97;
3339
3340 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3341
3342 usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3343 usMS = ucontrol->value.enumerated.item[0] & 1;
3344
3345 /* push our values into the register - consider that things will be left
3346 * in a funky state if the write fails */
3347
3348 usReg = snd_ac97_read(pac97, 0x7a);
3349 snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3350 usReg = snd_ac97_read(pac97, 0x20);
3351 snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
3352
3353 return 0;
3354}
3355
3356static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3357
3358 AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3359 /*
3360 * These are used to enable/disable surround sound on motherboards
3361 * that have 3 bidirectional analog jacks
3362 */
3363 {
3364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3365 .name = "Smart 5.1 Select",
3366 .info = snd_ac97_vt1617a_smart51_info,
3367 .get = snd_ac97_vt1617a_smart51_get,
3368 .put = snd_ac97_vt1617a_smart51_put,
3369 },
3370};
3371
3372int patch_vt1617a(struct snd_ac97 * ac97)
3373{
3374 int err = 0;
3375
3376 /* we choose to not fail out at this point, but we tell the
3377 caller when we return */
3378
3379 err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3380 ARRAY_SIZE(snd_ac97_controls_vt1617a));
3381
3382 /* bring analog power consumption to normal by turning off the
3383 * headphone amplifier, like WinXP driver for EPIA SP
Andrey Liakhovets9f458e7fb2006-08-28 16:52:41 +02003384 */
3385 snd_ac97_write_cache(ac97, 0x5c, 0x20);
Philip Prindeville4b499482005-08-12 16:46:17 +02003386 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3387 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
Daniel Jacobowitz9f428172007-01-12 19:11:47 +01003388 ac97->build_ops = &patch_vt1616_ops;
John Utze9024cc2007-03-12 12:30:06 +01003389
3390 return err;
Philip Prindeville4b499482005-08-12 16:46:17 +02003391}
3392
3393/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003394 */
Takashi Iwaiee423812005-11-17 14:21:36 +01003395static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003396{
Randy Cushman831466f2006-12-19 18:42:16 +01003397 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003398 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
Randy Cushman831466f2006-12-19 18:42:16 +01003399 is_shared_surrout(ac97) ? (1<<9) : 0);
3400 /* shared Mic / Center/LFE Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003401 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01003402 is_shared_clfeout(ac97) ? (1<<10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003403}
3404
Takashi Iwaiee423812005-11-17 14:21:36 +01003405static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003406 AC97_SURROUND_JACK_MODE_CTL,
3407 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408};
3409
Takashi Iwaiee423812005-11-17 14:21:36 +01003410static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02003411 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3413 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3414};
3415
Takashi Iwaiee423812005-11-17 14:21:36 +01003416static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417{
3418 int err;
3419 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
3420 return err;
3421 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
3422 return err;
3423 return 0;
3424}
3425
3426static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02003427 .build_specific = patch_it2646_specific,
3428 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429};
3430
Takashi Iwaiac519022007-02-22 12:58:27 +01003431static int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432{
3433 ac97->build_ops = &patch_it2646_ops;
3434 /* full DAC volume */
3435 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
3436 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
3437 return 0;
3438}
3439
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003440/*
3441 * Si3036 codec
3442 */
3443
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003445#define AC97_SI3036_LINE_CFG 0x5c
3446
Takashi Iwaiee423812005-11-17 14:21:36 +01003447static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003448AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3449};
3450
Takashi Iwaiee423812005-11-17 14:21:36 +01003451static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003452{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02003453 int idx, err;
3454 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
3455 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
3456 return err;
3457 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003458}
3459
3460static struct snd_ac97_build_ops patch_si3036_ops = {
3461 .build_specific = patch_si3036_specific,
3462};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
Takashi Iwaiac519022007-02-22 12:58:27 +01003464static int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02003466 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
3468 snd_ac97_write_cache(ac97, 0x68, 0);
3469 return 0;
3470}
Charl Coetzeeba224292006-02-09 11:48:21 +01003471
3472/*
3473 * LM 4550 Codec
3474 *
3475 * We use a static resolution table since LM4550 codec cannot be
3476 * properly autoprobed to determine the resolution via
3477 * check_volume_resolution().
3478 */
3479
3480static struct snd_ac97_res_table lm4550_restbl[] = {
3481 { AC97_MASTER, 0x1f1f },
3482 { AC97_HEADPHONE, 0x1f1f },
3483 { AC97_MASTER_MONO, 0x001f },
3484 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
3485 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01003486 { AC97_MIC, 0x001f },
3487 { AC97_LINE, 0x1f1f },
3488 { AC97_CD, 0x1f1f },
3489 { AC97_VIDEO, 0x1f1f },
3490 { AC97_AUX, 0x1f1f },
3491 { AC97_PCM, 0x1f1f },
3492 { AC97_REC_GAIN, 0x0f0f },
3493 { } /* terminator */
3494};
3495
Takashi Iwaiac519022007-02-22 12:58:27 +01003496static int patch_lm4550(struct snd_ac97 *ac97)
Charl Coetzeeba224292006-02-09 11:48:21 +01003497{
3498 ac97->res_table = lm4550_restbl;
3499 return 0;
3500}
Mike Rapoport82466ad2006-06-29 17:15:33 +02003501
3502/*
3503 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3504 */
3505static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
3506/* enable/disable headphone driver which allows direct connection to
3507 stereo headphone without the use of external DC blocking
3508 capacitors */
3509AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3510/* Filter used to compensate the DC offset is added in the ADC to remove idle
3511 tones from the audio band. */
3512AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3513/* Control smart-low-power mode feature. Allows automatic power down
3514 of unused blocks in the ADC analog front end and the PLL. */
3515AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3516};
3517
3518static int patch_ucb1400_specific(struct snd_ac97 * ac97)
3519{
3520 int idx, err;
3521 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
3522 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
3523 return err;
3524 return 0;
3525}
3526
3527static struct snd_ac97_build_ops patch_ucb1400_ops = {
3528 .build_specific = patch_ucb1400_specific,
3529};
3530
Takashi Iwaiac519022007-02-22 12:58:27 +01003531static int patch_ucb1400(struct snd_ac97 * ac97)
Mike Rapoport82466ad2006-06-29 17:15:33 +02003532{
3533 ac97->build_ops = &patch_ucb1400_ops;
3534 /* enable headphone driver and smart low power mode by default */
3535 snd_ac97_write(ac97, 0x6a, 0x0050);
3536 snd_ac97_write(ac97, 0x6c, 0x0030);
3537 return 0;
3538}