blob: 15be6ba87c82f85e95fd661a311f19133a285f4a [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
Takashi Iwaiee423812005-11-17 14:21:36 +0100193static inline int is_shared_linein(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200194{
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200195 return ! ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200196}
197
Takashi Iwaiee423812005-11-17 14:21:36 +0100198static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200199{
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200200 return ! ac97->indep_surround && is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200201}
202
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
205
206/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100207static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 static char *texts[3] = {
210 "Standard", "Small", "Smaller"
211 };
212
213 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
214 uinfo->count = 1;
215 uinfo->value.enumerated.items = 3;
216 if (uinfo->value.enumerated.item > 2)
217 uinfo->value.enumerated.item = 2;
218 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
219 return 0;
220}
221
Takashi Iwaiee423812005-11-17 14:21:36 +0100222static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Takashi Iwaiee423812005-11-17 14:21:36 +0100224 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 unsigned short val;
226
227 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
228 val = (val >> 10) & 3;
229 if (val > 0) /* 0 = invalid */
230 val--;
231 ucontrol->value.enumerated.item[0] = val;
232 return 0;
233}
234
Takashi Iwaiee423812005-11-17 14:21:36 +0100235static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Takashi Iwaiee423812005-11-17 14:21:36 +0100237 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 unsigned short val;
239
240 if (ucontrol->value.enumerated.item[0] > 2)
241 return -EINVAL;
242 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
243 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
244}
245
Takashi Iwaiee423812005-11-17 14:21:36 +0100246static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
249 .name = "3D Control - Speaker",
250 .info = snd_ac97_ymf753_info_speaker,
251 .get = snd_ac97_ymf753_get_speaker,
252 .put = snd_ac97_ymf753_put_speaker,
253};
254
255/* 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 +0100256static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 static char *texts[2] = { "AC-Link", "A/D Converter" };
259
260 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
261 uinfo->count = 1;
262 uinfo->value.enumerated.items = 2;
263 if (uinfo->value.enumerated.item > 1)
264 uinfo->value.enumerated.item = 1;
265 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
266 return 0;
267}
268
Takashi Iwaiee423812005-11-17 14:21:36 +0100269static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Takashi Iwaiee423812005-11-17 14:21:36 +0100271 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 unsigned short val;
273
274 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
275 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
276 return 0;
277}
278
Takashi Iwaiee423812005-11-17 14:21:36 +0100279static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Takashi Iwaiee423812005-11-17 14:21:36 +0100281 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 unsigned short val;
283
284 if (ucontrol->value.enumerated.item[0] > 1)
285 return -EINVAL;
286 val = ucontrol->value.enumerated.item[0] << 1;
287 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
288}
289
290/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
291 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
292 By default, no output pin is selected, and the S/PDIF signal is not output.
293 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100294static 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 -0700295{
296 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
297
298 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
299 uinfo->count = 1;
300 uinfo->value.enumerated.items = 3;
301 if (uinfo->value.enumerated.item > 2)
302 uinfo->value.enumerated.item = 2;
303 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
304 return 0;
305}
306
Takashi Iwaiee423812005-11-17 14:21:36 +0100307static 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 -0700308{
Takashi Iwaiee423812005-11-17 14:21:36 +0100309 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 unsigned short val;
311
312 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
313 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
314 return 0;
315}
316
Takashi Iwaiee423812005-11-17 14:21:36 +0100317static 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 -0700318{
Takashi Iwaiee423812005-11-17 14:21:36 +0100319 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 unsigned short val;
321
322 if (ucontrol->value.enumerated.item[0] > 2)
323 return -EINVAL;
324 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
325 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
326 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
327 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
328 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
329}
330
Takashi Iwaiee423812005-11-17 14:21:36 +0100331static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 {
333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
334 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
335 .info = snd_ac97_ymf753_spdif_source_info,
336 .get = snd_ac97_ymf753_spdif_source_get,
337 .put = snd_ac97_ymf753_spdif_source_put,
338 },
339 {
340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
341 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
342 .info = snd_ac97_ymf753_spdif_output_pin_info,
343 .get = snd_ac97_ymf753_spdif_output_pin_get,
344 .put = snd_ac97_ymf753_spdif_output_pin_put,
345 },
346 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
347};
348
Takashi Iwaiee423812005-11-17 14:21:36 +0100349static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Takashi Iwaiee423812005-11-17 14:21:36 +0100351 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 int err;
353
354 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
355 return err;
356 strcpy(kctl->id.name, "3D Control - Wide");
357 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
358 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
359 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
360 return err;
361 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
362 return 0;
363}
364
Takashi Iwaiee423812005-11-17 14:21:36 +0100365static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 int err;
368
369 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
370 return err;
371 return 0;
372}
373
374static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
375 .build_3d = patch_yamaha_ymf753_3d,
376 .build_post_spdif = patch_yamaha_ymf753_post_spdif
377};
378
Takashi Iwaiee423812005-11-17 14:21:36 +0100379int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
382 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
383 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
384 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
385 By default, no output pin is selected, and the S/PDIF signal is not output.
386 There is also a bit to mute S/PDIF output in a vendor-specific register.
387 */
388 ac97->build_ops = &patch_yamaha_ymf753_ops;
389 ac97->caps |= AC97_BC_BASS_TREBLE;
390 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
391 return 0;
392}
393
394/*
395 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
396 * removed broken wolfson00 patch.
397 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
398 */
399
Takashi Iwaiee423812005-11-17 14:21:36 +0100400static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200401AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
402AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
403};
404
Takashi Iwaiee423812005-11-17 14:21:36 +0100405static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200408 * Randolph Bentson <bentson@holmsjoen.com>
409 * WM9703/9707/9708/9717
410 */
411 int err, i;
412
413 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
414 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
415 return err;
416 }
417 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419}
Liam Girdwood3998b702005-07-29 11:41:55 +0200420
421static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
422 .build_specific = patch_wolfson_wm9703_specific,
423};
424
Takashi Iwaiee423812005-11-17 14:21:36 +0100425int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200426{
427 ac97->build_ops = &patch_wolfson_wm9703_ops;
428 return 0;
429}
430
Takashi Iwaiee423812005-11-17 14:21:36 +0100431static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200432AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
433AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
434AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
435AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
436AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
437AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
438};
439
Takashi Iwaiee423812005-11-17 14:21:36 +0100440static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200441{
442 int err, i;
443 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
444 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
445 return err;
446 }
447 /* patch for DVD noise */
448 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
449 return 0;
450}
451
452static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
453 .build_specific = patch_wolfson_wm9704_specific,
454};
455
Takashi Iwaiee423812005-11-17 14:21:36 +0100456int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Liam Girdwood3998b702005-07-29 11:41:55 +0200458 /* WM9704M/9704Q */
459 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return 0;
461}
Liam Girdwood3998b702005-07-29 11:41:55 +0200462
Takashi Iwaiee423812005-11-17 14:21:36 +0100463static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200464{
465 int err, i;
466 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
467 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
468 return err;
469 }
470 snd_ac97_write_cache(ac97, 0x72, 0x0808);
471 return 0;
472}
473
474static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
475 .build_specific = patch_wolfson_wm9705_specific,
476};
477
Takashi Iwaiee423812005-11-17 14:21:36 +0100478int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Liam Girdwood3998b702005-07-29 11:41:55 +0200480 /* WM9705, WM9710 */
481 ac97->build_ops = &patch_wolfson_wm9705_ops;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200482#ifdef CONFIG_TOUCHSCREEN_WM9705
483 /* WM9705 touchscreen uses AUX and VIDEO for touch */
Liam Girdwood8f888202006-09-07 18:07:46 +0200484 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
Rodolfo Giometti1459c782006-06-19 15:04:54 +0200485#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return 0;
487}
488
Liam Girdwood3998b702005-07-29 11:41:55 +0200489static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
490static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
491static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
492static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
493static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
494static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
495static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
496static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
497static const char* wm9711_rec_sel[] =
498 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
499static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
500
501static const struct ac97_enum wm9711_enum[] = {
502AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
503AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
504AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
505AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
506AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
507AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
508AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
509AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
510AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
511AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
512};
513
Takashi Iwaiee423812005-11-17 14:21:36 +0100514static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200515AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
516AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
517AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
518AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
519AC97_ENUM("ALC Function", wm9711_enum[0]),
520AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
521AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
522AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
523AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
524AC97_ENUM("ALC NG Type", wm9711_enum[9]),
525AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
526
527AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
528AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
529AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
530AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
531
532AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200533AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200534AC97_ENUM("Out3 Mux", wm9711_enum[2]),
535AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
536AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
537
538AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
539AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
540AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
541AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
542AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
543AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
544
545AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
546AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
547AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
548AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
549AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
550AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
551
552AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
553AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
554
555AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
556AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
557AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
558
559AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
560AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
561AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
562
563AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
564AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
565AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
566AC97_ENUM("Capture Select", wm9711_enum[8]),
567
568AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
569AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
570
571AC97_ENUM("Bass Control", wm9711_enum[5]),
572AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
573AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
574AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
575
576AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
577AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200578AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200579AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
580
581AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
582AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
583AC97_ENUM("Mic Select Source", wm9711_enum[7]),
Luke Zhang2aedbda2006-09-26 15:28:41 +0200584AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
585AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100586AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200587
588AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
589AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
590AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
591};
592
Takashi Iwaiee423812005-11-17 14:21:36 +0100593static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200594{
595 int err, i;
596
597 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
598 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
599 return err;
600 }
601 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
602 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
603 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
604 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
605 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
606 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
607 return 0;
608}
609
610static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
611 .build_specific = patch_wolfson_wm9711_specific,
612};
613
Takashi Iwaiee423812005-11-17 14:21:36 +0100614int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Liam Girdwood3998b702005-07-29 11:41:55 +0200616 /* WM9711, WM9712 */
617 ac97->build_ops = &patch_wolfson_wm9711_ops;
618
619 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
620 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return 0;
623}
624
Liam Girdwood3998b702005-07-29 11:41:55 +0200625static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200627static const char* wm9713_rec_src[] =
628 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
629 "Mono Mix", "Zh"};
630static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
631static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
632static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
633static const char* wm9713_spk_pga[] =
634 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
635static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
636static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
637static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
638static const char* wm9713_dac_inv[] =
639 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
640 "Headphone Mix Mono", "NC", "Vmid"};
641static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
642static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644static const struct ac97_enum wm9713_enum[] = {
645AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
646AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
647AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200648AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
649AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
650AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
651AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
652AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
653AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
654AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
655AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
656AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
657AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
658AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659};
660
Takashi Iwaiee423812005-11-17 14:21:36 +0100661static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200663AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
664AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
665AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
666
667AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
668AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
669AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
670AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
671
672AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
673AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
674AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
675AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100676AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200677AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
678AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
679
680AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
681AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
682AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
683AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
684
685AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
686AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
687AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
688AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
689AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
690AC97_ENUM("Capture Select", wm9713_enum[3]),
691
692AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
693AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
694AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
695AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
696AC97_ENUM("ALC Function", wm9713_enum[5]),
697AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
698AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
699AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
700AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
701AC97_ENUM("ALC NG Type", wm9713_enum[13]),
702AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
703
704AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
705AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
706AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
707AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
708AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
709AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
710
711AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
712AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
713AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
714AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
715AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
716AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
717
718AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
719AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
720AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
721AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
722AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
723AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
724
725AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
726AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
727AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
728AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
729AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
730AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
731
732AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
733AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
734AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
735AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
736AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
737AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
738
739AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
740AC97_ENUM("Master Input Mux", wm9713_enum[7]),
741AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
742AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
743AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
744
745AC97_ENUM("Bass Control", wm9713_enum[12]),
746AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
747AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
748AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
749AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
750AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751};
752
Takashi Iwaiee423812005-11-17 14:21:36 +0100753static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200754AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
755AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
756AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
757AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758};
759
Takashi Iwaiee423812005-11-17 14:21:36 +0100760static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200761{
762 int err, i;
763
764 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
765 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
766 return err;
767 }
768 return 0;
769}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Takashi Iwaiee423812005-11-17 14:21:36 +0100771static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 int err, i;
774
Liam Girdwood3998b702005-07-29 11:41:55 +0200775 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
776 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 -0700777 return err;
778 }
779 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
782 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
785 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 return 0;
787}
788
789#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100790static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
792 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
793 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
794}
795
Takashi Iwaiee423812005-11-17 14:21:36 +0100796static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
798 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
799 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
800 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
801}
802#endif
803
804static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
805 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200806 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#ifdef CONFIG_PM
808 .suspend = patch_wolfson_wm9713_suspend,
809 .resume = patch_wolfson_wm9713_resume
810#endif
811};
812
Takashi Iwaiee423812005-11-17 14:21:36 +0100813int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Liam Girdwood3998b702005-07-29 11:41:55 +0200815 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 ac97->build_ops = &patch_wolfson_wm9713_ops;
817
818 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200819 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
820 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200821 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
824 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
825 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
826
827 return 0;
828}
829
830/*
831 * Tritech codec
832 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100833int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 snd_ac97_write_cache(ac97, 0x26, 0x0300);
836 snd_ac97_write_cache(ac97, 0x26, 0x0000);
837 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
838 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
839 return 0;
840}
841
842/*
843 * Sigmatel STAC97xx codecs
844 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100845static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Takashi Iwaiee423812005-11-17 14:21:36 +0100847 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 int err;
849
850 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
851 return err;
852 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
853 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
854 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
855 return 0;
856}
857
Takashi Iwaiee423812005-11-17 14:21:36 +0100858static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Takashi Iwaiee423812005-11-17 14:21:36 +0100860 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 int err;
862
863 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
864 return err;
865 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
866 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
867 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
868 return err;
869 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
870 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
871 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
872 return 0;
873}
874
Takashi Iwaiee423812005-11-17 14:21:36 +0100875static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
877
Takashi Iwaiee423812005-11-17 14:21:36 +0100878static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
880
Takashi Iwaiee423812005-11-17 14:21:36 +0100881static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
883AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
884};
885
Takashi Iwaiee423812005-11-17 14:21:36 +0100886static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 int err;
889
890 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
891 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
892 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
893 return err;
894 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
895 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
896 return err;
897 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
898 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
899 return err;
900 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
901 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
902 return err;
903 return 0;
904}
905
906static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
907 .build_3d = patch_sigmatel_stac9700_3d,
908 .build_specific = patch_sigmatel_stac97xx_specific
909};
910
Takashi Iwaiee423812005-11-17 14:21:36 +0100911int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
913 ac97->build_ops = &patch_sigmatel_stac9700_ops;
914 return 0;
915}
916
Takashi Iwaiee423812005-11-17 14:21:36 +0100917static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
Takashi Iwaiee423812005-11-17 14:21:36 +0100919 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 int err;
921
Ingo Molnar62932df2006-01-16 16:34:20 +0100922 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
924 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
925 (ucontrol->value.integer.value[0] & 1) << 4);
926 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100927 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return err;
929}
930
Takashi Iwaiee423812005-11-17 14:21:36 +0100931static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
933 .name = "Sigmatel Output Bias Switch",
934 .info = snd_ac97_info_volsw,
935 .get = snd_ac97_get_volsw,
936 .put = snd_ac97_stac9708_put_bias,
937 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
938};
939
Takashi Iwaiee423812005-11-17 14:21:36 +0100940static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
942 int err;
943
944 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
945 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
946 return err;
947 return patch_sigmatel_stac97xx_specific(ac97);
948}
949
950static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
951 .build_3d = patch_sigmatel_stac9708_3d,
952 .build_specific = patch_sigmatel_stac9708_specific
953};
954
Takashi Iwaiee423812005-11-17 14:21:36 +0100955int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
957 unsigned int codec72, codec6c;
958
959 ac97->build_ops = &patch_sigmatel_stac9708_ops;
960 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
961
962 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
963 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
964
965 if ((codec72==0) && (codec6c==0)) {
966 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
968 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
970 } else if ((codec72==0x8000) && (codec6c==0)) {
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
972 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
973 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
974 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
975 /* nothing */
976 }
977 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
978 return 0;
979}
980
Takashi Iwaiee423812005-11-17 14:21:36 +0100981int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982{
983 ac97->build_ops = &patch_sigmatel_stac9700_ops;
984 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
985 // patch for SigmaTel
986 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
987 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
988 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
990 }
991 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
992 return 0;
993}
994
Takashi Iwaiee423812005-11-17 14:21:36 +0100995int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
997 // patch for SigmaTel
998 ac97->build_ops = &patch_sigmatel_stac9700_ops;
999 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1000 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1001 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1002 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1003 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1004 return 0;
1005}
1006
Takashi Iwaiee423812005-11-17 14:21:36 +01001007int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
1009 // patch for SigmaTel
1010 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1011 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1012 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1013 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1014 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1015 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1016 return 0;
1017}
1018
Takashi Iwaiee423812005-11-17 14:21:36 +01001019static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
1021 static char *texts[5] = { "Input/Disabled", "Front Output",
1022 "Rear Output", "Center/LFE Output", "Mixer Output" };
1023
1024 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1025 uinfo->count = 1;
1026 uinfo->value.enumerated.items = 5;
1027 if (uinfo->value.enumerated.item > 4)
1028 uinfo->value.enumerated.item = 4;
1029 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1030 return 0;
1031}
1032
Takashi Iwaiee423812005-11-17 14:21:36 +01001033static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Takashi Iwaiee423812005-11-17 14:21:36 +01001035 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 int shift = kcontrol->private_value;
1037 unsigned short val;
1038
1039 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1040 if (!(val & 4))
1041 ucontrol->value.enumerated.item[0] = 0;
1042 else
1043 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1044 return 0;
1045}
1046
Takashi Iwaiee423812005-11-17 14:21:36 +01001047static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Takashi Iwaiee423812005-11-17 14:21:36 +01001049 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 int shift = kcontrol->private_value;
1051 unsigned short val;
1052
1053 if (ucontrol->value.enumerated.item[0] > 4)
1054 return -EINVAL;
1055 if (ucontrol->value.enumerated.item[0] == 0)
1056 val = 0;
1057 else
1058 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1059 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1060 7 << shift, val << shift, 0);
1061}
1062
Takashi Iwaiee423812005-11-17 14:21:36 +01001063static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
1065 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1066 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1067
1068 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1069 uinfo->count = 1;
1070 uinfo->value.enumerated.items = 7;
1071 if (uinfo->value.enumerated.item > 6)
1072 uinfo->value.enumerated.item = 6;
1073 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1074 return 0;
1075}
1076
Takashi Iwaiee423812005-11-17 14:21:36 +01001077static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Takashi Iwaiee423812005-11-17 14:21:36 +01001079 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 int shift = kcontrol->private_value;
1081 unsigned short val;
1082
1083 val = ac97->regs[AC97_SIGMATEL_INSEL];
1084 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1085 return 0;
1086}
1087
Takashi Iwaiee423812005-11-17 14:21:36 +01001088static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Takashi Iwaiee423812005-11-17 14:21:36 +01001090 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 int shift = kcontrol->private_value;
1092
1093 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1094 ucontrol->value.enumerated.item[0] << shift, 0);
1095}
1096
Takashi Iwaiee423812005-11-17 14:21:36 +01001097static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
1099 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1100
1101 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1102 uinfo->count = 1;
1103 uinfo->value.enumerated.items = 3;
1104 if (uinfo->value.enumerated.item > 2)
1105 uinfo->value.enumerated.item = 2;
1106 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1107 return 0;
1108}
1109
Takashi Iwaiee423812005-11-17 14:21:36 +01001110static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Takashi Iwaiee423812005-11-17 14:21:36 +01001112 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1115 return 0;
1116}
1117
Takashi Iwaiee423812005-11-17 14:21:36 +01001118static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Takashi Iwaiee423812005-11-17 14:21:36 +01001120 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1123 ucontrol->value.enumerated.item[0], 0);
1124}
1125
1126#define STAC9758_OUTPUT_JACK(xname, shift) \
1127{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1128 .info = snd_ac97_stac9758_output_jack_info, \
1129 .get = snd_ac97_stac9758_output_jack_get, \
1130 .put = snd_ac97_stac9758_output_jack_put, \
1131 .private_value = shift }
1132#define STAC9758_INPUT_JACK(xname, shift) \
1133{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1134 .info = snd_ac97_stac9758_input_jack_info, \
1135 .get = snd_ac97_stac9758_input_jack_get, \
1136 .put = snd_ac97_stac9758_input_jack_put, \
1137 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001138static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1140 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1141 STAC9758_OUTPUT_JACK("Front Jack", 7),
1142 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1143 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1144 STAC9758_INPUT_JACK("Mic Input Source", 0),
1145 STAC9758_INPUT_JACK("Line Input Source", 8),
1146 {
1147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1148 .name = "Headphone Amp",
1149 .info = snd_ac97_stac9758_phonesel_info,
1150 .get = snd_ac97_stac9758_phonesel_get,
1151 .put = snd_ac97_stac9758_phonesel_put
1152 },
1153 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1154 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1155};
1156
Takashi Iwaiee423812005-11-17 14:21:36 +01001157static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
1159 int err;
1160
1161 err = patch_sigmatel_stac97xx_specific(ac97);
1162 if (err < 0)
1163 return err;
1164 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1165 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1166 if (err < 0)
1167 return err;
1168 /* DAC-A direct */
1169 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1170 /* DAC-A to Mix = PCM */
1171 /* DAC-B direct = Surround */
1172 /* DAC-B to Mix */
1173 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1174 /* DAC-C direct = Center/LFE */
1175
1176 return 0;
1177}
1178
1179static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1180 .build_3d = patch_sigmatel_stac9700_3d,
1181 .build_specific = patch_sigmatel_stac9758_specific
1182};
1183
Takashi Iwaiee423812005-11-17 14:21:36 +01001184int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
1186 static unsigned short regs[4] = {
1187 AC97_SIGMATEL_OUTSEL,
1188 AC97_SIGMATEL_IOMISC,
1189 AC97_SIGMATEL_INSEL,
1190 AC97_SIGMATEL_VARIOUS
1191 };
1192 static unsigned short def_regs[4] = {
1193 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1194 /* IOMISC */ 0x2001,
1195 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1196 /* VARIOUS */ 0x0040
1197 };
1198 static unsigned short m675_regs[4] = {
1199 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1200 /* IOMISC */ 0x2102, /* HP amp on */
1201 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1202 /* VARIOUS */ 0x0041 /* stereo mic */
1203 };
1204 unsigned short *pregs = def_regs;
1205 int i;
1206
1207 /* Gateway M675 notebook */
1208 if (ac97->pci &&
1209 ac97->subsystem_vendor == 0x107b &&
1210 ac97->subsystem_device == 0x0601)
1211 pregs = m675_regs;
1212
1213 // patch for SigmaTel
1214 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1215 /* FIXME: assume only page 0 for writing cache */
1216 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1217 for (i = 0; i < 4; i++)
1218 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1219
1220 ac97->flags |= AC97_STEREO_MUTES;
1221 return 0;
1222}
1223
1224/*
1225 * Cirrus Logic CS42xx codecs
1226 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001227static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1229 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1230};
1231
Takashi Iwaiee423812005-11-17 14:21:36 +01001232static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
1234 int err;
1235
1236 /* con mask, pro mask, default */
1237 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1238 return err;
1239 /* switch, spsa */
1240 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1241 return err;
1242 switch (ac97->id & AC97_ID_CS_MASK) {
1243 case AC97_ID_CS4205:
1244 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1245 return err;
1246 break;
1247 }
1248 /* set default PCM S/PDIF params */
1249 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1250 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1251 return 0;
1252}
1253
1254static struct snd_ac97_build_ops patch_cirrus_ops = {
1255 .build_spdif = patch_cirrus_build_spdif
1256};
1257
Takashi Iwaiee423812005-11-17 14:21:36 +01001258int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
1260 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1261 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1262 - sp/dif EA ID is not set, but sp/dif is always present.
1263 - enable/disable is spdif register bit 15.
1264 - sp/dif control register is 0x68. differs from AC97:
1265 - valid is bit 14 (vs 15)
1266 - no DRS
1267 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1268 - sp/dif ssource select is in 0x5e bits 0,1.
1269 */
1270
1271 ac97->build_ops = &patch_cirrus_ops;
1272 ac97->flags |= AC97_CS_SPDIF;
1273 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1274 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1275 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1276 return 0;
1277}
1278
Takashi Iwaiee423812005-11-17 14:21:36 +01001279int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
1281 /* force the detection of PC Beep */
1282 ac97->flags |= AC97_HAS_PC_BEEP;
1283
1284 return patch_cirrus_spdif(ac97);
1285}
1286
1287/*
1288 * Conexant codecs
1289 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001290static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1292};
1293
Takashi Iwaiee423812005-11-17 14:21:36 +01001294static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
1296 int err;
1297
1298 /* con mask, pro mask, default */
1299 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1300 return err;
1301 /* switch */
1302 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1303 return err;
1304 /* set default PCM S/PDIF params */
1305 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1306 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1307 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1308 return 0;
1309}
1310
1311static struct snd_ac97_build_ops patch_conexant_ops = {
1312 .build_spdif = patch_conexant_build_spdif
1313};
1314
Takashi Iwaiee423812005-11-17 14:21:36 +01001315int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
1317 ac97->build_ops = &patch_conexant_ops;
1318 ac97->flags |= AC97_CX_SPDIF;
1319 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1320 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1321 return 0;
1322}
1323
1324/*
1325 * Analog Device AD18xx, AD19xx codecs
1326 */
1327#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001328static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
1330 static unsigned short setup_regs[] = {
1331 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1332 };
1333 int i, codec;
1334
1335 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1336 unsigned short reg = setup_regs[i];
1337 if (test_bit(reg, ac97->reg_accessed)) {
1338 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1339 snd_ac97_read(ac97, reg);
1340 }
1341 }
1342
1343 if (! (ac97->flags & AC97_AD_MULTI))
1344 /* normal restore */
1345 snd_ac97_restore_status(ac97);
1346 else {
1347 /* restore the AD18xx codec configurations */
1348 for (codec = 0; codec < 3; codec++) {
1349 if (! ac97->spec.ad18xx.id[codec])
1350 continue;
1351 /* select single codec */
1352 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1353 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1354 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1355 }
1356 /* select all codecs */
1357 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1358
1359 /* restore status */
1360 for (i = 2; i < 0x7c ; i += 2) {
1361 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1362 continue;
1363 if (test_bit(i, ac97->reg_accessed)) {
1364 /* handle multi codecs for AD18xx */
1365 if (i == AC97_PCM) {
1366 for (codec = 0; codec < 3; codec++) {
1367 if (! ac97->spec.ad18xx.id[codec])
1368 continue;
1369 /* select single codec */
1370 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1371 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1372 /* update PCM bits */
1373 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1374 }
1375 /* select all codecs */
1376 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1377 continue;
1378 } else if (i == AC97_AD_TEST ||
1379 i == AC97_AD_CODEC_CFG ||
1380 i == AC97_AD_SERIAL_CFG)
1381 continue; /* ignore */
1382 }
1383 snd_ac97_write(ac97, i, ac97->regs[i]);
1384 snd_ac97_read(ac97, i);
1385 }
1386 }
1387
1388 snd_ac97_restore_iec958(ac97);
1389}
Jaya Kumar1561f092006-06-19 15:06:14 +02001390
1391static void ad1888_resume(struct snd_ac97 *ac97)
1392{
1393 ad18xx_resume(ac97);
1394 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1395}
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397#endif
1398
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001399static const struct snd_ac97_res_table ad1819_restbl[] = {
1400 { AC97_PHONE, 0x9f1f },
1401 { AC97_MIC, 0x9f1f },
1402 { AC97_LINE, 0x9f1f },
1403 { AC97_CD, 0x9f1f },
1404 { AC97_VIDEO, 0x9f1f },
1405 { AC97_AUX, 0x9f1f },
1406 { AC97_PCM, 0x9f1f },
1407 { } /* terminator */
1408};
1409
Takashi Iwaiee423812005-11-17 14:21:36 +01001410int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 unsigned short scfg;
1413
1414 // patch for Analog Devices
1415 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1416 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
Ville Syrjalabd25b7c2006-09-04 12:28:24 +02001417 ac97->res_table = ad1819_restbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return 0;
1419}
1420
Takashi Iwaiee423812005-11-17 14:21:36 +01001421static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
1423 unsigned short val;
1424
1425 // test for unchained codec
1426 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1427 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1428 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1429 if ((val & 0xff40) != 0x5340)
1430 return 0;
1431 ac97->spec.ad18xx.unchained[idx] = mask;
1432 ac97->spec.ad18xx.id[idx] = val;
1433 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1434 return mask;
1435}
1436
Takashi Iwaiee423812005-11-17 14:21:36 +01001437static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
1439 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1440 unsigned short val;
1441
1442 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1443 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1444 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1445 if ((val & 0xff40) != 0x5340)
1446 return 0;
1447 if (codec_bits)
1448 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1449 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1450 ac97->spec.ad18xx.id[idx] = val;
1451 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1452 return 1;
1453}
1454
Takashi Iwaiee423812005-11-17 14:21:36 +01001455static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
1457 // already detected?
1458 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1459 cidx1 = -1;
1460 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1461 cidx2 = -1;
1462 if (cidx1 < 0 && cidx2 < 0)
1463 return;
1464 // test for chained codecs
1465 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1466 ac97->spec.ad18xx.unchained[unchained_idx]);
1467 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1468 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1469 if (cidx1 >= 0) {
1470 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1471 patch_ad1881_chained1(ac97, cidx2, 0);
1472 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1473 patch_ad1881_chained1(ac97, cidx1, 0);
1474 } else if (cidx2 >= 0) {
1475 patch_ad1881_chained1(ac97, cidx2, 0);
1476 }
1477}
1478
1479static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1480#ifdef CONFIG_PM
1481 .resume = ad18xx_resume
1482#endif
1483};
1484
Takashi Iwaiee423812005-11-17 14:21:36 +01001485int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
1487 static const char cfg_idxs[3][2] = {
1488 {2, 1},
1489 {0, 2},
1490 {0, 1}
1491 };
1492
1493 // patch for Analog Devices
1494 unsigned short codecs[3];
1495 unsigned short val;
1496 int idx, num;
1497
1498 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1499 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1500 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1501 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1502 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1503
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001504 if (! (codecs[0] || codecs[1] || codecs[2]))
1505 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507 for (idx = 0; idx < 3; idx++)
1508 if (ac97->spec.ad18xx.unchained[idx])
1509 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1510
1511 if (ac97->spec.ad18xx.id[1]) {
1512 ac97->flags |= AC97_AD_MULTI;
1513 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1514 }
1515 if (ac97->spec.ad18xx.id[2]) {
1516 ac97->flags |= AC97_AD_MULTI;
1517 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1518 }
1519
1520 __end:
1521 /* select all codecs */
1522 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1523 /* check if only one codec is present */
1524 for (idx = num = 0; idx < 3; idx++)
1525 if (ac97->spec.ad18xx.id[idx])
1526 num++;
1527 if (num == 1) {
1528 /* ok, deselect all ID bits */
1529 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1530 ac97->spec.ad18xx.codec_cfg[0] =
1531 ac97->spec.ad18xx.codec_cfg[1] =
1532 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1533 }
1534 /* required for AD1886/AD1885 combination */
1535 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1536 if (ac97->spec.ad18xx.id[0]) {
1537 ac97->id &= 0xffff0000;
1538 ac97->id |= ac97->spec.ad18xx.id[0];
1539 }
1540 ac97->build_ops = &patch_ad1881_build_ops;
1541 return 0;
1542}
1543
Takashi Iwaiee423812005-11-17 14:21:36 +01001544static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1546 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1547 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1548 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1549 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1550 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1551};
1552
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001553static DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
1554
Takashi Iwaiee423812005-11-17 14:21:36 +01001555static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
1557 int err;
1558
1559 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1560 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001561 reset_tlv(ac97, "Headphone Playback Volume",
1562 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 return 0;
1564}
1565
1566static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1567 .build_specific = &patch_ad1885_specific,
1568#ifdef CONFIG_PM
1569 .resume = ad18xx_resume
1570#endif
1571};
1572
Takashi Iwaiee423812005-11-17 14:21:36 +01001573int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
1575 patch_ad1881(ac97);
1576 /* This is required to deal with the Intel D815EEAL2 */
1577 /* i.e. Line out is actually headphone out from codec */
1578
1579 /* set default */
1580 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1581
1582 ac97->build_ops = &patch_ad1885_build_ops;
1583 return 0;
1584}
1585
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001586static int patch_ad1886_specific(struct snd_ac97 * ac97)
1587{
1588 reset_tlv(ac97, "Headphone Playback Volume",
1589 db_scale_6bit_6db_max);
1590 return 0;
1591}
1592
1593static struct snd_ac97_build_ops patch_ad1886_build_ops = {
1594 .build_specific = &patch_ad1886_specific,
1595#ifdef CONFIG_PM
1596 .resume = ad18xx_resume
1597#endif
1598};
1599
Takashi Iwaiee423812005-11-17 14:21:36 +01001600int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
1602 patch_ad1881(ac97);
1603 /* Presario700 workaround */
1604 /* for Jack Sense/SPDIF Register misetting causing */
1605 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001606 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 return 0;
1608}
1609
1610/* MISC bits */
1611#define AC97_AD198X_MBC 0x0003 /* mic boost */
1612#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1613#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1614#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1615#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1616#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1617#define AC97_AD198X_VREF_0 0x000c /* 0V */
1618#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1619#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1620#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1621#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1622#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1623#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1624#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1625#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1626#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1627#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1628#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1629#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1630
1631
Takashi Iwaiee423812005-11-17 14:21:36 +01001632static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
1634 static char *texts[2] = { "AC-Link", "A/D Converter" };
1635
1636 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1637 uinfo->count = 1;
1638 uinfo->value.enumerated.items = 2;
1639 if (uinfo->value.enumerated.item > 1)
1640 uinfo->value.enumerated.item = 1;
1641 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1642 return 0;
1643}
1644
Takashi Iwaiee423812005-11-17 14:21:36 +01001645static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Takashi Iwaiee423812005-11-17 14:21:36 +01001647 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 unsigned short val;
1649
1650 val = ac97->regs[AC97_AD_SERIAL_CFG];
1651 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1652 return 0;
1653}
1654
Takashi Iwaiee423812005-11-17 14:21:36 +01001655static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Takashi Iwaiee423812005-11-17 14:21:36 +01001657 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 unsigned short val;
1659
1660 if (ucontrol->value.enumerated.item[0] > 1)
1661 return -EINVAL;
1662 val = ucontrol->value.enumerated.item[0] << 2;
1663 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1664}
1665
Takashi Iwaiee423812005-11-17 14:21:36 +01001666static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1668 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1669 .info = snd_ac97_ad198x_spdif_source_info,
1670 .get = snd_ac97_ad198x_spdif_source_get,
1671 .put = snd_ac97_ad198x_spdif_source_put,
1672};
1673
Takashi Iwaiee423812005-11-17 14:21:36 +01001674static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
1676 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1677}
1678
Takashi Iwaiee423812005-11-17 14:21:36 +01001679static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1681 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1682};
1683
Takashi Iwai128a46a2006-01-11 18:15:43 +01001684/* black list to avoid HP/Line jack-sense controls
1685 * (SS vendor << 16 | device)
1686 */
1687static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001688 0x10140537, /* Thinkpad T41p */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001689 0x10140554, /* Thinkpad T42p/R50p */
1690 0 /* end */
1691};
1692
1693static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1694{
1695 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1696 for (; *list; list++)
1697 if (*list == subid)
1698 return 1;
1699 return 0;
1700}
1701
Takashi Iwaiee423812005-11-17 14:21:36 +01001702static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001704 if (check_list(ac97, ad1981_jacks_blacklist))
1705 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1707 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1708}
1709
1710static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1711 .build_post_spdif = patch_ad198x_post_spdif,
1712 .build_specific = patch_ad1981a_specific,
1713#ifdef CONFIG_PM
1714 .resume = ad18xx_resume
1715#endif
1716};
1717
Takashi Iwai128a46a2006-01-11 18:15:43 +01001718/* white list to enable HP jack-sense bits
1719 * (SS vendor << 16 | device)
1720 */
1721static unsigned int ad1981_jacks_whitelist[] = {
1722 0x0e11005a, /* HP nc4000/4010 */
1723 0x103c0890, /* HP nc6000 */
1724 0x103c0938, /* HP nc4220 */
1725 0x103c099c, /* HP nx6110 */
1726 0x103c0944, /* HP nc6220 */
1727 0x103c0934, /* HP nc8220 */
1728 0x103c006d, /* HP nx9105 */
1729 0x17340088, /* FSC Scenic-W */
1730 0 /* end */
1731};
1732
Takashi Iwaiee423812005-11-17 14:21:36 +01001733static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001735 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 /* enable headphone jack sense */
1737 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
Takashi Iwaiee423812005-11-17 14:21:36 +01001740int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 patch_ad1881(ac97);
1743 ac97->build_ops = &patch_ad1981a_build_ops;
1744 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1745 ac97->flags |= AC97_STEREO_MUTES;
1746 check_ad1981_hp_jack_sense(ac97);
1747 return 0;
1748}
1749
Takashi Iwaiee423812005-11-17 14:21:36 +01001750static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1752
Takashi Iwaiee423812005-11-17 14:21:36 +01001753static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 int err;
1756
1757 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1758 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001759 if (check_list(ac97, ad1981_jacks_blacklist))
1760 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1762 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1763}
1764
1765static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1766 .build_post_spdif = patch_ad198x_post_spdif,
1767 .build_specific = patch_ad1981b_specific,
1768#ifdef CONFIG_PM
1769 .resume = ad18xx_resume
1770#endif
1771};
1772
Takashi Iwaiee423812005-11-17 14:21:36 +01001773int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 patch_ad1881(ac97);
1776 ac97->build_ops = &patch_ad1981b_build_ops;
1777 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1778 ac97->flags |= AC97_STEREO_MUTES;
1779 check_ad1981_hp_jack_sense(ac97);
1780 return 0;
1781}
1782
Takashi Iwaiee423812005-11-17 14:21:36 +01001783static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1786 uinfo->count = 1;
1787 uinfo->value.integer.min = 0;
1788 uinfo->value.integer.max = 1;
1789 return 0;
1790}
1791
Takashi Iwaiee423812005-11-17 14:21:36 +01001792static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
Takashi Iwaiee423812005-11-17 14:21:36 +01001794 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 unsigned short val;
1796
1797 val = ac97->regs[AC97_AD_MISC];
1798 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1799 return 0;
1800}
1801
Takashi Iwaiee423812005-11-17 14:21:36 +01001802static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
Takashi Iwaiee423812005-11-17 14:21:36 +01001804 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 unsigned short val;
1806
1807 val = !ucontrol->value.integer.value[0]
1808 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1809 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1810 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1811}
1812
Takashi Iwaiee423812005-11-17 14:21:36 +01001813static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
1815 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1816
1817 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1818 uinfo->count = 1;
1819 uinfo->value.enumerated.items = 3;
1820 if (uinfo->value.enumerated.item > 2)
1821 uinfo->value.enumerated.item = 2;
1822 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1823 return 0;
1824}
1825
Takashi Iwaiee423812005-11-17 14:21:36 +01001826static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
Takashi Iwaiee423812005-11-17 14:21:36 +01001828 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 unsigned short val;
1830
1831 val = ac97->regs[AC97_AD_MISC];
1832 if (!(val & AC97_AD198X_DMIX1))
1833 ucontrol->value.enumerated.item[0] = 0;
1834 else
1835 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1836 return 0;
1837}
1838
Takashi Iwaiee423812005-11-17 14:21:36 +01001839static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Takashi Iwaiee423812005-11-17 14:21:36 +01001841 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 unsigned short val;
1843
1844 if (ucontrol->value.enumerated.item[0] > 2)
1845 return -EINVAL;
1846 if (ucontrol->value.enumerated.item[0] == 0)
1847 val = 0;
1848 else
1849 val = AC97_AD198X_DMIX1 |
1850 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1851 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1852 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1853}
1854
Takashi Iwaiee423812005-11-17 14:21:36 +01001855static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001856{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001857 unsigned short val = 0;
1858 if (! is_shared_linein(ac97))
1859 val |= (1 << 12);
1860 if (! is_shared_micin(ac97))
1861 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001862 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001863 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001864}
1865
Takashi Iwaiee423812005-11-17 14:21:36 +01001866static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 {
1868 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1869 .name = "Exchange Front/Surround",
1870 .info = snd_ac97_ad1888_lohpsel_info,
1871 .get = snd_ac97_ad1888_lohpsel_get,
1872 .put = snd_ac97_ad1888_lohpsel_put
1873 },
Jaya Kumar02856b52006-06-23 15:18:41 +02001874 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1875 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1877 {
1878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1879 .name = "Downmix",
1880 .info = snd_ac97_ad1888_downmix_info,
1881 .get = snd_ac97_ad1888_downmix_get,
1882 .put = snd_ac97_ad1888_downmix_put
1883 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001884 AC97_SURROUND_JACK_MODE_CTL,
1885 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001886
1887 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1888 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889};
1890
Takashi Iwaiee423812005-11-17 14:21:36 +01001891static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
1893 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1894 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1895 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1896 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1897}
1898
1899static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1900 .build_post_spdif = patch_ad198x_post_spdif,
1901 .build_specific = patch_ad1888_specific,
1902#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02001903 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001905 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906};
1907
Takashi Iwaiee423812005-11-17 14:21:36 +01001908int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
1910 unsigned short misc;
1911
1912 patch_ad1881(ac97);
1913 ac97->build_ops = &patch_ad1888_build_ops;
1914 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1915 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1916 /* AD-compatible mode */
1917 /* Stereo mutes enabled */
1918 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1919 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1920 AC97_AD198X_LOSEL |
1921 AC97_AD198X_HPSEL |
1922 AC97_AD198X_MSPLT |
1923 AC97_AD198X_AC97NC);
1924 ac97->flags |= AC97_STEREO_MUTES;
1925 return 0;
1926}
1927
Takashi Iwaiee423812005-11-17 14:21:36 +01001928static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 int err;
1931
1932 if ((err = patch_ad1888_specific(ac97)) < 0)
1933 return err;
1934 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1935}
1936
1937static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1938 .build_post_spdif = patch_ad198x_post_spdif,
1939 .build_specific = patch_ad1980_specific,
1940#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001941 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001943 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944};
1945
Takashi Iwaiee423812005-11-17 14:21:36 +01001946int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 patch_ad1888(ac97);
1949 ac97->build_ops = &patch_ad1980_build_ops;
1950 return 0;
1951}
1952
Takashi Iwaiee423812005-11-17 14:21:36 +01001953static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1955};
1956
Takashi Iwaiee423812005-11-17 14:21:36 +01001957static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001958{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001959 ad1888_update_jacks(ac97);
Takashi Iwaifc232c62005-05-27 10:42:45 +02001960 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1961 is_shared_micin(ac97) ? 0 : 1 << 9);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001962}
1963
Takashi Iwaiee423812005-11-17 14:21:36 +01001964static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965{
1966 int err;
1967
1968 if ((err = patch_ad1980_specific(ac97)) < 0)
1969 return err;
1970 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1971}
1972
1973static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1974 .build_post_spdif = patch_ad198x_post_spdif,
1975 .build_specific = patch_ad1985_specific,
1976#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001977 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001979 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980};
1981
Takashi Iwaiee423812005-11-17 14:21:36 +01001982int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
1984 unsigned short misc;
1985
1986 patch_ad1881(ac97);
1987 ac97->build_ops = &patch_ad1985_build_ops;
1988 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1989 /* switch front/surround line-out/hp-out */
1990 /* center/LFE, mic in 3.75V mode */
1991 /* AD-compatible mode */
1992 /* Stereo mutes enabled */
1993 /* in accordance with ADI driver: misc | 0x5c28 */
1994 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1995 AC97_AD198X_VREFH |
1996 AC97_AD198X_LOSEL |
1997 AC97_AD198X_HPSEL |
1998 AC97_AD198X_CLDIS |
1999 AC97_AD198X_LODIS |
2000 AC97_AD198X_MSPLT |
2001 AC97_AD198X_AC97NC);
2002 ac97->flags |= AC97_STEREO_MUTES;
2003 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2004 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2005 return 0;
2006}
2007
2008/*
2009 * realtek ALC65x/850 codecs
2010 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002011static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002013 int shared;
2014
2015 /* shared Line-In */
2016 shared = is_shared_linein(ac97);
2017 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2018 shared ? (1 << 9) : 0);
2019 /* update shared Mic */
2020 shared = is_shared_micin(ac97);
2021 /* disable/enable vref */
2022 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2023 shared ? (1 << 12) : 0);
2024 /* turn on/off center-on-mic */
2025 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2026 shared ? (1 << 10) : 0);
2027 /* GPIO0 high for mic */
2028 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2029 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030}
2031
Takashi Iwaiee423812005-11-17 14:21:36 +01002032static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2034 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2035 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2036 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2037 /* 4: Analog Input To Surround */
2038 /* 5: Analog Input To Center/LFE */
2039 /* 6: Independent Master Volume Right */
2040 /* 7: Independent Master Volume Left */
2041 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002042 /* 9: Line-In/Surround share */
2043 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 /* 11-13: in IEC958 controls */
2045 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
2046#if 0 /* always set in patch_alc650 */
2047 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2048 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2049 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2050 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2051 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2052 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2053#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002054 AC97_SURROUND_JACK_MODE_CTL,
2055 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056};
2057
Takashi Iwaiee423812005-11-17 14:21:36 +01002058static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002059 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2061 /* disable this controls since it doesn't work as expected */
2062 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2063};
2064
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002065static DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
2066
Takashi Iwaiee423812005-11-17 14:21:36 +01002067static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
2069 int err;
2070
2071 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2072 return err;
2073 if (ac97->ext_id & AC97_EI_SPDIF) {
2074 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2075 return err;
2076 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002077 if (ac97->id != AC97_ID_ALC650F)
2078 reset_tlv(ac97, "Master Playback Volume",
2079 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 return 0;
2081}
2082
2083static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002084 .build_specific = patch_alc650_specific,
2085 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086};
2087
Takashi Iwaiee423812005-11-17 14:21:36 +01002088int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089{
2090 unsigned short val;
2091
2092 ac97->build_ops = &patch_alc650_ops;
2093
2094 /* determine the revision */
2095 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2096 if (val < 3)
2097 ac97->id = 0x414c4720; /* Old version */
2098 else if (val < 0x10)
2099 ac97->id = 0x414c4721; /* D version */
2100 else if (val < 0x20)
2101 ac97->id = 0x414c4722; /* E version */
2102 else if (val < 0x30)
2103 ac97->id = 0x414c4723; /* F version */
2104
2105 /* revision E or F */
2106 /* FIXME: what about revision D ? */
2107 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2108 ac97->id == 0x414c4723);
2109
2110 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2111 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2112 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2113
2114 /* Enable SPDIF-IN only on Rev.E and above */
2115 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2116 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002117 if (ac97->spec.dev_flags &&
2118 /* ASUS A6KM requires EAPD */
2119 ! (ac97->subsystem_vendor == 0x1043 &&
2120 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 val |= 0x03; /* enable */
2122 else
2123 val &= ~0x03; /* disable */
2124 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2125
2126 /* set default: slot 3,4,7,8,6,9
2127 spdif-in monitor off, analog-spdif off, spdif-in off
2128 center on mic off, surround on line-in off
2129 downmix off, duplicate front off
2130 */
2131 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2132
2133 /* set GPIO0 for mic bias */
2134 /* GPIO0 pin output, no interrupt, high */
2135 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2136 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2137 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2138 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2139
2140 /* full DAC volume */
2141 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2142 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2143 return 0;
2144}
2145
Takashi Iwaiee423812005-11-17 14:21:36 +01002146static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002148 int shared;
2149
2150 /* shared Line-In */
2151 shared = is_shared_linein(ac97);
2152 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2153 shared ? (1 << 9) : 0, 0);
2154 /* update shared mic */
2155 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 /* misc control; vrefout disable */
2157 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002158 shared ? (1 << 12) : 0);
2159 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2160 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
Takashi Iwaiee423812005-11-17 14:21:36 +01002163static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002165 AC97_SURROUND_JACK_MODE_CTL,
2166 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167};
2168
Takashi Iwaiee423812005-11-17 14:21:36 +01002169static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
2171 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2172 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002173 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2176 uinfo->count = 1;
2177 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2178 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2179 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2180 strcpy(uinfo->value.enumerated.name,
2181 ac97->spec.dev_flags ?
2182 texts_658[uinfo->value.enumerated.item] :
2183 texts_655[uinfo->value.enumerated.item]);
2184 return 0;
2185}
2186
Takashi Iwaiee423812005-11-17 14:21:36 +01002187static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
Takashi Iwaiee423812005-11-17 14:21:36 +01002189 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 unsigned short val;
2191
2192 val = ac97->regs[AC97_ALC650_MULTICH];
2193 val = (val >> 12) & 3;
2194 if (ac97->spec.dev_flags && val == 3)
2195 val = 0;
2196 ucontrol->value.enumerated.item[0] = val;
2197 return 0;
2198}
2199
Takashi Iwaiee423812005-11-17 14:21:36 +01002200static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
Takashi Iwaiee423812005-11-17 14:21:36 +01002202 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2205 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2206 0);
2207}
2208
Takashi Iwaiee423812005-11-17 14:21:36 +01002209static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002210 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 /* disable this controls since it doesn't work as expected */
2212 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2213 {
2214 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002215 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 .info = alc655_iec958_route_info,
2217 .get = alc655_iec958_route_get,
2218 .put = alc655_iec958_route_put,
2219 },
2220};
2221
Takashi Iwaiee423812005-11-17 14:21:36 +01002222static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
2224 int err;
2225
2226 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2227 return err;
2228 if (ac97->ext_id & AC97_EI_SPDIF) {
2229 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2230 return err;
2231 }
2232 return 0;
2233}
2234
2235static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002236 .build_specific = patch_alc655_specific,
2237 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238};
2239
Takashi Iwaiee423812005-11-17 14:21:36 +01002240int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241{
2242 unsigned int val;
2243
Takashi Iwaia5022b02005-09-02 14:03:05 +02002244 if (ac97->id == AC97_ID_ALC658) {
2245 ac97->spec.dev_flags = 1; /* ALC658 */
2246 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2247 ac97->id = AC97_ID_ALC658D;
2248 ac97->spec.dev_flags = 2;
2249 }
2250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
2252 ac97->build_ops = &patch_alc655_ops;
2253
2254 /* assume only page 0 for writing cache */
2255 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2256
2257 /* adjust default values */
2258 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002259 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002261 else { /* ALC655 */
2262 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002263 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2264 ac97->subsystem_device == 0x0161)) /* LG K1 Express */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002265 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2266 else
2267 val |= (1 << 1); /* Pin 47 is spdif input pin */
2268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 val &= ~(1 << 12); /* vref enable */
2270 snd_ac97_write_cache(ac97, 0x7a, val);
2271 /* set default: spdif-in enabled,
2272 spdif-in monitor off, spdif-in PCM off
2273 center on mic off, surround on line-in off
2274 duplicate front off
2275 */
2276 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2277
2278 /* full DAC volume */
2279 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2280 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002281
2282 /* update undocumented bit... */
2283 if (ac97->id == AC97_ID_ALC658D)
2284 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2285
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 return 0;
2287}
2288
2289
2290#define AC97_ALC850_JACK_SELECT 0x76
2291#define AC97_ALC850_MISC1 0x7a
2292
Takashi Iwaiee423812005-11-17 14:21:36 +01002293static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002295 int shared;
2296
2297 /* shared Line-In */
2298 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 /* SURR 1kOhm (bit4), Amp (bit5) */
2300 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002301 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002303 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2304 shared ? (2<<12) : (0<<12));
2305 /* update shared mic */
2306 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 /* Vref disable (bit12), 1kOhm (bit13) */
2308 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002309 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002310 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002311 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002312 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
Takashi Iwaiee423812005-11-17 14:21:36 +01002315static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002317 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002318 AC97_SURROUND_JACK_MODE_CTL,
2319 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320};
2321
Takashi Iwaiee423812005-11-17 14:21:36 +01002322static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323{
2324 int err;
2325
2326 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2327 return err;
2328 if (ac97->ext_id & AC97_EI_SPDIF) {
2329 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2330 return err;
2331 }
2332 return 0;
2333}
2334
2335static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002336 .build_specific = patch_alc850_specific,
2337 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338};
2339
Takashi Iwaiee423812005-11-17 14:21:36 +01002340int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
2342 ac97->build_ops = &patch_alc850_ops;
2343
2344 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2345
2346 /* assume only page 0 for writing cache */
2347 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2348
2349 /* adjust default values */
2350 /* set default: spdif-in enabled,
2351 spdif-in monitor off, spdif-in PCM off
2352 center on mic off, surround on line-in off
2353 duplicate front off
2354 */
2355 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2356 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2357 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2358 */
2359 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2360 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2361 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2362 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2363 */
2364 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2365 (1<<11)|(0<<12)|(1<<15));
2366
2367 /* full DAC volume */
2368 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2369 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2370 return 0;
2371}
2372
2373
2374/*
2375 * C-Media CM97xx codecs
2376 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002377static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002378{
2379 /* shared Line-In */
2380 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2381 is_shared_linein(ac97) ? (1 << 10) : 0);
2382}
2383
Takashi Iwaiee423812005-11-17 14:21:36 +01002384static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002386 AC97_SURROUND_JACK_MODE_CTL,
2387 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388};
2389
Takashi Iwaiee423812005-11-17 14:21:36 +01002390static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
2392 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2393}
2394
2395static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002396 .build_specific = patch_cm9738_specific,
2397 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398};
2399
Takashi Iwaiee423812005-11-17 14:21:36 +01002400int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
2402 ac97->build_ops = &patch_cm9738_ops;
2403 /* FIXME: can anyone confirm below? */
2404 /* CM9738 has no PCM volume although the register reacts */
2405 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2406 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2407
2408 return 0;
2409}
2410
Takashi Iwaiee423812005-11-17 14:21:36 +01002411static 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 -07002412{
2413 static char *texts[] = { "Analog", "Digital" };
2414
2415 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2416 uinfo->count = 1;
2417 uinfo->value.enumerated.items = 2;
2418 if (uinfo->value.enumerated.item > 1)
2419 uinfo->value.enumerated.item = 1;
2420 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2421 return 0;
2422}
2423
Takashi Iwaiee423812005-11-17 14:21:36 +01002424static 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 -07002425{
Takashi Iwaiee423812005-11-17 14:21:36 +01002426 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 unsigned short val;
2428
2429 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2430 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2431 return 0;
2432}
2433
Takashi Iwaiee423812005-11-17 14:21:36 +01002434static 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 -07002435{
Takashi Iwaiee423812005-11-17 14:21:36 +01002436 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
2438 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2439 0x01 << 1,
2440 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2441}
2442
Takashi Iwaiee423812005-11-17 14:21:36 +01002443static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 /* BIT 0: SPDI_EN - always true */
2445 { /* BIT 1: SPDIFS */
2446 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2447 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2448 .info = snd_ac97_cmedia_spdif_playback_source_info,
2449 .get = snd_ac97_cmedia_spdif_playback_source_get,
2450 .put = snd_ac97_cmedia_spdif_playback_source_put,
2451 },
2452 /* BIT 2: IG_SPIV */
2453 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2454 /* BIT 3: SPI2F */
2455 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2456 /* BIT 4: SPI2SDI */
2457 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2458 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2459};
2460
Takashi Iwaiee423812005-11-17 14:21:36 +01002461static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002463 /* shared Line-In */
2464 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2465 is_shared_linein(ac97) ? (1 << 10) : 0);
2466 /* shared Mic */
2467 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2468 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469}
2470
Takashi Iwaiee423812005-11-17 14:21:36 +01002471static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002472 AC97_SURROUND_JACK_MODE_CTL,
2473 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474};
2475
Takashi Iwaiee423812005-11-17 14:21:36 +01002476static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
2478 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2479}
2480
Takashi Iwaiee423812005-11-17 14:21:36 +01002481static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
2483 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2484}
2485
2486static struct snd_ac97_build_ops patch_cm9739_ops = {
2487 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002488 .build_post_spdif = patch_cm9739_post_spdif,
2489 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490};
2491
Takashi Iwaiee423812005-11-17 14:21:36 +01002492int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
2494 unsigned short val;
2495
2496 ac97->build_ops = &patch_cm9739_ops;
2497
2498 /* CM9739/A has no Master and PCM volume although the register reacts */
2499 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2500 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2501 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2502
2503 /* check spdif */
2504 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2505 if (val & AC97_EA_SPCV) {
2506 /* enable spdif in */
2507 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2508 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2509 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2510 } else {
2511 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2512 ac97->rates[AC97_RATES_SPDIF] = 0;
2513 }
2514
2515 /* set-up multi channel */
2516 /* bit 14: 0 = SPDIF, 1 = EAPD */
2517 /* bit 13: enable internal vref output for mic */
2518 /* bit 12: disable center/lfe (swithable) */
2519 /* bit 10: disable surround/line (switchable) */
2520 /* bit 9: mix 2 surround off */
2521 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2522 /* bit 3: undocumented; surround? */
2523 /* bit 0: dB */
2524 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2525 val |= (1 << 3);
2526 val |= (1 << 13);
2527 if (! (ac97->ext_id & AC97_EI_SPDIF))
2528 val |= (1 << 14);
2529 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2530
2531 /* FIXME: set up GPIO */
2532 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2533 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2534 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2535 if (ac97->pci &&
2536 ac97->subsystem_vendor == 0x1043 &&
2537 ac97->subsystem_device == 0x1843) {
2538 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2539 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2540 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2541 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2542 }
2543
2544 return 0;
2545}
2546
2547#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002548#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549#define AC97_CM9761_SPDIF_CTRL 0x6c
2550
Takashi Iwaiee423812005-11-17 14:21:36 +01002551static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002553 /* FIXME: check the bits for each model
2554 * model 83 is confirmed to work
2555 */
2556 static unsigned short surr_on[3][2] = {
2557 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2558 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2559 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002561 static unsigned short clfe_on[3][2] = {
2562 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2563 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2564 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002566 static unsigned short surr_shared[3][2] = {
2567 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2568 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2569 { 0x0000, 0x0400 }, /* 9761-83 */
2570 };
2571 static unsigned short clfe_shared[3][2] = {
2572 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2573 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2574 { 0x2000, 0x0800 }, /* 9761-83 */
2575 };
2576 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002577
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002578 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2579 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2580 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2581 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2582
2583 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584}
2585
Takashi Iwaiee423812005-11-17 14:21:36 +01002586static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002587 AC97_SURROUND_JACK_MODE_CTL,
2588 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589};
2590
Takashi Iwaiee423812005-11-17 14:21:36 +01002591static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002592{
2593 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2594
2595 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2596 uinfo->count = 1;
2597 uinfo->value.enumerated.items = 3;
2598 if (uinfo->value.enumerated.item > 2)
2599 uinfo->value.enumerated.item = 2;
2600 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2601 return 0;
2602}
2603
Takashi Iwaiee423812005-11-17 14:21:36 +01002604static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002605{
Takashi Iwaiee423812005-11-17 14:21:36 +01002606 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002607
2608 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2609 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2610 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2611 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2612 else
2613 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2614 return 0;
2615}
2616
Takashi Iwaiee423812005-11-17 14:21:36 +01002617static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002618{
Takashi Iwaiee423812005-11-17 14:21:36 +01002619 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002620
2621 if (ucontrol->value.enumerated.item[0] == 2)
2622 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2623 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2624 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2625 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2626}
2627
2628static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2629static const struct ac97_enum cm9761_dac_clock_enum =
2630 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2631
Takashi Iwaiee423812005-11-17 14:21:36 +01002632static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002633 { /* BIT 1: SPDIFS */
2634 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2635 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2636 .info = cm9761_spdif_out_source_info,
2637 .get = cm9761_spdif_out_source_get,
2638 .put = cm9761_spdif_out_source_put,
2639 },
2640 /* BIT 2: IG_SPIV */
2641 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2642 /* BIT 3: SPI2F */
2643 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2644 /* BIT 4: SPI2SDI */
2645 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2646 /* BIT 9-10: DAC_CTL */
2647 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2648};
2649
Takashi Iwaiee423812005-11-17 14:21:36 +01002650static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002651{
2652 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2653}
2654
Takashi Iwaiee423812005-11-17 14:21:36 +01002655static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
2657 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2658}
2659
2660static struct snd_ac97_build_ops patch_cm9761_ops = {
2661 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002662 .build_post_spdif = patch_cm9761_post_spdif,
2663 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664};
2665
Takashi Iwaiee423812005-11-17 14:21:36 +01002666int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667{
2668 unsigned short val;
2669
2670 /* CM9761 has no PCM volume although the register reacts */
2671 /* Master volume seems to have _some_ influence on the analog
2672 * input sounds
2673 */
2674 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2675 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2676 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2677
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002678 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 if (ac97->id == AC97_ID_CM9761_82) {
2680 unsigned short tmp;
2681 /* check page 1, reg 0x60 */
2682 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2683 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2684 tmp = snd_ac97_read(ac97, 0x60);
2685 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2686 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002687 } else if (ac97->id == AC97_ID_CM9761_83)
2688 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690 ac97->build_ops = &patch_cm9761_ops;
2691
2692 /* enable spdif */
2693 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2694 ac97->ext_id |= AC97_EI_SPDIF;
2695 /* to be sure: we overwrite the ext status bits */
2696 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2697 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002698 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2700
2701 /* set-up multi channel */
2702 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002703 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002705 * bit 12: CLFE control (reverted on rev B)
2706 * bit 11: Mic/center share (reverted on rev B)
2707 * bit 10: suddound/line share
2708 * bit 9: Analog-in mix -> surround
2709 * bit 8: Analog-in mix -> CLFE
2710 * bit 7: Mic/LFE share (mic/center/lfe)
2711 * bit 5: vref select (9761A)
2712 * bit 4: front control
2713 * bit 3: surround control (revereted with rev B)
2714 * bit 2: front mic
2715 * bit 1: stereo mic
2716 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 */
2718
2719#if 0
2720 if (ac97->spec.dev_flags)
2721 val = 0x0214;
2722 else
2723 val = 0x321c;
2724#endif
2725 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2726 val |= (1 << 4); /* front on */
2727 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2728
2729 /* FIXME: set up GPIO */
2730 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2731 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2732
2733 return 0;
2734}
2735
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002736#define AC97_CM9780_SIDE 0x60
2737#define AC97_CM9780_JACK 0x62
2738#define AC97_CM9780_MIXER 0x64
2739#define AC97_CM9780_MULTI_CHAN 0x66
2740#define AC97_CM9780_SPDIF 0x6c
2741
2742static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2743static const struct ac97_enum cm9780_ch_select_enum =
2744 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01002745static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002746 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2747 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2748 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2749};
2750
Takashi Iwaiee423812005-11-17 14:21:36 +01002751static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002752{
2753 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2754}
2755
2756static struct snd_ac97_build_ops patch_cm9780_ops = {
2757 .build_specific = patch_cm9780_specific,
2758 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2759};
2760
Takashi Iwaiee423812005-11-17 14:21:36 +01002761int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002762{
2763 unsigned short val;
2764
2765 ac97->build_ops = &patch_cm9780_ops;
2766
2767 /* enable spdif */
2768 if (ac97->ext_id & AC97_EI_SPDIF) {
2769 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2770 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2771 val |= 0x1; /* SPDI_EN */
2772 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2773 }
2774
2775 return 0;
2776}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
2778/*
2779 * VIA VT1616 codec
2780 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002781static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2783AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2784AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2785AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2786};
2787
Takashi Iwaiee423812005-11-17 14:21:36 +01002788static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789{
2790 int err;
2791
2792 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2793 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2794 return err;
2795 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2796 return err;
2797 return 0;
2798}
2799
2800static struct snd_ac97_build_ops patch_vt1616_ops = {
2801 .build_specific = patch_vt1616_specific
2802};
2803
Takashi Iwaiee423812005-11-17 14:21:36 +01002804int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805{
2806 ac97->build_ops = &patch_vt1616_ops;
2807 return 0;
2808}
2809
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002810/*
Philip Prindeville4b499482005-08-12 16:46:17 +02002811 * VT1617A codec
2812 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002813int patch_vt1617a(struct snd_ac97 * ac97)
Philip Prindeville4b499482005-08-12 16:46:17 +02002814{
Andrey Liakhovets9f458e72006-08-28 16:52:41 +02002815 /* bring analog power consumption to normal, like WinXP driver
2816 * for EPIA SP
2817 */
2818 snd_ac97_write_cache(ac97, 0x5c, 0x20);
Philip Prindeville4b499482005-08-12 16:46:17 +02002819 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2820 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2821 return 0;
2822}
2823
2824/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002825 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002826static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002827{
2828 /* shared Line-In */
2829 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2830 is_shared_linein(ac97) ? (1<<9) : 0);
2831 /* shared Mic */
2832 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2833 is_shared_micin(ac97) ? (1<<10) : 0);
2834}
2835
Takashi Iwaiee423812005-11-17 14:21:36 +01002836static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002837 AC97_SURROUND_JACK_MODE_CTL,
2838 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839};
2840
Takashi Iwaiee423812005-11-17 14:21:36 +01002841static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002842 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2844 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2845};
2846
Takashi Iwaiee423812005-11-17 14:21:36 +01002847static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
2849 int err;
2850 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2851 return err;
2852 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2853 return err;
2854 return 0;
2855}
2856
2857static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002858 .build_specific = patch_it2646_specific,
2859 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860};
2861
Takashi Iwaiee423812005-11-17 14:21:36 +01002862int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863{
2864 ac97->build_ops = &patch_it2646_ops;
2865 /* full DAC volume */
2866 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2867 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2868 return 0;
2869}
2870
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002871/*
2872 * Si3036 codec
2873 */
2874
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002876#define AC97_SI3036_LINE_CFG 0x5c
2877
Takashi Iwaiee423812005-11-17 14:21:36 +01002878static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002879AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2880};
2881
Takashi Iwaiee423812005-11-17 14:21:36 +01002882static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002883{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02002884 int idx, err;
2885 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2886 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2887 return err;
2888 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002889}
2890
2891static struct snd_ac97_build_ops patch_si3036_ops = {
2892 .build_specific = patch_si3036_specific,
2893};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
Takashi Iwaiee423812005-11-17 14:21:36 +01002895int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002897 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2899 snd_ac97_write_cache(ac97, 0x68, 0);
2900 return 0;
2901}
Charl Coetzeeba224292006-02-09 11:48:21 +01002902
2903/*
2904 * LM 4550 Codec
2905 *
2906 * We use a static resolution table since LM4550 codec cannot be
2907 * properly autoprobed to determine the resolution via
2908 * check_volume_resolution().
2909 */
2910
2911static struct snd_ac97_res_table lm4550_restbl[] = {
2912 { AC97_MASTER, 0x1f1f },
2913 { AC97_HEADPHONE, 0x1f1f },
2914 { AC97_MASTER_MONO, 0x001f },
2915 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2916 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01002917 { AC97_MIC, 0x001f },
2918 { AC97_LINE, 0x1f1f },
2919 { AC97_CD, 0x1f1f },
2920 { AC97_VIDEO, 0x1f1f },
2921 { AC97_AUX, 0x1f1f },
2922 { AC97_PCM, 0x1f1f },
2923 { AC97_REC_GAIN, 0x0f0f },
2924 { } /* terminator */
2925};
2926
2927int patch_lm4550(struct snd_ac97 *ac97)
2928{
2929 ac97->res_table = lm4550_restbl;
2930 return 0;
2931}
Mike Rapoport82466ad2006-06-29 17:15:33 +02002932
2933/*
2934 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
2935 */
2936static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
2937/* enable/disable headphone driver which allows direct connection to
2938 stereo headphone without the use of external DC blocking
2939 capacitors */
2940AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
2941/* Filter used to compensate the DC offset is added in the ADC to remove idle
2942 tones from the audio band. */
2943AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
2944/* Control smart-low-power mode feature. Allows automatic power down
2945 of unused blocks in the ADC analog front end and the PLL. */
2946AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
2947};
2948
2949static int patch_ucb1400_specific(struct snd_ac97 * ac97)
2950{
2951 int idx, err;
2952 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
2953 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
2954 return err;
2955 return 0;
2956}
2957
2958static struct snd_ac97_build_ops patch_ucb1400_ops = {
2959 .build_specific = patch_ucb1400_specific,
2960};
2961
2962int patch_ucb1400(struct snd_ac97 * ac97)
2963{
2964 ac97->build_ops = &patch_ucb1400_ops;
2965 /* enable headphone driver and smart low power mode by default */
2966 snd_ac97_write(ac97, 0x6a, 0x0050);
2967 snd_ac97_write(ac97, 0x6c, 0x0030);
2968 return 0;
2969}