blob: 5f69b9c9f1b3aeaabe9c6583b736a9247198c627 [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
26#include <sound/driver.h>
27#include <linux/delay.h>
28#include <linux/init.h>
29#include <linux/slab.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010030#include <linux/mutex.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <sound/core.h>
33#include <sound/pcm.h>
34#include <sound/control.h>
Takashi Iwai2f3482f2006-08-21 18:44:31 +020035#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <sound/ac97_codec.h>
37#include "ac97_patch.h"
38#include "ac97_id.h"
39#include "ac97_local.h"
40
41/*
42 * Chip specific initialization
43 */
44
Takashi Iwaiee423812005-11-17 14:21:36 +010045static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 int idx, err;
48
49 for (idx = 0; idx < count; idx++)
50 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
51 return err;
52 return 0;
53}
54
Takashi Iwai2f3482f2006-08-21 18:44:31 +020055/* replace with a new TLV */
56static void reset_tlv(struct snd_ac97 *ac97, const char *name,
57 unsigned int *tlv)
58{
59 struct snd_ctl_elem_id sid;
60 struct snd_kcontrol *kctl;
61 memset(&sid, 0, sizeof(sid));
62 strcpy(sid.name, name);
63 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
64 kctl = snd_ctl_find_id(ac97->bus->card, &sid);
65 if (kctl && kctl->tlv.p)
66 kctl->tlv.p = tlv;
67}
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* set to the page, update bits and restore the page */
Takashi Iwaiee423812005-11-17 14:21:36 +010070static 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 -070071{
72 unsigned short page_save;
73 int ret;
74
Ingo Molnar62932df2006-01-16 16:34:20 +010075 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
77 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
78 ret = snd_ac97_update_bits(ac97, reg, mask, value);
79 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
Ingo Molnar62932df2006-01-16 16:34:20 +010080 mutex_unlock(&ac97->page_mutex); /* unlock paging */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return ret;
82}
83
Takashi Iwaieb8caf32005-04-13 14:32:57 +020084/*
85 * shared line-in/mic controls
86 */
Takashi Iwaiee423812005-11-17 14:21:36 +010087static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
Takashi Iwaieb8caf32005-04-13 14:32:57 +020088 const char **texts, unsigned int nums)
89{
90 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
91 uinfo->count = 1;
92 uinfo->value.enumerated.items = nums;
93 if (uinfo->value.enumerated.item > nums - 1)
94 uinfo->value.enumerated.item = nums - 1;
95 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
96 return 0;
97}
98
Takashi Iwaiee423812005-11-17 14:21:36 +010099static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200100{
101 static const char *texts[] = { "Shared", "Independent" };
102 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
103}
104
Takashi Iwaiee423812005-11-17 14:21:36 +0100105static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200106{
Takashi Iwaiee423812005-11-17 14:21:36 +0100107 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200108
109 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
110 return 0;
111}
112
Takashi Iwaiee423812005-11-17 14:21:36 +0100113static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200114{
Takashi Iwaiee423812005-11-17 14:21:36 +0100115 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200116 unsigned char indep = !!ucontrol->value.enumerated.item[0];
117
118 if (indep != ac97->indep_surround) {
119 ac97->indep_surround = indep;
120 if (ac97->build_ops->update_jacks)
121 ac97->build_ops->update_jacks(ac97);
122 return 1;
123 }
124 return 0;
125}
126
Takashi Iwaiee423812005-11-17 14:21:36 +0100127static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200128{
129 static const char *texts[] = { "2ch", "4ch", "6ch" };
130 if (kcontrol->private_value)
131 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
132 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
133}
134
Takashi Iwaiee423812005-11-17 14:21:36 +0100135static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200136{
Takashi Iwaiee423812005-11-17 14:21:36 +0100137 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200138
139 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
140 return 0;
141}
142
Takashi Iwaiee423812005-11-17 14:21:36 +0100143static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200144{
Takashi Iwaiee423812005-11-17 14:21:36 +0100145 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200146 unsigned char mode = ucontrol->value.enumerated.item[0];
147
148 if (mode != ac97->channel_mode) {
149 ac97->channel_mode = mode;
150 if (ac97->build_ops->update_jacks)
151 ac97->build_ops->update_jacks(ac97);
152 return 1;
153 }
154 return 0;
155}
156
157#define AC97_SURROUND_JACK_MODE_CTL \
158 { \
159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
160 .name = "Surround Jack Mode", \
161 .info = ac97_surround_jack_mode_info, \
162 .get = ac97_surround_jack_mode_get, \
163 .put = ac97_surround_jack_mode_put, \
164 }
165#define AC97_CHANNEL_MODE_CTL \
166 { \
167 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
168 .name = "Channel Mode", \
169 .info = ac97_channel_mode_info, \
170 .get = ac97_channel_mode_get, \
171 .put = ac97_channel_mode_put, \
172 }
173#define AC97_CHANNEL_MODE_4CH_CTL \
174 { \
175 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
176 .name = "Channel Mode", \
177 .info = ac97_channel_mode_info, \
178 .get = ac97_channel_mode_get, \
179 .put = ac97_channel_mode_put, \
180 .private_value = 1, \
181 }
182
Takashi Iwaiee423812005-11-17 14:21:36 +0100183static inline int is_surround_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200184{
185 return ac97->channel_mode >= 1;
186}
187
Takashi Iwaiee423812005-11-17 14:21:36 +0100188static inline int is_clfe_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200189{
Takashi Iwaieb9b4142005-09-13 18:39:21 +0200190 return ac97->channel_mode >= 2;
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200191}
192
Randy Cushman831466f2006-12-19 18:42:16 +0100193/* system has shared jacks with surround out enabled */
194static inline int is_shared_surrout(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200195{
Randy Cushman831466f2006-12-19 18:42:16 +0100196 return !ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200197}
198
Randy Cushman831466f2006-12-19 18:42:16 +0100199/* system has shared jacks with center/lfe out enabled */
200static inline int is_shared_clfeout(struct snd_ac97 *ac97)
201{
202 return !ac97->indep_surround && is_clfe_on(ac97);
203}
204
205/* system has shared jacks with line in enabled */
206static inline int is_shared_linein(struct snd_ac97 *ac97)
207{
208 return !ac97->indep_surround && !is_surround_on(ac97);
209}
210
211/* system has shared jacks with mic in enabled */
Takashi Iwaiee423812005-11-17 14:21:36 +0100212static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200213{
Randy Cushman831466f2006-12-19 18:42:16 +0100214 return !ac97->indep_surround && !is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200215}
216
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
219
220/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100221static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 static char *texts[3] = {
224 "Standard", "Small", "Smaller"
225 };
226
227 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
228 uinfo->count = 1;
229 uinfo->value.enumerated.items = 3;
230 if (uinfo->value.enumerated.item > 2)
231 uinfo->value.enumerated.item = 2;
232 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
233 return 0;
234}
235
Takashi Iwaiee423812005-11-17 14:21:36 +0100236static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Takashi Iwaiee423812005-11-17 14:21:36 +0100238 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 unsigned short val;
240
241 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
242 val = (val >> 10) & 3;
243 if (val > 0) /* 0 = invalid */
244 val--;
245 ucontrol->value.enumerated.item[0] = val;
246 return 0;
247}
248
Takashi Iwaiee423812005-11-17 14:21:36 +0100249static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Takashi Iwaiee423812005-11-17 14:21:36 +0100251 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 unsigned short val;
253
254 if (ucontrol->value.enumerated.item[0] > 2)
255 return -EINVAL;
256 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
257 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
258}
259
Takashi Iwaiee423812005-11-17 14:21:36 +0100260static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
263 .name = "3D Control - Speaker",
264 .info = snd_ac97_ymf753_info_speaker,
265 .get = snd_ac97_ymf753_get_speaker,
266 .put = snd_ac97_ymf753_put_speaker,
267};
268
269/* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100270static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 static char *texts[2] = { "AC-Link", "A/D Converter" };
273
274 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
275 uinfo->count = 1;
276 uinfo->value.enumerated.items = 2;
277 if (uinfo->value.enumerated.item > 1)
278 uinfo->value.enumerated.item = 1;
279 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
280 return 0;
281}
282
Takashi Iwaiee423812005-11-17 14:21:36 +0100283static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Takashi Iwaiee423812005-11-17 14:21:36 +0100285 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 unsigned short val;
287
288 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
289 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
290 return 0;
291}
292
Takashi Iwaiee423812005-11-17 14:21:36 +0100293static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Takashi Iwaiee423812005-11-17 14:21:36 +0100295 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 unsigned short val;
297
298 if (ucontrol->value.enumerated.item[0] > 1)
299 return -EINVAL;
300 val = ucontrol->value.enumerated.item[0] << 1;
301 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
302}
303
304/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
305 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
306 By default, no output pin is selected, and the S/PDIF signal is not output.
307 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100308static 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 -0700309{
310 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
311
312 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
313 uinfo->count = 1;
314 uinfo->value.enumerated.items = 3;
315 if (uinfo->value.enumerated.item > 2)
316 uinfo->value.enumerated.item = 2;
317 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
318 return 0;
319}
320
Takashi Iwaiee423812005-11-17 14:21:36 +0100321static 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 -0700322{
Takashi Iwaiee423812005-11-17 14:21:36 +0100323 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 unsigned short val;
325
326 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
327 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
328 return 0;
329}
330
Takashi Iwaiee423812005-11-17 14:21:36 +0100331static 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 -0700332{
Takashi Iwaiee423812005-11-17 14:21:36 +0100333 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 unsigned short val;
335
336 if (ucontrol->value.enumerated.item[0] > 2)
337 return -EINVAL;
338 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
339 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
340 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
341 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
342 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
343}
344
Takashi Iwaiee423812005-11-17 14:21:36 +0100345static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 {
347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
348 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
349 .info = snd_ac97_ymf753_spdif_source_info,
350 .get = snd_ac97_ymf753_spdif_source_get,
351 .put = snd_ac97_ymf753_spdif_source_put,
352 },
353 {
354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
355 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
356 .info = snd_ac97_ymf753_spdif_output_pin_info,
357 .get = snd_ac97_ymf753_spdif_output_pin_get,
358 .put = snd_ac97_ymf753_spdif_output_pin_put,
359 },
360 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
361};
362
Takashi Iwaiee423812005-11-17 14:21:36 +0100363static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Takashi Iwaiee423812005-11-17 14:21:36 +0100365 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 int err;
367
368 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
369 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);
373 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
374 return err;
375 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
376 return 0;
377}
378
Takashi Iwaiee423812005-11-17 14:21:36 +0100379static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 int err;
382
383 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
384 return err;
385 return 0;
386}
387
388static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
389 .build_3d = patch_yamaha_ymf753_3d,
390 .build_post_spdif = patch_yamaha_ymf753_post_spdif
391};
392
Takashi Iwaiee423812005-11-17 14:21:36 +0100393int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
396 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
397 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
398 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
399 By default, no output pin is selected, and the S/PDIF signal is not output.
400 There is also a bit to mute S/PDIF output in a vendor-specific register.
401 */
402 ac97->build_ops = &patch_yamaha_ymf753_ops;
403 ac97->caps |= AC97_BC_BASS_TREBLE;
404 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
405 return 0;
406}
407
408/*
409 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
410 * removed broken wolfson00 patch.
411 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
412 */
413
Takashi Iwaiee423812005-11-17 14:21:36 +0100414static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200415AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
416AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
417};
418
Takashi Iwaiee423812005-11-17 14:21:36 +0100419static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
421 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200422 * Randolph Bentson <bentson@holmsjoen.com>
423 * WM9703/9707/9708/9717
424 */
425 int err, i;
426
427 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
428 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
429 return err;
430 }
431 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 0;
433}
Liam Girdwood3998b702005-07-29 11:41:55 +0200434
435static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
436 .build_specific = patch_wolfson_wm9703_specific,
437};
438
Takashi Iwaiee423812005-11-17 14:21:36 +0100439int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200440{
441 ac97->build_ops = &patch_wolfson_wm9703_ops;
442 return 0;
443}
444
Takashi Iwaiee423812005-11-17 14:21:36 +0100445static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200446AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
447AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
448AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
449AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
450AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
451AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
452};
453
Takashi Iwaiee423812005-11-17 14:21:36 +0100454static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200455{
456 int err, i;
457 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
458 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
459 return err;
460 }
461 /* patch for DVD noise */
462 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
463 return 0;
464}
465
466static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
467 .build_specific = patch_wolfson_wm9704_specific,
468};
469
Takashi Iwaiee423812005-11-17 14:21:36 +0100470int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Liam Girdwood3998b702005-07-29 11:41:55 +0200472 /* WM9704M/9704Q */
473 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return 0;
475}
Liam Girdwood3998b702005-07-29 11:41:55 +0200476
Takashi Iwaiee423812005-11-17 14:21:36 +0100477static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200478{
479 int err, i;
480 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
481 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
482 return err;
483 }
484 snd_ac97_write_cache(ac97, 0x72, 0x0808);
485 return 0;
486}
487
488static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
489 .build_specific = patch_wolfson_wm9705_specific,
490};
491
Takashi Iwaiee423812005-11-17 14:21:36 +0100492int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Liam Girdwood3998b702005-07-29 11:41:55 +0200494 /* WM9705, WM9710 */
495 ac97->build_ops = &patch_wolfson_wm9705_ops;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200496#ifdef CONFIG_TOUCHSCREEN_WM9705
497 /* WM9705 touchscreen uses AUX and VIDEO for touch */
Liam Girdwood8f888202006-09-07 18:07:46 +0200498 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 return 0;
501}
502
Liam Girdwood3998b702005-07-29 11:41:55 +0200503static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
504static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
505static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
506static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
507static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
508static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
509static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
510static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
511static const char* wm9711_rec_sel[] =
512 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
513static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
514
515static const struct ac97_enum wm9711_enum[] = {
516AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
517AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
518AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
519AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
520AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
521AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
522AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
523AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
524AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
525AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
526};
527
Takashi Iwaiee423812005-11-17 14:21:36 +0100528static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200529AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
530AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
531AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
532AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
533AC97_ENUM("ALC Function", wm9711_enum[0]),
534AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
535AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
536AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
537AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
538AC97_ENUM("ALC NG Type", wm9711_enum[9]),
539AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
540
541AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
542AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
543AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
544AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
545
546AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200547AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200548AC97_ENUM("Out3 Mux", wm9711_enum[2]),
549AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
550AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
551
552AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
553AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
554AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
555AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
556AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
557AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
558
559AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
560AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
561AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
562AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
563AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
564AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
565
566AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
567AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
568
569AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
570AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
571AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
572
573AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
574AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
575AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
576
577AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
578AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
579AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
580AC97_ENUM("Capture Select", wm9711_enum[8]),
581
582AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
583AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
584
585AC97_ENUM("Bass Control", wm9711_enum[5]),
586AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
587AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
588AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
589
590AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
591AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200592AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200593AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
594
595AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
596AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
597AC97_ENUM("Mic Select Source", wm9711_enum[7]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200598AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
599AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100600AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200601
602AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
603AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
604AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
605};
606
Takashi Iwaiee423812005-11-17 14:21:36 +0100607static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200608{
609 int err, i;
610
611 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
612 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
613 return err;
614 }
615 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
616 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
617 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
618 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
619 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
620 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
621 return 0;
622}
623
624static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
625 .build_specific = patch_wolfson_wm9711_specific,
626};
627
Takashi Iwaiee423812005-11-17 14:21:36 +0100628int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Liam Girdwood3998b702005-07-29 11:41:55 +0200630 /* WM9711, WM9712 */
631 ac97->build_ops = &patch_wolfson_wm9711_ops;
632
633 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
634 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return 0;
637}
638
Liam Girdwood3998b702005-07-29 11:41:55 +0200639static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200641static const char* wm9713_rec_src[] =
642 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
643 "Mono Mix", "Zh"};
644static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
645static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
646static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
647static const char* wm9713_spk_pga[] =
648 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
649static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
650static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
651static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
652static const char* wm9713_dac_inv[] =
653 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
654 "Headphone Mix Mono", "NC", "Vmid"};
655static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
656static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658static const struct ac97_enum wm9713_enum[] = {
659AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
660AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
661AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200662AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
663AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
664AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
665AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
666AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
667AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
668AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
669AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
670AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
671AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
672AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673};
674
Takashi Iwaiee423812005-11-17 14:21:36 +0100675static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200677AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
678AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
679AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
680
681AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
682AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
683AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
684AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
685
686AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
687AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
688AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
689AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100690AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200691AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
692AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
693
694AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
695AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
696AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
697AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
698
699AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
700AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
701AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
702AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
703AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
704AC97_ENUM("Capture Select", wm9713_enum[3]),
705
706AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
707AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
708AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
709AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
710AC97_ENUM("ALC Function", wm9713_enum[5]),
711AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
712AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
713AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
714AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
715AC97_ENUM("ALC NG Type", wm9713_enum[13]),
716AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
717
718AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
719AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
720AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
721AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
722AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
723AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
724
725AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
726AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
727AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
728AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
729AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
730AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
731
732AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
733AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
734AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
735AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
736AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
737AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
738
739AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
740AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
741AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
742AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
743AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
744AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
745
746AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
747AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
748AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
749AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
750AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
751AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
752
753AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
754AC97_ENUM("Master Input Mux", wm9713_enum[7]),
755AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
756AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
757AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
758
759AC97_ENUM("Bass Control", wm9713_enum[12]),
760AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
761AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
762AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
763AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
764AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765};
766
Takashi Iwaiee423812005-11-17 14:21:36 +0100767static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200768AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
769AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
770AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
771AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772};
773
Takashi Iwaiee423812005-11-17 14:21:36 +0100774static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200775{
776 int err, i;
777
778 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
779 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
780 return err;
781 }
782 return 0;
783}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Takashi Iwaiee423812005-11-17 14:21:36 +0100785static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
787 int err, i;
788
Liam Girdwood3998b702005-07-29 11:41:55 +0200789 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
790 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 return err;
792 }
793 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
796 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
799 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return 0;
801}
802
803#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100804static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
806 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
807 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
808}
809
Takashi Iwaiee423812005-11-17 14:21:36 +0100810static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
812 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
813 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
814 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
815}
816#endif
817
818static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
819 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200820 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821#ifdef CONFIG_PM
822 .suspend = patch_wolfson_wm9713_suspend,
823 .resume = patch_wolfson_wm9713_resume
824#endif
825};
826
Takashi Iwaiee423812005-11-17 14:21:36 +0100827int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Liam Girdwood3998b702005-07-29 11:41:55 +0200829 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 ac97->build_ops = &patch_wolfson_wm9713_ops;
831
832 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200833 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
834 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200835 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
838 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
839 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
840
841 return 0;
842}
843
844/*
845 * Tritech codec
846 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100847int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 snd_ac97_write_cache(ac97, 0x26, 0x0300);
850 snd_ac97_write_cache(ac97, 0x26, 0x0000);
851 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
852 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
853 return 0;
854}
855
856/*
857 * Sigmatel STAC97xx codecs
858 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100859static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Takashi Iwaiee423812005-11-17 14:21:36 +0100861 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 int err;
863
864 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
865 return err;
866 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
867 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
868 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
869 return 0;
870}
871
Takashi Iwaiee423812005-11-17 14:21:36 +0100872static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Takashi Iwaiee423812005-11-17 14:21:36 +0100874 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 int err;
876
877 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
878 return err;
879 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
880 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
881 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
882 return err;
883 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
884 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
885 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
886 return 0;
887}
888
Takashi Iwaiee423812005-11-17 14:21:36 +0100889static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
891
Takashi Iwaiee423812005-11-17 14:21:36 +0100892static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
894
Takashi Iwaiee423812005-11-17 14:21:36 +0100895static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
897AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
898};
899
Takashi Iwaiee423812005-11-17 14:21:36 +0100900static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
902 int err;
903
904 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
905 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
906 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
907 return err;
908 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
909 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
910 return err;
911 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
912 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
913 return err;
914 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
915 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
916 return err;
917 return 0;
918}
919
920static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
921 .build_3d = patch_sigmatel_stac9700_3d,
922 .build_specific = patch_sigmatel_stac97xx_specific
923};
924
Takashi Iwaiee423812005-11-17 14:21:36 +0100925int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
927 ac97->build_ops = &patch_sigmatel_stac9700_ops;
928 return 0;
929}
930
Takashi Iwaiee423812005-11-17 14:21:36 +0100931static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
Takashi Iwaiee423812005-11-17 14:21:36 +0100933 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 int err;
935
Ingo Molnar62932df2006-01-16 16:34:20 +0100936 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
938 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
939 (ucontrol->value.integer.value[0] & 1) << 4);
940 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100941 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return err;
943}
944
Takashi Iwaiee423812005-11-17 14:21:36 +0100945static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
947 .name = "Sigmatel Output Bias Switch",
948 .info = snd_ac97_info_volsw,
949 .get = snd_ac97_get_volsw,
950 .put = snd_ac97_stac9708_put_bias,
951 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
952};
953
Takashi Iwaiee423812005-11-17 14:21:36 +0100954static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 int err;
957
James C Georgase4c3bf02006-12-19 11:09:41 +0100958 /* the register bit is writable, but the function is not implemented: */
959 snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
962 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
963 return err;
964 return patch_sigmatel_stac97xx_specific(ac97);
965}
966
967static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
968 .build_3d = patch_sigmatel_stac9708_3d,
969 .build_specific = patch_sigmatel_stac9708_specific
970};
971
Takashi Iwaiee423812005-11-17 14:21:36 +0100972int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
974 unsigned int codec72, codec6c;
975
976 ac97->build_ops = &patch_sigmatel_stac9708_ops;
977 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
978
979 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
980 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
981
982 if ((codec72==0) && (codec6c==0)) {
983 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
984 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
985 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
986 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
987 } else if ((codec72==0x8000) && (codec6c==0)) {
988 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
991 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
992 /* nothing */
993 }
994 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
995 return 0;
996}
997
Takashi Iwaiee423812005-11-17 14:21:36 +0100998int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
1000 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1001 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1002 // patch for SigmaTel
1003 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1004 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1005 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1006 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1007 }
1008 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1009 return 0;
1010}
1011
Takashi Iwaiee423812005-11-17 14:21:36 +01001012int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 // patch for SigmaTel
1015 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1016 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1017 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1018 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1019 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1020 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1021 return 0;
1022}
1023
Takashi Iwaiee423812005-11-17 14:21:36 +01001024int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025{
1026 // patch for SigmaTel
1027 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1028 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1029 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1030 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1031 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1032 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1033 return 0;
1034}
1035
Takashi Iwaiee423812005-11-17 14:21:36 +01001036static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
1038 static char *texts[5] = { "Input/Disabled", "Front Output",
1039 "Rear Output", "Center/LFE Output", "Mixer Output" };
1040
1041 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1042 uinfo->count = 1;
1043 uinfo->value.enumerated.items = 5;
1044 if (uinfo->value.enumerated.item > 4)
1045 uinfo->value.enumerated.item = 4;
1046 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1047 return 0;
1048}
1049
Takashi Iwaiee423812005-11-17 14:21:36 +01001050static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Takashi Iwaiee423812005-11-17 14:21:36 +01001052 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 int shift = kcontrol->private_value;
1054 unsigned short val;
1055
1056 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1057 if (!(val & 4))
1058 ucontrol->value.enumerated.item[0] = 0;
1059 else
1060 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1061 return 0;
1062}
1063
Takashi Iwaiee423812005-11-17 14:21:36 +01001064static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
Takashi Iwaiee423812005-11-17 14:21:36 +01001066 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 int shift = kcontrol->private_value;
1068 unsigned short val;
1069
1070 if (ucontrol->value.enumerated.item[0] > 4)
1071 return -EINVAL;
1072 if (ucontrol->value.enumerated.item[0] == 0)
1073 val = 0;
1074 else
1075 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1076 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1077 7 << shift, val << shift, 0);
1078}
1079
Takashi Iwaiee423812005-11-17 14:21:36 +01001080static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
1082 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1083 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1084
1085 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1086 uinfo->count = 1;
1087 uinfo->value.enumerated.items = 7;
1088 if (uinfo->value.enumerated.item > 6)
1089 uinfo->value.enumerated.item = 6;
1090 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1091 return 0;
1092}
1093
Takashi Iwaiee423812005-11-17 14:21:36 +01001094static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
Takashi Iwaiee423812005-11-17 14:21:36 +01001096 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 int shift = kcontrol->private_value;
1098 unsigned short val;
1099
1100 val = ac97->regs[AC97_SIGMATEL_INSEL];
1101 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1102 return 0;
1103}
1104
Takashi Iwaiee423812005-11-17 14:21:36 +01001105static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Takashi Iwaiee423812005-11-17 14:21:36 +01001107 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 int shift = kcontrol->private_value;
1109
1110 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1111 ucontrol->value.enumerated.item[0] << shift, 0);
1112}
1113
Takashi Iwaiee423812005-11-17 14:21:36 +01001114static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
1116 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1117
1118 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1119 uinfo->count = 1;
1120 uinfo->value.enumerated.items = 3;
1121 if (uinfo->value.enumerated.item > 2)
1122 uinfo->value.enumerated.item = 2;
1123 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1124 return 0;
1125}
1126
Takashi Iwaiee423812005-11-17 14:21:36 +01001127static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Takashi Iwaiee423812005-11-17 14:21:36 +01001129 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1132 return 0;
1133}
1134
Takashi Iwaiee423812005-11-17 14:21:36 +01001135static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Takashi Iwaiee423812005-11-17 14:21:36 +01001137 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1140 ucontrol->value.enumerated.item[0], 0);
1141}
1142
1143#define STAC9758_OUTPUT_JACK(xname, shift) \
1144{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1145 .info = snd_ac97_stac9758_output_jack_info, \
1146 .get = snd_ac97_stac9758_output_jack_get, \
1147 .put = snd_ac97_stac9758_output_jack_put, \
1148 .private_value = shift }
1149#define STAC9758_INPUT_JACK(xname, shift) \
1150{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1151 .info = snd_ac97_stac9758_input_jack_info, \
1152 .get = snd_ac97_stac9758_input_jack_get, \
1153 .put = snd_ac97_stac9758_input_jack_put, \
1154 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001155static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1157 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1158 STAC9758_OUTPUT_JACK("Front Jack", 7),
1159 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1160 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1161 STAC9758_INPUT_JACK("Mic Input Source", 0),
1162 STAC9758_INPUT_JACK("Line Input Source", 8),
1163 {
1164 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1165 .name = "Headphone Amp",
1166 .info = snd_ac97_stac9758_phonesel_info,
1167 .get = snd_ac97_stac9758_phonesel_get,
1168 .put = snd_ac97_stac9758_phonesel_put
1169 },
1170 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1171 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1172};
1173
Takashi Iwaiee423812005-11-17 14:21:36 +01001174static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
1176 int err;
1177
1178 err = patch_sigmatel_stac97xx_specific(ac97);
1179 if (err < 0)
1180 return err;
1181 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1182 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1183 if (err < 0)
1184 return err;
1185 /* DAC-A direct */
1186 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1187 /* DAC-A to Mix = PCM */
1188 /* DAC-B direct = Surround */
1189 /* DAC-B to Mix */
1190 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1191 /* DAC-C direct = Center/LFE */
1192
1193 return 0;
1194}
1195
1196static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1197 .build_3d = patch_sigmatel_stac9700_3d,
1198 .build_specific = patch_sigmatel_stac9758_specific
1199};
1200
Takashi Iwaiee423812005-11-17 14:21:36 +01001201int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
1203 static unsigned short regs[4] = {
1204 AC97_SIGMATEL_OUTSEL,
1205 AC97_SIGMATEL_IOMISC,
1206 AC97_SIGMATEL_INSEL,
1207 AC97_SIGMATEL_VARIOUS
1208 };
1209 static unsigned short def_regs[4] = {
1210 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1211 /* IOMISC */ 0x2001,
1212 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1213 /* VARIOUS */ 0x0040
1214 };
1215 static unsigned short m675_regs[4] = {
1216 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1217 /* IOMISC */ 0x2102, /* HP amp on */
1218 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1219 /* VARIOUS */ 0x0041 /* stereo mic */
1220 };
1221 unsigned short *pregs = def_regs;
1222 int i;
1223
1224 /* Gateway M675 notebook */
1225 if (ac97->pci &&
1226 ac97->subsystem_vendor == 0x107b &&
1227 ac97->subsystem_device == 0x0601)
1228 pregs = m675_regs;
1229
1230 // patch for SigmaTel
1231 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1232 /* FIXME: assume only page 0 for writing cache */
1233 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1234 for (i = 0; i < 4; i++)
1235 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1236
1237 ac97->flags |= AC97_STEREO_MUTES;
1238 return 0;
1239}
1240
1241/*
1242 * Cirrus Logic CS42xx codecs
1243 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001244static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1246 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1247};
1248
Takashi Iwaiee423812005-11-17 14:21:36 +01001249static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251 int err;
1252
1253 /* con mask, pro mask, default */
1254 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1255 return err;
1256 /* switch, spsa */
1257 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1258 return err;
1259 switch (ac97->id & AC97_ID_CS_MASK) {
1260 case AC97_ID_CS4205:
1261 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1262 return err;
1263 break;
1264 }
1265 /* set default PCM S/PDIF params */
1266 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1267 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1268 return 0;
1269}
1270
1271static struct snd_ac97_build_ops patch_cirrus_ops = {
1272 .build_spdif = patch_cirrus_build_spdif
1273};
1274
Takashi Iwaiee423812005-11-17 14:21:36 +01001275int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1278 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1279 - sp/dif EA ID is not set, but sp/dif is always present.
1280 - enable/disable is spdif register bit 15.
1281 - sp/dif control register is 0x68. differs from AC97:
1282 - valid is bit 14 (vs 15)
1283 - no DRS
1284 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1285 - sp/dif ssource select is in 0x5e bits 0,1.
1286 */
1287
1288 ac97->build_ops = &patch_cirrus_ops;
1289 ac97->flags |= AC97_CS_SPDIF;
1290 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1291 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1292 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1293 return 0;
1294}
1295
Takashi Iwaiee423812005-11-17 14:21:36 +01001296int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
1298 /* force the detection of PC Beep */
1299 ac97->flags |= AC97_HAS_PC_BEEP;
1300
1301 return patch_cirrus_spdif(ac97);
1302}
1303
1304/*
1305 * Conexant codecs
1306 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001307static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1309};
1310
Takashi Iwaiee423812005-11-17 14:21:36 +01001311static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
1313 int err;
1314
1315 /* con mask, pro mask, default */
1316 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1317 return err;
1318 /* switch */
1319 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1320 return err;
1321 /* set default PCM S/PDIF params */
1322 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1323 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1324 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1325 return 0;
1326}
1327
1328static struct snd_ac97_build_ops patch_conexant_ops = {
1329 .build_spdif = patch_conexant_build_spdif
1330};
1331
Takashi Iwaiee423812005-11-17 14:21:36 +01001332int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
1334 ac97->build_ops = &patch_conexant_ops;
1335 ac97->flags |= AC97_CX_SPDIF;
1336 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1337 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1338 return 0;
1339}
1340
1341/*
1342 * Analog Device AD18xx, AD19xx codecs
1343 */
1344#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001345static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
1347 static unsigned short setup_regs[] = {
1348 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1349 };
1350 int i, codec;
1351
1352 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1353 unsigned short reg = setup_regs[i];
1354 if (test_bit(reg, ac97->reg_accessed)) {
1355 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1356 snd_ac97_read(ac97, reg);
1357 }
1358 }
1359
1360 if (! (ac97->flags & AC97_AD_MULTI))
1361 /* normal restore */
1362 snd_ac97_restore_status(ac97);
1363 else {
1364 /* restore the AD18xx codec configurations */
1365 for (codec = 0; codec < 3; codec++) {
1366 if (! ac97->spec.ad18xx.id[codec])
1367 continue;
1368 /* select single codec */
1369 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1370 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1371 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1372 }
1373 /* select all codecs */
1374 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1375
1376 /* restore status */
1377 for (i = 2; i < 0x7c ; i += 2) {
1378 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1379 continue;
1380 if (test_bit(i, ac97->reg_accessed)) {
1381 /* handle multi codecs for AD18xx */
1382 if (i == AC97_PCM) {
1383 for (codec = 0; codec < 3; codec++) {
1384 if (! ac97->spec.ad18xx.id[codec])
1385 continue;
1386 /* select single codec */
1387 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1388 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1389 /* update PCM bits */
1390 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1391 }
1392 /* select all codecs */
1393 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1394 continue;
1395 } else if (i == AC97_AD_TEST ||
1396 i == AC97_AD_CODEC_CFG ||
1397 i == AC97_AD_SERIAL_CFG)
1398 continue; /* ignore */
1399 }
1400 snd_ac97_write(ac97, i, ac97->regs[i]);
1401 snd_ac97_read(ac97, i);
1402 }
1403 }
1404
1405 snd_ac97_restore_iec958(ac97);
1406}
Jaya Kumar1561f092006-06-19 15:06:14 +02001407
1408static void ad1888_resume(struct snd_ac97 *ac97)
1409{
1410 ad18xx_resume(ac97);
1411 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1412}
1413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414#endif
1415
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001416static const struct snd_ac97_res_table ad1819_restbl[] = {
1417 { AC97_PHONE, 0x9f1f },
1418 { AC97_MIC, 0x9f1f },
1419 { AC97_LINE, 0x9f1f },
1420 { AC97_CD, 0x9f1f },
1421 { AC97_VIDEO, 0x9f1f },
1422 { AC97_AUX, 0x9f1f },
1423 { AC97_PCM, 0x9f1f },
1424 { } /* terminator */
1425};
1426
Takashi Iwaiee423812005-11-17 14:21:36 +01001427int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
1429 unsigned short scfg;
1430
1431 // patch for Analog Devices
1432 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1433 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001434 ac97->res_table = ad1819_restbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return 0;
1436}
1437
Takashi Iwaiee423812005-11-17 14:21:36 +01001438static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
1440 unsigned short val;
1441
1442 // test for unchained codec
1443 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1444 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1445 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1446 if ((val & 0xff40) != 0x5340)
1447 return 0;
1448 ac97->spec.ad18xx.unchained[idx] = mask;
1449 ac97->spec.ad18xx.id[idx] = val;
1450 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1451 return mask;
1452}
1453
Takashi Iwaiee423812005-11-17 14:21:36 +01001454static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
1456 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1457 unsigned short val;
1458
1459 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1460 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1461 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1462 if ((val & 0xff40) != 0x5340)
1463 return 0;
1464 if (codec_bits)
1465 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1466 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1467 ac97->spec.ad18xx.id[idx] = val;
1468 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1469 return 1;
1470}
1471
Takashi Iwaiee423812005-11-17 14:21:36 +01001472static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 // already detected?
1475 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1476 cidx1 = -1;
1477 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1478 cidx2 = -1;
1479 if (cidx1 < 0 && cidx2 < 0)
1480 return;
1481 // test for chained codecs
1482 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1483 ac97->spec.ad18xx.unchained[unchained_idx]);
1484 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1485 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1486 if (cidx1 >= 0) {
Takashi Iwaic19bcdc2006-11-08 15:48:43 +01001487 if (cidx2 < 0)
1488 patch_ad1881_chained1(ac97, cidx1, 0);
1489 else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 patch_ad1881_chained1(ac97, cidx2, 0);
1491 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1492 patch_ad1881_chained1(ac97, cidx1, 0);
1493 } else if (cidx2 >= 0) {
1494 patch_ad1881_chained1(ac97, cidx2, 0);
1495 }
1496}
1497
1498static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1499#ifdef CONFIG_PM
1500 .resume = ad18xx_resume
1501#endif
1502};
1503
Takashi Iwaiee423812005-11-17 14:21:36 +01001504int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
1506 static const char cfg_idxs[3][2] = {
1507 {2, 1},
1508 {0, 2},
1509 {0, 1}
1510 };
1511
1512 // patch for Analog Devices
1513 unsigned short codecs[3];
1514 unsigned short val;
1515 int idx, num;
1516
1517 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1518 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1519 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1520 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1521 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1522
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001523 if (! (codecs[0] || codecs[1] || codecs[2]))
1524 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 for (idx = 0; idx < 3; idx++)
1527 if (ac97->spec.ad18xx.unchained[idx])
1528 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1529
1530 if (ac97->spec.ad18xx.id[1]) {
1531 ac97->flags |= AC97_AD_MULTI;
1532 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1533 }
1534 if (ac97->spec.ad18xx.id[2]) {
1535 ac97->flags |= AC97_AD_MULTI;
1536 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1537 }
1538
1539 __end:
1540 /* select all codecs */
1541 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1542 /* check if only one codec is present */
1543 for (idx = num = 0; idx < 3; idx++)
1544 if (ac97->spec.ad18xx.id[idx])
1545 num++;
1546 if (num == 1) {
1547 /* ok, deselect all ID bits */
1548 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1549 ac97->spec.ad18xx.codec_cfg[0] =
1550 ac97->spec.ad18xx.codec_cfg[1] =
1551 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1552 }
1553 /* required for AD1886/AD1885 combination */
1554 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1555 if (ac97->spec.ad18xx.id[0]) {
1556 ac97->id &= 0xffff0000;
1557 ac97->id |= ac97->spec.ad18xx.id[0];
1558 }
1559 ac97->build_ops = &patch_ad1881_build_ops;
1560 return 0;
1561}
1562
Takashi Iwaiee423812005-11-17 14:21:36 +01001563static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1565 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1566 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1567 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1568 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1569 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1570};
1571
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001572static DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
1573
Takashi Iwaiee423812005-11-17 14:21:36 +01001574static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
1576 int err;
1577
1578 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1579 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001580 reset_tlv(ac97, "Headphone Playback Volume",
1581 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 return 0;
1583}
1584
1585static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1586 .build_specific = &patch_ad1885_specific,
1587#ifdef CONFIG_PM
1588 .resume = ad18xx_resume
1589#endif
1590};
1591
Takashi Iwaiee423812005-11-17 14:21:36 +01001592int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
1594 patch_ad1881(ac97);
1595 /* This is required to deal with the Intel D815EEAL2 */
1596 /* i.e. Line out is actually headphone out from codec */
1597
1598 /* set default */
1599 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1600
1601 ac97->build_ops = &patch_ad1885_build_ops;
1602 return 0;
1603}
1604
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001605static int patch_ad1886_specific(struct snd_ac97 * ac97)
1606{
1607 reset_tlv(ac97, "Headphone Playback Volume",
1608 db_scale_6bit_6db_max);
1609 return 0;
1610}
1611
1612static struct snd_ac97_build_ops patch_ad1886_build_ops = {
1613 .build_specific = &patch_ad1886_specific,
1614#ifdef CONFIG_PM
1615 .resume = ad18xx_resume
1616#endif
1617};
1618
Takashi Iwaiee423812005-11-17 14:21:36 +01001619int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
1621 patch_ad1881(ac97);
1622 /* Presario700 workaround */
1623 /* for Jack Sense/SPDIF Register misetting causing */
1624 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001625 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return 0;
1627}
1628
1629/* MISC bits */
1630#define AC97_AD198X_MBC 0x0003 /* mic boost */
1631#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1632#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1633#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1634#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1635#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1636#define AC97_AD198X_VREF_0 0x000c /* 0V */
1637#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1638#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1639#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1640#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1641#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1642#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1643#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1644#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1645#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1646#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1647#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1648#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1649
1650
Takashi Iwaiee423812005-11-17 14:21:36 +01001651static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
1653 static char *texts[2] = { "AC-Link", "A/D Converter" };
1654
1655 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1656 uinfo->count = 1;
1657 uinfo->value.enumerated.items = 2;
1658 if (uinfo->value.enumerated.item > 1)
1659 uinfo->value.enumerated.item = 1;
1660 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1661 return 0;
1662}
1663
Takashi Iwaiee423812005-11-17 14:21:36 +01001664static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
Takashi Iwaiee423812005-11-17 14:21:36 +01001666 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 unsigned short val;
1668
1669 val = ac97->regs[AC97_AD_SERIAL_CFG];
1670 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1671 return 0;
1672}
1673
Takashi Iwaiee423812005-11-17 14:21:36 +01001674static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Takashi Iwaiee423812005-11-17 14:21:36 +01001676 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 unsigned short val;
1678
1679 if (ucontrol->value.enumerated.item[0] > 1)
1680 return -EINVAL;
1681 val = ucontrol->value.enumerated.item[0] << 2;
1682 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1683}
1684
Takashi Iwaiee423812005-11-17 14:21:36 +01001685static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1687 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1688 .info = snd_ac97_ad198x_spdif_source_info,
1689 .get = snd_ac97_ad198x_spdif_source_get,
1690 .put = snd_ac97_ad198x_spdif_source_put,
1691};
1692
Takashi Iwaiee423812005-11-17 14:21:36 +01001693static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1696}
1697
Takashi Iwaiee423812005-11-17 14:21:36 +01001698static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1700 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1701};
1702
Takashi Iwai128a46a2006-01-11 18:15:43 +01001703/* black list to avoid HP/Line jack-sense controls
1704 * (SS vendor << 16 | device)
1705 */
1706static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001707 0x10140537, /* Thinkpad T41p */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001708 0x10140554, /* Thinkpad T42p/R50p */
1709 0 /* end */
1710};
1711
1712static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1713{
1714 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1715 for (; *list; list++)
1716 if (*list == subid)
1717 return 1;
1718 return 0;
1719}
1720
Takashi Iwaiee423812005-11-17 14:21:36 +01001721static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001723 if (check_list(ac97, ad1981_jacks_blacklist))
1724 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1726 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1727}
1728
1729static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1730 .build_post_spdif = patch_ad198x_post_spdif,
1731 .build_specific = patch_ad1981a_specific,
1732#ifdef CONFIG_PM
1733 .resume = ad18xx_resume
1734#endif
1735};
1736
Takashi Iwai128a46a2006-01-11 18:15:43 +01001737/* white list to enable HP jack-sense bits
1738 * (SS vendor << 16 | device)
1739 */
1740static unsigned int ad1981_jacks_whitelist[] = {
1741 0x0e11005a, /* HP nc4000/4010 */
1742 0x103c0890, /* HP nc6000 */
1743 0x103c0938, /* HP nc4220 */
1744 0x103c099c, /* HP nx6110 */
1745 0x103c0944, /* HP nc6220 */
1746 0x103c0934, /* HP nc8220 */
1747 0x103c006d, /* HP nx9105 */
1748 0x17340088, /* FSC Scenic-W */
1749 0 /* end */
1750};
1751
Takashi Iwaiee423812005-11-17 14:21:36 +01001752static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001754 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 /* enable headphone jack sense */
1756 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757}
1758
Takashi Iwaiee423812005-11-17 14:21:36 +01001759int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
1761 patch_ad1881(ac97);
1762 ac97->build_ops = &patch_ad1981a_build_ops;
1763 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1764 ac97->flags |= AC97_STEREO_MUTES;
1765 check_ad1981_hp_jack_sense(ac97);
1766 return 0;
1767}
1768
Takashi Iwaiee423812005-11-17 14:21:36 +01001769static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1771
Takashi Iwaiee423812005-11-17 14:21:36 +01001772static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 int err;
1775
1776 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1777 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001778 if (check_list(ac97, ad1981_jacks_blacklist))
1779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1781 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1782}
1783
1784static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1785 .build_post_spdif = patch_ad198x_post_spdif,
1786 .build_specific = patch_ad1981b_specific,
1787#ifdef CONFIG_PM
1788 .resume = ad18xx_resume
1789#endif
1790};
1791
Takashi Iwaiee423812005-11-17 14:21:36 +01001792int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
1794 patch_ad1881(ac97);
1795 ac97->build_ops = &patch_ad1981b_build_ops;
1796 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1797 ac97->flags |= AC97_STEREO_MUTES;
1798 check_ad1981_hp_jack_sense(ac97);
1799 return 0;
1800}
1801
Takashi Iwaiee423812005-11-17 14:21:36 +01001802static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
1804 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1805 uinfo->count = 1;
1806 uinfo->value.integer.min = 0;
1807 uinfo->value.integer.max = 1;
1808 return 0;
1809}
1810
Takashi Iwaiee423812005-11-17 14:21:36 +01001811static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
Takashi Iwaiee423812005-11-17 14:21:36 +01001813 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 unsigned short val;
1815
1816 val = ac97->regs[AC97_AD_MISC];
1817 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1818 return 0;
1819}
1820
Takashi Iwaiee423812005-11-17 14:21:36 +01001821static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
Takashi Iwaiee423812005-11-17 14:21:36 +01001823 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 unsigned short val;
1825
1826 val = !ucontrol->value.integer.value[0]
1827 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1828 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1829 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1830}
1831
Takashi Iwaiee423812005-11-17 14:21:36 +01001832static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
1834 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1835
1836 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1837 uinfo->count = 1;
1838 uinfo->value.enumerated.items = 3;
1839 if (uinfo->value.enumerated.item > 2)
1840 uinfo->value.enumerated.item = 2;
1841 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1842 return 0;
1843}
1844
Takashi Iwaiee423812005-11-17 14:21:36 +01001845static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
Takashi Iwaiee423812005-11-17 14:21:36 +01001847 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 unsigned short val;
1849
1850 val = ac97->regs[AC97_AD_MISC];
1851 if (!(val & AC97_AD198X_DMIX1))
1852 ucontrol->value.enumerated.item[0] = 0;
1853 else
1854 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1855 return 0;
1856}
1857
Takashi Iwaiee423812005-11-17 14:21:36 +01001858static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859{
Takashi Iwaiee423812005-11-17 14:21:36 +01001860 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 unsigned short val;
1862
1863 if (ucontrol->value.enumerated.item[0] > 2)
1864 return -EINVAL;
1865 if (ucontrol->value.enumerated.item[0] == 0)
1866 val = 0;
1867 else
1868 val = AC97_AD198X_DMIX1 |
1869 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1870 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1871 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1872}
1873
Takashi Iwaiee423812005-11-17 14:21:36 +01001874static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001875{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001876 unsigned short val = 0;
1877 if (! is_shared_linein(ac97))
1878 val |= (1 << 12);
1879 if (! is_shared_micin(ac97))
1880 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001881 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001882 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001883}
1884
Takashi Iwaiee423812005-11-17 14:21:36 +01001885static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 {
1887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1888 .name = "Exchange Front/Surround",
1889 .info = snd_ac97_ad1888_lohpsel_info,
1890 .get = snd_ac97_ad1888_lohpsel_get,
1891 .put = snd_ac97_ad1888_lohpsel_put
1892 },
Jaya Kumar02856b52006-06-23 15:18:41 +02001893 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1894 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1896 {
1897 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1898 .name = "Downmix",
1899 .info = snd_ac97_ad1888_downmix_info,
1900 .get = snd_ac97_ad1888_downmix_get,
1901 .put = snd_ac97_ad1888_downmix_put
1902 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001903 AC97_SURROUND_JACK_MODE_CTL,
1904 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001905
1906 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1907 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908};
1909
Takashi Iwaiee423812005-11-17 14:21:36 +01001910static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
1912 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1913 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1914 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1915 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1916}
1917
1918static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1919 .build_post_spdif = patch_ad198x_post_spdif,
1920 .build_specific = patch_ad1888_specific,
1921#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02001922 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001924 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925};
1926
Takashi Iwaiee423812005-11-17 14:21:36 +01001927int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
1929 unsigned short misc;
1930
1931 patch_ad1881(ac97);
1932 ac97->build_ops = &patch_ad1888_build_ops;
1933 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1934 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1935 /* AD-compatible mode */
1936 /* Stereo mutes enabled */
1937 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1938 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1939 AC97_AD198X_LOSEL |
1940 AC97_AD198X_HPSEL |
1941 AC97_AD198X_MSPLT |
1942 AC97_AD198X_AC97NC);
1943 ac97->flags |= AC97_STEREO_MUTES;
1944 return 0;
1945}
1946
Takashi Iwaiee423812005-11-17 14:21:36 +01001947static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
1949 int err;
1950
1951 if ((err = patch_ad1888_specific(ac97)) < 0)
1952 return err;
1953 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1954}
1955
1956static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1957 .build_post_spdif = patch_ad198x_post_spdif,
1958 .build_specific = patch_ad1980_specific,
1959#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001960 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001962 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963};
1964
Takashi Iwaiee423812005-11-17 14:21:36 +01001965int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 patch_ad1888(ac97);
1968 ac97->build_ops = &patch_ad1980_build_ops;
1969 return 0;
1970}
1971
Takashi Iwaiee423812005-11-17 14:21:36 +01001972static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1974};
1975
Takashi Iwaiee423812005-11-17 14:21:36 +01001976static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001977{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001978 ad1888_update_jacks(ac97);
Takashi Iwaifc232c62005-05-27 10:42:45 +02001979 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1980 is_shared_micin(ac97) ? 0 : 1 << 9);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001981}
1982
Takashi Iwaiee423812005-11-17 14:21:36 +01001983static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
1985 int err;
1986
1987 if ((err = patch_ad1980_specific(ac97)) < 0)
1988 return err;
1989 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1990}
1991
1992static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1993 .build_post_spdif = patch_ad198x_post_spdif,
1994 .build_specific = patch_ad1985_specific,
1995#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001996 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001998 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999};
2000
Takashi Iwaiee423812005-11-17 14:21:36 +01002001int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
2003 unsigned short misc;
2004
2005 patch_ad1881(ac97);
2006 ac97->build_ops = &patch_ad1985_build_ops;
2007 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2008 /* switch front/surround line-out/hp-out */
2009 /* center/LFE, mic in 3.75V mode */
2010 /* AD-compatible mode */
2011 /* Stereo mutes enabled */
2012 /* in accordance with ADI driver: misc | 0x5c28 */
2013 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
2014 AC97_AD198X_VREFH |
2015 AC97_AD198X_LOSEL |
2016 AC97_AD198X_HPSEL |
2017 AC97_AD198X_CLDIS |
2018 AC97_AD198X_LODIS |
2019 AC97_AD198X_MSPLT |
2020 AC97_AD198X_AC97NC);
2021 ac97->flags |= AC97_STEREO_MUTES;
2022 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2023 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2024 return 0;
2025}
2026
2027/*
2028 * realtek ALC65x/850 codecs
2029 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002030static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002032 int shared;
2033
Randy Cushman831466f2006-12-19 18:42:16 +01002034 /* shared Line-In / Surround Out */
2035 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002036 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2037 shared ? (1 << 9) : 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002038 /* update shared Mic In / Center/LFE Out */
2039 shared = is_shared_clfeout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002040 /* disable/enable vref */
2041 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2042 shared ? (1 << 12) : 0);
2043 /* turn on/off center-on-mic */
2044 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2045 shared ? (1 << 10) : 0);
2046 /* GPIO0 high for mic */
2047 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2048 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Takashi Iwaiee423812005-11-17 14:21:36 +01002051static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2053 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2054 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2055 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2056 /* 4: Analog Input To Surround */
2057 /* 5: Analog Input To Center/LFE */
2058 /* 6: Independent Master Volume Right */
2059 /* 7: Independent Master Volume Left */
2060 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002061 /* 9: Line-In/Surround share */
2062 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 /* 11-13: in IEC958 controls */
2064 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
2065#if 0 /* always set in patch_alc650 */
2066 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2067 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2068 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2069 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2070 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2071 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2072#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002073 AC97_SURROUND_JACK_MODE_CTL,
2074 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075};
2076
Takashi Iwaiee423812005-11-17 14:21:36 +01002077static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002078 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2080 /* disable this controls since it doesn't work as expected */
2081 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2082};
2083
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002084static DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
2085
Takashi Iwaiee423812005-11-17 14:21:36 +01002086static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 int err;
2089
2090 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2091 return err;
2092 if (ac97->ext_id & AC97_EI_SPDIF) {
2093 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2094 return err;
2095 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002096 if (ac97->id != AC97_ID_ALC650F)
2097 reset_tlv(ac97, "Master Playback Volume",
2098 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 return 0;
2100}
2101
2102static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002103 .build_specific = patch_alc650_specific,
2104 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105};
2106
Takashi Iwaiee423812005-11-17 14:21:36 +01002107int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
2109 unsigned short val;
2110
2111 ac97->build_ops = &patch_alc650_ops;
2112
2113 /* determine the revision */
2114 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2115 if (val < 3)
2116 ac97->id = 0x414c4720; /* Old version */
2117 else if (val < 0x10)
2118 ac97->id = 0x414c4721; /* D version */
2119 else if (val < 0x20)
2120 ac97->id = 0x414c4722; /* E version */
2121 else if (val < 0x30)
2122 ac97->id = 0x414c4723; /* F version */
2123
2124 /* revision E or F */
2125 /* FIXME: what about revision D ? */
2126 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2127 ac97->id == 0x414c4723);
2128
2129 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2130 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2131 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2132
2133 /* Enable SPDIF-IN only on Rev.E and above */
2134 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2135 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002136 if (ac97->spec.dev_flags &&
2137 /* ASUS A6KM requires EAPD */
2138 ! (ac97->subsystem_vendor == 0x1043 &&
2139 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 val |= 0x03; /* enable */
2141 else
2142 val &= ~0x03; /* disable */
2143 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2144
2145 /* set default: slot 3,4,7,8,6,9
2146 spdif-in monitor off, analog-spdif off, spdif-in off
2147 center on mic off, surround on line-in off
2148 downmix off, duplicate front off
2149 */
2150 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2151
2152 /* set GPIO0 for mic bias */
2153 /* GPIO0 pin output, no interrupt, high */
2154 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2155 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2156 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2157 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2158
2159 /* full DAC volume */
2160 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2161 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2162 return 0;
2163}
2164
Takashi Iwaiee423812005-11-17 14:21:36 +01002165static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002167 int shared;
2168
Randy Cushman831466f2006-12-19 18:42:16 +01002169 /* shared Line-In / Surround Out */
2170 shared = is_shared_surrout(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002171 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2172 shared ? (1 << 9) : 0, 0);
Randy Cushman831466f2006-12-19 18:42:16 +01002173 /* update shared Mic In / Center/LFE Out */
2174 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 /* misc control; vrefout disable */
2176 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002177 shared ? (1 << 12) : 0);
2178 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2179 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180}
2181
Takashi Iwaiee423812005-11-17 14:21:36 +01002182static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002184 AC97_SURROUND_JACK_MODE_CTL,
2185 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186};
2187
Takashi Iwaiee423812005-11-17 14:21:36 +01002188static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
2190 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2191 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002192 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
2194 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2195 uinfo->count = 1;
2196 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2197 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2198 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2199 strcpy(uinfo->value.enumerated.name,
2200 ac97->spec.dev_flags ?
2201 texts_658[uinfo->value.enumerated.item] :
2202 texts_655[uinfo->value.enumerated.item]);
2203 return 0;
2204}
2205
Takashi Iwaiee423812005-11-17 14:21:36 +01002206static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Takashi Iwaiee423812005-11-17 14:21:36 +01002208 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 unsigned short val;
2210
2211 val = ac97->regs[AC97_ALC650_MULTICH];
2212 val = (val >> 12) & 3;
2213 if (ac97->spec.dev_flags && val == 3)
2214 val = 0;
2215 ucontrol->value.enumerated.item[0] = val;
2216 return 0;
2217}
2218
Takashi Iwaiee423812005-11-17 14:21:36 +01002219static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
Takashi Iwaiee423812005-11-17 14:21:36 +01002221 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
2223 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2224 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2225 0);
2226}
2227
Takashi Iwaiee423812005-11-17 14:21:36 +01002228static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002229 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 /* disable this controls since it doesn't work as expected */
2231 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2232 {
2233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002234 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .info = alc655_iec958_route_info,
2236 .get = alc655_iec958_route_get,
2237 .put = alc655_iec958_route_put,
2238 },
2239};
2240
Takashi Iwaiee423812005-11-17 14:21:36 +01002241static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242{
2243 int err;
2244
2245 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2246 return err;
2247 if (ac97->ext_id & AC97_EI_SPDIF) {
2248 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2249 return err;
2250 }
2251 return 0;
2252}
2253
2254static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002255 .build_specific = patch_alc655_specific,
2256 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257};
2258
Takashi Iwaiee423812005-11-17 14:21:36 +01002259int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260{
2261 unsigned int val;
2262
Takashi Iwaia5022b02005-09-02 14:03:05 +02002263 if (ac97->id == AC97_ID_ALC658) {
2264 ac97->spec.dev_flags = 1; /* ALC658 */
2265 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2266 ac97->id = AC97_ID_ALC658D;
2267 ac97->spec.dev_flags = 2;
2268 }
2269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
2271 ac97->build_ops = &patch_alc655_ops;
2272
2273 /* assume only page 0 for writing cache */
2274 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2275
2276 /* adjust default values */
2277 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002278 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002280 else { /* ALC655 */
2281 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002282 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
Jaroslav Kyselae7d24f02006-10-05 09:30:36 +02002283 ac97->subsystem_device == 0x0161 || /* LG K1 Express */
Jerome Demangecbcc2c42006-10-16 21:08:57 +02002284 ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
2285 ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002286 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2287 else
2288 val |= (1 << 1); /* Pin 47 is spdif input pin */
2289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 val &= ~(1 << 12); /* vref enable */
2291 snd_ac97_write_cache(ac97, 0x7a, val);
2292 /* set default: spdif-in enabled,
2293 spdif-in monitor off, spdif-in PCM off
2294 center on mic off, surround on line-in off
2295 duplicate front off
2296 */
2297 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2298
2299 /* full DAC volume */
2300 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2301 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002302
2303 /* update undocumented bit... */
2304 if (ac97->id == AC97_ID_ALC658D)
2305 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2306
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 return 0;
2308}
2309
2310
2311#define AC97_ALC850_JACK_SELECT 0x76
2312#define AC97_ALC850_MISC1 0x7a
2313
Takashi Iwaiee423812005-11-17 14:21:36 +01002314static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002316 int shared;
2317
Randy Cushman831466f2006-12-19 18:42:16 +01002318 /* shared Line-In / Surround Out */
2319 shared = is_shared_surrout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 /* SURR 1kOhm (bit4), Amp (bit5) */
2321 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002322 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002324 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2325 shared ? (2<<12) : (0<<12));
Randy Cushman831466f2006-12-19 18:42:16 +01002326 /* update shared Mic In / Center/LFE Out */
2327 shared = is_shared_clfeout(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 /* Vref disable (bit12), 1kOhm (bit13) */
2329 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002330 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002331 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002332 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002333 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
Takashi Iwaiee423812005-11-17 14:21:36 +01002336static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002338 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002339 AC97_SURROUND_JACK_MODE_CTL,
2340 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341};
2342
Takashi Iwaiee423812005-11-17 14:21:36 +01002343static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344{
2345 int err;
2346
2347 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2348 return err;
2349 if (ac97->ext_id & AC97_EI_SPDIF) {
2350 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2351 return err;
2352 }
2353 return 0;
2354}
2355
2356static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002357 .build_specific = patch_alc850_specific,
2358 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359};
2360
Takashi Iwaiee423812005-11-17 14:21:36 +01002361int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
2363 ac97->build_ops = &patch_alc850_ops;
2364
2365 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2366
2367 /* assume only page 0 for writing cache */
2368 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2369
2370 /* adjust default values */
2371 /* set default: spdif-in enabled,
2372 spdif-in monitor off, spdif-in PCM off
2373 center on mic off, surround on line-in off
2374 duplicate front off
2375 */
2376 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2377 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2378 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2379 */
2380 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2381 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2382 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2383 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2384 */
2385 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2386 (1<<11)|(0<<12)|(1<<15));
2387
2388 /* full DAC volume */
2389 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2390 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2391 return 0;
2392}
2393
2394
2395/*
2396 * C-Media CM97xx codecs
2397 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002398static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002399{
Randy Cushman831466f2006-12-19 18:42:16 +01002400 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002401 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002402 is_shared_surrout(ac97) ? (1 << 10) : 0);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002403}
2404
Takashi Iwaiee423812005-11-17 14:21:36 +01002405static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002407 AC97_SURROUND_JACK_MODE_CTL,
2408 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409};
2410
Takashi Iwaiee423812005-11-17 14:21:36 +01002411static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
2413 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2414}
2415
2416static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002417 .build_specific = patch_cm9738_specific,
2418 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419};
2420
Takashi Iwaiee423812005-11-17 14:21:36 +01002421int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
2423 ac97->build_ops = &patch_cm9738_ops;
2424 /* FIXME: can anyone confirm below? */
2425 /* CM9738 has no PCM volume although the register reacts */
2426 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2427 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2428
2429 return 0;
2430}
2431
Takashi Iwaiee423812005-11-17 14:21:36 +01002432static 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 -07002433{
2434 static char *texts[] = { "Analog", "Digital" };
2435
2436 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2437 uinfo->count = 1;
2438 uinfo->value.enumerated.items = 2;
2439 if (uinfo->value.enumerated.item > 1)
2440 uinfo->value.enumerated.item = 1;
2441 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2442 return 0;
2443}
2444
Takashi Iwaiee423812005-11-17 14:21:36 +01002445static 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 -07002446{
Takashi Iwaiee423812005-11-17 14:21:36 +01002447 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 unsigned short val;
2449
2450 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2451 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2452 return 0;
2453}
2454
Takashi Iwaiee423812005-11-17 14:21:36 +01002455static 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 -07002456{
Takashi Iwaiee423812005-11-17 14:21:36 +01002457 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
2459 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2460 0x01 << 1,
2461 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2462}
2463
Takashi Iwaiee423812005-11-17 14:21:36 +01002464static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 /* BIT 0: SPDI_EN - always true */
2466 { /* BIT 1: SPDIFS */
2467 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2468 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2469 .info = snd_ac97_cmedia_spdif_playback_source_info,
2470 .get = snd_ac97_cmedia_spdif_playback_source_get,
2471 .put = snd_ac97_cmedia_spdif_playback_source_put,
2472 },
2473 /* BIT 2: IG_SPIV */
2474 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2475 /* BIT 3: SPI2F */
2476 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2477 /* BIT 4: SPI2SDI */
2478 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2479 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2480};
2481
Takashi Iwaiee423812005-11-17 14:21:36 +01002482static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Randy Cushman831466f2006-12-19 18:42:16 +01002484 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002485 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002486 is_shared_surrout(ac97) ? (1 << 10) : 0);
2487 /* shared Mic In / Center/LFE Out **/
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002488 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
Randy Cushman831466f2006-12-19 18:42:16 +01002489 is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
Takashi Iwaiee423812005-11-17 14:21:36 +01002492static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002493 AC97_SURROUND_JACK_MODE_CTL,
2494 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495};
2496
Takashi Iwaiee423812005-11-17 14:21:36 +01002497static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498{
2499 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2500}
2501
Takashi Iwaiee423812005-11-17 14:21:36 +01002502static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
2504 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2505}
2506
2507static struct snd_ac97_build_ops patch_cm9739_ops = {
2508 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002509 .build_post_spdif = patch_cm9739_post_spdif,
2510 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511};
2512
Takashi Iwaiee423812005-11-17 14:21:36 +01002513int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
2515 unsigned short val;
2516
2517 ac97->build_ops = &patch_cm9739_ops;
2518
2519 /* CM9739/A has no Master and PCM volume although the register reacts */
2520 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2521 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2522 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2523
2524 /* check spdif */
2525 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2526 if (val & AC97_EA_SPCV) {
2527 /* enable spdif in */
2528 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2529 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2530 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2531 } else {
2532 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2533 ac97->rates[AC97_RATES_SPDIF] = 0;
2534 }
2535
2536 /* set-up multi channel */
2537 /* bit 14: 0 = SPDIF, 1 = EAPD */
2538 /* bit 13: enable internal vref output for mic */
2539 /* bit 12: disable center/lfe (swithable) */
2540 /* bit 10: disable surround/line (switchable) */
2541 /* bit 9: mix 2 surround off */
2542 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2543 /* bit 3: undocumented; surround? */
2544 /* bit 0: dB */
2545 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2546 val |= (1 << 3);
2547 val |= (1 << 13);
2548 if (! (ac97->ext_id & AC97_EI_SPDIF))
2549 val |= (1 << 14);
2550 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2551
2552 /* FIXME: set up GPIO */
2553 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2554 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2555 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2556 if (ac97->pci &&
2557 ac97->subsystem_vendor == 0x1043 &&
2558 ac97->subsystem_device == 0x1843) {
2559 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2560 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2561 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2562 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2563 }
2564
2565 return 0;
2566}
2567
2568#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002569#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570#define AC97_CM9761_SPDIF_CTRL 0x6c
2571
Takashi Iwaiee423812005-11-17 14:21:36 +01002572static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002574 /* FIXME: check the bits for each model
2575 * model 83 is confirmed to work
2576 */
2577 static unsigned short surr_on[3][2] = {
2578 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2579 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2580 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002582 static unsigned short clfe_on[3][2] = {
2583 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2584 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2585 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002587 static unsigned short surr_shared[3][2] = {
2588 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2589 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2590 { 0x0000, 0x0400 }, /* 9761-83 */
2591 };
2592 static unsigned short clfe_shared[3][2] = {
2593 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2594 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2595 { 0x2000, 0x0800 }, /* 9761-83 */
2596 };
2597 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002598
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002599 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2600 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
Randy Cushman831466f2006-12-19 18:42:16 +01002601 val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
2602 val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002603
2604 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
Takashi Iwaiee423812005-11-17 14:21:36 +01002607static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002608 AC97_SURROUND_JACK_MODE_CTL,
2609 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610};
2611
Takashi Iwaiee423812005-11-17 14:21:36 +01002612static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002613{
2614 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2615
2616 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2617 uinfo->count = 1;
2618 uinfo->value.enumerated.items = 3;
2619 if (uinfo->value.enumerated.item > 2)
2620 uinfo->value.enumerated.item = 2;
2621 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2622 return 0;
2623}
2624
Takashi Iwaiee423812005-11-17 14:21:36 +01002625static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002626{
Takashi Iwaiee423812005-11-17 14:21:36 +01002627 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002628
2629 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2630 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2631 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2632 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2633 else
2634 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2635 return 0;
2636}
2637
Takashi Iwaiee423812005-11-17 14:21:36 +01002638static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002639{
Takashi Iwaiee423812005-11-17 14:21:36 +01002640 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002641
2642 if (ucontrol->value.enumerated.item[0] == 2)
2643 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2644 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2645 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2646 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2647}
2648
2649static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2650static const struct ac97_enum cm9761_dac_clock_enum =
2651 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2652
Takashi Iwaiee423812005-11-17 14:21:36 +01002653static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002654 { /* BIT 1: SPDIFS */
2655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2656 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2657 .info = cm9761_spdif_out_source_info,
2658 .get = cm9761_spdif_out_source_get,
2659 .put = cm9761_spdif_out_source_put,
2660 },
2661 /* BIT 2: IG_SPIV */
2662 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2663 /* BIT 3: SPI2F */
2664 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2665 /* BIT 4: SPI2SDI */
2666 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2667 /* BIT 9-10: DAC_CTL */
2668 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2669};
2670
Takashi Iwaiee423812005-11-17 14:21:36 +01002671static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002672{
2673 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2674}
2675
Takashi Iwaiee423812005-11-17 14:21:36 +01002676static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
2678 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2679}
2680
2681static struct snd_ac97_build_ops patch_cm9761_ops = {
2682 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002683 .build_post_spdif = patch_cm9761_post_spdif,
2684 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685};
2686
Takashi Iwaiee423812005-11-17 14:21:36 +01002687int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688{
2689 unsigned short val;
2690
2691 /* CM9761 has no PCM volume although the register reacts */
2692 /* Master volume seems to have _some_ influence on the analog
2693 * input sounds
2694 */
2695 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2696 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2697 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2698
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002699 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 if (ac97->id == AC97_ID_CM9761_82) {
2701 unsigned short tmp;
2702 /* check page 1, reg 0x60 */
2703 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2704 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2705 tmp = snd_ac97_read(ac97, 0x60);
2706 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2707 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002708 } else if (ac97->id == AC97_ID_CM9761_83)
2709 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 ac97->build_ops = &patch_cm9761_ops;
2712
2713 /* enable spdif */
2714 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2715 ac97->ext_id |= AC97_EI_SPDIF;
2716 /* to be sure: we overwrite the ext status bits */
2717 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2718 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002719 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2721
2722 /* set-up multi channel */
2723 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002724 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002726 * bit 12: CLFE control (reverted on rev B)
2727 * bit 11: Mic/center share (reverted on rev B)
2728 * bit 10: suddound/line share
2729 * bit 9: Analog-in mix -> surround
2730 * bit 8: Analog-in mix -> CLFE
2731 * bit 7: Mic/LFE share (mic/center/lfe)
2732 * bit 5: vref select (9761A)
2733 * bit 4: front control
2734 * bit 3: surround control (revereted with rev B)
2735 * bit 2: front mic
2736 * bit 1: stereo mic
2737 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 */
2739
2740#if 0
2741 if (ac97->spec.dev_flags)
2742 val = 0x0214;
2743 else
2744 val = 0x321c;
2745#endif
2746 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2747 val |= (1 << 4); /* front on */
2748 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2749
2750 /* FIXME: set up GPIO */
2751 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2752 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2753
2754 return 0;
2755}
2756
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002757#define AC97_CM9780_SIDE 0x60
2758#define AC97_CM9780_JACK 0x62
2759#define AC97_CM9780_MIXER 0x64
2760#define AC97_CM9780_MULTI_CHAN 0x66
2761#define AC97_CM9780_SPDIF 0x6c
2762
2763static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2764static const struct ac97_enum cm9780_ch_select_enum =
2765 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01002766static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002767 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2768 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2769 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2770};
2771
Takashi Iwaiee423812005-11-17 14:21:36 +01002772static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002773{
2774 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2775}
2776
2777static struct snd_ac97_build_ops patch_cm9780_ops = {
2778 .build_specific = patch_cm9780_specific,
2779 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2780};
2781
Takashi Iwaiee423812005-11-17 14:21:36 +01002782int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002783{
2784 unsigned short val;
2785
2786 ac97->build_ops = &patch_cm9780_ops;
2787
2788 /* enable spdif */
2789 if (ac97->ext_id & AC97_EI_SPDIF) {
2790 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2791 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2792 val |= 0x1; /* SPDI_EN */
2793 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2794 }
2795
2796 return 0;
2797}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
2799/*
2800 * VIA VT1616 codec
2801 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002802static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2804AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2805AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2806AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2807};
2808
Takashi Iwaiee423812005-11-17 14:21:36 +01002809static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
2811 int err;
2812
2813 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2814 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2815 return err;
2816 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2817 return err;
2818 return 0;
2819}
2820
2821static struct snd_ac97_build_ops patch_vt1616_ops = {
2822 .build_specific = patch_vt1616_specific
2823};
2824
Takashi Iwaiee423812005-11-17 14:21:36 +01002825int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826{
2827 ac97->build_ops = &patch_vt1616_ops;
2828 return 0;
2829}
2830
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002831/*
Philip Prindeville4b499482005-08-12 16:46:17 +02002832 * VT1617A codec
2833 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002834int patch_vt1617a(struct snd_ac97 * ac97)
Philip Prindeville4b499482005-08-12 16:46:17 +02002835{
Andrey Liakhovets9f458e7fb2006-08-28 16:52:41 +02002836 /* bring analog power consumption to normal, like WinXP driver
2837 * for EPIA SP
2838 */
2839 snd_ac97_write_cache(ac97, 0x5c, 0x20);
Philip Prindeville4b499482005-08-12 16:46:17 +02002840 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2841 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2842 return 0;
2843}
2844
2845/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002846 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002847static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002848{
Randy Cushman831466f2006-12-19 18:42:16 +01002849 /* shared Line-In / Surround Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002850 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
Randy Cushman831466f2006-12-19 18:42:16 +01002851 is_shared_surrout(ac97) ? (1<<9) : 0);
2852 /* shared Mic / Center/LFE Out */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002853 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
Randy Cushman831466f2006-12-19 18:42:16 +01002854 is_shared_clfeout(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_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002858 AC97_SURROUND_JACK_MODE_CTL,
2859 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860};
2861
Takashi Iwaiee423812005-11-17 14:21:36 +01002862static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002863 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2865 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2866};
2867
Takashi Iwaiee423812005-11-17 14:21:36 +01002868static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
2870 int err;
2871 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2872 return err;
2873 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2874 return err;
2875 return 0;
2876}
2877
2878static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002879 .build_specific = patch_it2646_specific,
2880 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881};
2882
Takashi Iwaiee423812005-11-17 14:21:36 +01002883int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884{
2885 ac97->build_ops = &patch_it2646_ops;
2886 /* full DAC volume */
2887 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2888 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2889 return 0;
2890}
2891
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002892/*
2893 * Si3036 codec
2894 */
2895
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002897#define AC97_SI3036_LINE_CFG 0x5c
2898
Takashi Iwaiee423812005-11-17 14:21:36 +01002899static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002900AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2901};
2902
Takashi Iwaiee423812005-11-17 14:21:36 +01002903static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002904{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02002905 int idx, err;
2906 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2907 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2908 return err;
2909 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002910}
2911
2912static struct snd_ac97_build_ops patch_si3036_ops = {
2913 .build_specific = patch_si3036_specific,
2914};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Takashi Iwaiee423812005-11-17 14:21:36 +01002916int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002918 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2920 snd_ac97_write_cache(ac97, 0x68, 0);
2921 return 0;
2922}
Charl Coetzeeba224292006-02-09 11:48:21 +01002923
2924/*
2925 * LM 4550 Codec
2926 *
2927 * We use a static resolution table since LM4550 codec cannot be
2928 * properly autoprobed to determine the resolution via
2929 * check_volume_resolution().
2930 */
2931
2932static struct snd_ac97_res_table lm4550_restbl[] = {
2933 { AC97_MASTER, 0x1f1f },
2934 { AC97_HEADPHONE, 0x1f1f },
2935 { AC97_MASTER_MONO, 0x001f },
2936 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2937 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01002938 { AC97_MIC, 0x001f },
2939 { AC97_LINE, 0x1f1f },
2940 { AC97_CD, 0x1f1f },
2941 { AC97_VIDEO, 0x1f1f },
2942 { AC97_AUX, 0x1f1f },
2943 { AC97_PCM, 0x1f1f },
2944 { AC97_REC_GAIN, 0x0f0f },
2945 { } /* terminator */
2946};
2947
2948int patch_lm4550(struct snd_ac97 *ac97)
2949{
2950 ac97->res_table = lm4550_restbl;
2951 return 0;
2952}
Mike Rapoport82466ad2006-06-29 17:15:33 +02002953
2954/*
2955 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
2956 */
2957static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
2958/* enable/disable headphone driver which allows direct connection to
2959 stereo headphone without the use of external DC blocking
2960 capacitors */
2961AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
2962/* Filter used to compensate the DC offset is added in the ADC to remove idle
2963 tones from the audio band. */
2964AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
2965/* Control smart-low-power mode feature. Allows automatic power down
2966 of unused blocks in the ADC analog front end and the PLL. */
2967AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
2968};
2969
2970static int patch_ucb1400_specific(struct snd_ac97 * ac97)
2971{
2972 int idx, err;
2973 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
2974 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
2975 return err;
2976 return 0;
2977}
2978
2979static struct snd_ac97_build_ops patch_ucb1400_ops = {
2980 .build_specific = patch_ucb1400_specific,
2981};
2982
2983int patch_ucb1400(struct snd_ac97 * ac97)
2984{
2985 ac97->build_ops = &patch_ucb1400_ops;
2986 /* enable headphone driver and smart low power mode by default */
2987 snd_ac97_write(ac97, 0x6a, 0x0050);
2988 snd_ac97_write(ac97, 0x6c, 0x0030);
2989 return 0;
2990}