blob: 392f6ccace5d2e172515cb64f60379d181eb2dc2 [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 */
484 ac97->flags |=3D AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
485#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),
533AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
534AC97_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]),
578AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
579AC97_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]),
584AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100585AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200586
587AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
588AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
589AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
590};
591
Takashi Iwaiee423812005-11-17 14:21:36 +0100592static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200593{
594 int err, i;
595
596 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
597 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
598 return err;
599 }
600 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
601 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
602 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
603 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
604 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
605 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
606 return 0;
607}
608
609static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
610 .build_specific = patch_wolfson_wm9711_specific,
611};
612
Takashi Iwaiee423812005-11-17 14:21:36 +0100613int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Liam Girdwood3998b702005-07-29 11:41:55 +0200615 /* WM9711, WM9712 */
616 ac97->build_ops = &patch_wolfson_wm9711_ops;
617
618 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
619 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return 0;
622}
623
Liam Girdwood3998b702005-07-29 11:41:55 +0200624static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200626static const char* wm9713_rec_src[] =
627 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
628 "Mono Mix", "Zh"};
629static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
630static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
631static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
632static const char* wm9713_spk_pga[] =
633 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
634static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
635static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
636static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
637static const char* wm9713_dac_inv[] =
638 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
639 "Headphone Mix Mono", "NC", "Vmid"};
640static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
641static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643static const struct ac97_enum wm9713_enum[] = {
644AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
645AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
646AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200647AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
648AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
649AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
650AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
651AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
652AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
653AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
654AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
655AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
656AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
657AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658};
659
Takashi Iwaiee423812005-11-17 14:21:36 +0100660static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200662AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
663AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
664AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
665
666AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
667AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
668AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
669AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
670
671AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
672AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
673AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
674AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100675AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200676AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
677AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
678
679AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
680AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
681AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
682AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
683
684AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
685AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
686AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
687AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
688AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
689AC97_ENUM("Capture Select", wm9713_enum[3]),
690
691AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
692AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
693AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
694AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
695AC97_ENUM("ALC Function", wm9713_enum[5]),
696AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
697AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
698AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
699AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
700AC97_ENUM("ALC NG Type", wm9713_enum[13]),
701AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
702
703AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
704AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
705AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
706AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
707AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
708AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
709
710AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
711AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
712AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
713AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
714AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
715AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
716
717AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
718AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
719AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
720AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
721AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
722AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
723
724AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
725AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
726AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
727AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
728AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
729AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
730
731AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
732AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
733AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
734AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
735AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
736AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
737
738AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
739AC97_ENUM("Master Input Mux", wm9713_enum[7]),
740AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
741AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
742AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
743
744AC97_ENUM("Bass Control", wm9713_enum[12]),
745AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
746AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
747AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
748AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
749AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750};
751
Takashi Iwaiee423812005-11-17 14:21:36 +0100752static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200753AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
754AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
755AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
756AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757};
758
Takashi Iwaiee423812005-11-17 14:21:36 +0100759static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200760{
761 int err, i;
762
763 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
764 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
765 return err;
766 }
767 return 0;
768}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Takashi Iwaiee423812005-11-17 14:21:36 +0100770static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 int err, i;
773
Liam Girdwood3998b702005-07-29 11:41:55 +0200774 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
775 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 -0700776 return err;
777 }
778 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
781 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
784 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return 0;
786}
787
788#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100789static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
792 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
793}
794
Takashi Iwaiee423812005-11-17 14:21:36 +0100795static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
797 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
798 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
799 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
800}
801#endif
802
803static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
804 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200805 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806#ifdef CONFIG_PM
807 .suspend = patch_wolfson_wm9713_suspend,
808 .resume = patch_wolfson_wm9713_resume
809#endif
810};
811
Takashi Iwaiee423812005-11-17 14:21:36 +0100812int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Liam Girdwood3998b702005-07-29 11:41:55 +0200814 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 ac97->build_ops = &patch_wolfson_wm9713_ops;
816
817 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200818 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
819 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200820 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
823 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
824 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
825
826 return 0;
827}
828
829/*
830 * Tritech codec
831 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100832int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834 snd_ac97_write_cache(ac97, 0x26, 0x0300);
835 snd_ac97_write_cache(ac97, 0x26, 0x0000);
836 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
837 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
838 return 0;
839}
840
841/*
842 * Sigmatel STAC97xx codecs
843 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100844static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Takashi Iwaiee423812005-11-17 14:21:36 +0100846 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 int err;
848
849 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
850 return err;
851 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
852 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
853 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
854 return 0;
855}
856
Takashi Iwaiee423812005-11-17 14:21:36 +0100857static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Takashi Iwaiee423812005-11-17 14:21:36 +0100859 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 int err;
861
862 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
863 return err;
864 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
865 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
866 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
867 return err;
868 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
869 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
870 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
871 return 0;
872}
873
Takashi Iwaiee423812005-11-17 14:21:36 +0100874static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
876
Takashi Iwaiee423812005-11-17 14:21:36 +0100877static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
879
Takashi Iwaiee423812005-11-17 14:21:36 +0100880static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
882AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
883};
884
Takashi Iwaiee423812005-11-17 14:21:36 +0100885static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
887 int err;
888
889 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
890 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
891 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
892 return err;
893 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
894 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
895 return err;
896 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
897 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
898 return err;
899 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
900 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
901 return err;
902 return 0;
903}
904
905static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
906 .build_3d = patch_sigmatel_stac9700_3d,
907 .build_specific = patch_sigmatel_stac97xx_specific
908};
909
Takashi Iwaiee423812005-11-17 14:21:36 +0100910int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
912 ac97->build_ops = &patch_sigmatel_stac9700_ops;
913 return 0;
914}
915
Takashi Iwaiee423812005-11-17 14:21:36 +0100916static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Takashi Iwaiee423812005-11-17 14:21:36 +0100918 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 int err;
920
Ingo Molnar62932df2006-01-16 16:34:20 +0100921 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
923 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
924 (ucontrol->value.integer.value[0] & 1) << 4);
925 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100926 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 return err;
928}
929
Takashi Iwaiee423812005-11-17 14:21:36 +0100930static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
932 .name = "Sigmatel Output Bias Switch",
933 .info = snd_ac97_info_volsw,
934 .get = snd_ac97_get_volsw,
935 .put = snd_ac97_stac9708_put_bias,
936 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
937};
938
Takashi Iwaiee423812005-11-17 14:21:36 +0100939static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
941 int err;
942
943 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
944 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
945 return err;
946 return patch_sigmatel_stac97xx_specific(ac97);
947}
948
949static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
950 .build_3d = patch_sigmatel_stac9708_3d,
951 .build_specific = patch_sigmatel_stac9708_specific
952};
953
Takashi Iwaiee423812005-11-17 14:21:36 +0100954int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 unsigned int codec72, codec6c;
957
958 ac97->build_ops = &patch_sigmatel_stac9708_ops;
959 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
960
961 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
962 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
963
964 if ((codec72==0) && (codec6c==0)) {
965 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
966 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
968 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
969 } else if ((codec72==0x8000) && (codec6c==0)) {
970 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
972 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
973 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
974 /* nothing */
975 }
976 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
977 return 0;
978}
979
Takashi Iwaiee423812005-11-17 14:21:36 +0100980int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
982 ac97->build_ops = &patch_sigmatel_stac9700_ops;
983 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
984 // patch for SigmaTel
985 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
986 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
987 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
988 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
989 }
990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
991 return 0;
992}
993
Takashi Iwaiee423812005-11-17 14:21:36 +0100994int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 // patch for SigmaTel
997 ac97->build_ops = &patch_sigmatel_stac9700_ops;
998 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
999 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1000 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1001 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1002 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1003 return 0;
1004}
1005
Takashi Iwaiee423812005-11-17 14:21:36 +01001006int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
1008 // patch for SigmaTel
1009 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1010 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1011 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1012 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1013 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1014 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1015 return 0;
1016}
1017
Takashi Iwaiee423812005-11-17 14:21:36 +01001018static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019{
1020 static char *texts[5] = { "Input/Disabled", "Front Output",
1021 "Rear Output", "Center/LFE Output", "Mixer Output" };
1022
1023 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1024 uinfo->count = 1;
1025 uinfo->value.enumerated.items = 5;
1026 if (uinfo->value.enumerated.item > 4)
1027 uinfo->value.enumerated.item = 4;
1028 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1029 return 0;
1030}
1031
Takashi Iwaiee423812005-11-17 14:21:36 +01001032static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Takashi Iwaiee423812005-11-17 14:21:36 +01001034 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 int shift = kcontrol->private_value;
1036 unsigned short val;
1037
1038 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1039 if (!(val & 4))
1040 ucontrol->value.enumerated.item[0] = 0;
1041 else
1042 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1043 return 0;
1044}
1045
Takashi Iwaiee423812005-11-17 14:21:36 +01001046static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
Takashi Iwaiee423812005-11-17 14:21:36 +01001048 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 int shift = kcontrol->private_value;
1050 unsigned short val;
1051
1052 if (ucontrol->value.enumerated.item[0] > 4)
1053 return -EINVAL;
1054 if (ucontrol->value.enumerated.item[0] == 0)
1055 val = 0;
1056 else
1057 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1058 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1059 7 << shift, val << shift, 0);
1060}
1061
Takashi Iwaiee423812005-11-17 14:21:36 +01001062static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1065 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1066
1067 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1068 uinfo->count = 1;
1069 uinfo->value.enumerated.items = 7;
1070 if (uinfo->value.enumerated.item > 6)
1071 uinfo->value.enumerated.item = 6;
1072 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1073 return 0;
1074}
1075
Takashi Iwaiee423812005-11-17 14:21:36 +01001076static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
Takashi Iwaiee423812005-11-17 14:21:36 +01001078 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 int shift = kcontrol->private_value;
1080 unsigned short val;
1081
1082 val = ac97->regs[AC97_SIGMATEL_INSEL];
1083 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1084 return 0;
1085}
1086
Takashi Iwaiee423812005-11-17 14:21:36 +01001087static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Takashi Iwaiee423812005-11-17 14:21:36 +01001089 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 int shift = kcontrol->private_value;
1091
1092 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1093 ucontrol->value.enumerated.item[0] << shift, 0);
1094}
1095
Takashi Iwaiee423812005-11-17 14:21:36 +01001096static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
1098 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1099
1100 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1101 uinfo->count = 1;
1102 uinfo->value.enumerated.items = 3;
1103 if (uinfo->value.enumerated.item > 2)
1104 uinfo->value.enumerated.item = 2;
1105 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1106 return 0;
1107}
1108
Takashi Iwaiee423812005-11-17 14:21:36 +01001109static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Takashi Iwaiee423812005-11-17 14:21:36 +01001111 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1114 return 0;
1115}
1116
Takashi Iwaiee423812005-11-17 14:21:36 +01001117static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Takashi Iwaiee423812005-11-17 14:21:36 +01001119 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1122 ucontrol->value.enumerated.item[0], 0);
1123}
1124
1125#define STAC9758_OUTPUT_JACK(xname, shift) \
1126{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1127 .info = snd_ac97_stac9758_output_jack_info, \
1128 .get = snd_ac97_stac9758_output_jack_get, \
1129 .put = snd_ac97_stac9758_output_jack_put, \
1130 .private_value = shift }
1131#define STAC9758_INPUT_JACK(xname, shift) \
1132{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1133 .info = snd_ac97_stac9758_input_jack_info, \
1134 .get = snd_ac97_stac9758_input_jack_get, \
1135 .put = snd_ac97_stac9758_input_jack_put, \
1136 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001137static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1139 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1140 STAC9758_OUTPUT_JACK("Front Jack", 7),
1141 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1142 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1143 STAC9758_INPUT_JACK("Mic Input Source", 0),
1144 STAC9758_INPUT_JACK("Line Input Source", 8),
1145 {
1146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1147 .name = "Headphone Amp",
1148 .info = snd_ac97_stac9758_phonesel_info,
1149 .get = snd_ac97_stac9758_phonesel_get,
1150 .put = snd_ac97_stac9758_phonesel_put
1151 },
1152 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1153 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1154};
1155
Takashi Iwaiee423812005-11-17 14:21:36 +01001156static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
1158 int err;
1159
1160 err = patch_sigmatel_stac97xx_specific(ac97);
1161 if (err < 0)
1162 return err;
1163 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1164 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1165 if (err < 0)
1166 return err;
1167 /* DAC-A direct */
1168 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1169 /* DAC-A to Mix = PCM */
1170 /* DAC-B direct = Surround */
1171 /* DAC-B to Mix */
1172 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1173 /* DAC-C direct = Center/LFE */
1174
1175 return 0;
1176}
1177
1178static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1179 .build_3d = patch_sigmatel_stac9700_3d,
1180 .build_specific = patch_sigmatel_stac9758_specific
1181};
1182
Takashi Iwaiee423812005-11-17 14:21:36 +01001183int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
1185 static unsigned short regs[4] = {
1186 AC97_SIGMATEL_OUTSEL,
1187 AC97_SIGMATEL_IOMISC,
1188 AC97_SIGMATEL_INSEL,
1189 AC97_SIGMATEL_VARIOUS
1190 };
1191 static unsigned short def_regs[4] = {
1192 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1193 /* IOMISC */ 0x2001,
1194 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1195 /* VARIOUS */ 0x0040
1196 };
1197 static unsigned short m675_regs[4] = {
1198 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1199 /* IOMISC */ 0x2102, /* HP amp on */
1200 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1201 /* VARIOUS */ 0x0041 /* stereo mic */
1202 };
1203 unsigned short *pregs = def_regs;
1204 int i;
1205
1206 /* Gateway M675 notebook */
1207 if (ac97->pci &&
1208 ac97->subsystem_vendor == 0x107b &&
1209 ac97->subsystem_device == 0x0601)
1210 pregs = m675_regs;
1211
1212 // patch for SigmaTel
1213 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1214 /* FIXME: assume only page 0 for writing cache */
1215 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1216 for (i = 0; i < 4; i++)
1217 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1218
1219 ac97->flags |= AC97_STEREO_MUTES;
1220 return 0;
1221}
1222
1223/*
1224 * Cirrus Logic CS42xx codecs
1225 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001226static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1228 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1229};
1230
Takashi Iwaiee423812005-11-17 14:21:36 +01001231static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
1233 int err;
1234
1235 /* con mask, pro mask, default */
1236 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1237 return err;
1238 /* switch, spsa */
1239 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1240 return err;
1241 switch (ac97->id & AC97_ID_CS_MASK) {
1242 case AC97_ID_CS4205:
1243 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1244 return err;
1245 break;
1246 }
1247 /* set default PCM S/PDIF params */
1248 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1249 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1250 return 0;
1251}
1252
1253static struct snd_ac97_build_ops patch_cirrus_ops = {
1254 .build_spdif = patch_cirrus_build_spdif
1255};
1256
Takashi Iwaiee423812005-11-17 14:21:36 +01001257int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1260 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1261 - sp/dif EA ID is not set, but sp/dif is always present.
1262 - enable/disable is spdif register bit 15.
1263 - sp/dif control register is 0x68. differs from AC97:
1264 - valid is bit 14 (vs 15)
1265 - no DRS
1266 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1267 - sp/dif ssource select is in 0x5e bits 0,1.
1268 */
1269
1270 ac97->build_ops = &patch_cirrus_ops;
1271 ac97->flags |= AC97_CS_SPDIF;
1272 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1273 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1274 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1275 return 0;
1276}
1277
Takashi Iwaiee423812005-11-17 14:21:36 +01001278int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
1280 /* force the detection of PC Beep */
1281 ac97->flags |= AC97_HAS_PC_BEEP;
1282
1283 return patch_cirrus_spdif(ac97);
1284}
1285
1286/*
1287 * Conexant codecs
1288 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001289static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1291};
1292
Takashi Iwaiee423812005-11-17 14:21:36 +01001293static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294{
1295 int err;
1296
1297 /* con mask, pro mask, default */
1298 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1299 return err;
1300 /* switch */
1301 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1302 return err;
1303 /* set default PCM S/PDIF params */
1304 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1305 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1306 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1307 return 0;
1308}
1309
1310static struct snd_ac97_build_ops patch_conexant_ops = {
1311 .build_spdif = patch_conexant_build_spdif
1312};
1313
Takashi Iwaiee423812005-11-17 14:21:36 +01001314int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 ac97->build_ops = &patch_conexant_ops;
1317 ac97->flags |= AC97_CX_SPDIF;
1318 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1319 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1320 return 0;
1321}
1322
1323/*
1324 * Analog Device AD18xx, AD19xx codecs
1325 */
1326#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001327static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
1329 static unsigned short setup_regs[] = {
1330 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1331 };
1332 int i, codec;
1333
1334 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1335 unsigned short reg = setup_regs[i];
1336 if (test_bit(reg, ac97->reg_accessed)) {
1337 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1338 snd_ac97_read(ac97, reg);
1339 }
1340 }
1341
1342 if (! (ac97->flags & AC97_AD_MULTI))
1343 /* normal restore */
1344 snd_ac97_restore_status(ac97);
1345 else {
1346 /* restore the AD18xx codec configurations */
1347 for (codec = 0; codec < 3; codec++) {
1348 if (! ac97->spec.ad18xx.id[codec])
1349 continue;
1350 /* select single codec */
1351 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1352 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1353 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1354 }
1355 /* select all codecs */
1356 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1357
1358 /* restore status */
1359 for (i = 2; i < 0x7c ; i += 2) {
1360 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1361 continue;
1362 if (test_bit(i, ac97->reg_accessed)) {
1363 /* handle multi codecs for AD18xx */
1364 if (i == AC97_PCM) {
1365 for (codec = 0; codec < 3; codec++) {
1366 if (! ac97->spec.ad18xx.id[codec])
1367 continue;
1368 /* select single codec */
1369 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1370 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1371 /* update PCM bits */
1372 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1373 }
1374 /* select all codecs */
1375 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1376 continue;
1377 } else if (i == AC97_AD_TEST ||
1378 i == AC97_AD_CODEC_CFG ||
1379 i == AC97_AD_SERIAL_CFG)
1380 continue; /* ignore */
1381 }
1382 snd_ac97_write(ac97, i, ac97->regs[i]);
1383 snd_ac97_read(ac97, i);
1384 }
1385 }
1386
1387 snd_ac97_restore_iec958(ac97);
1388}
Jaya Kumar1561f092006-06-19 15:06:14 +02001389
1390static void ad1888_resume(struct snd_ac97 *ac97)
1391{
1392 ad18xx_resume(ac97);
1393 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1394}
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396#endif
1397
Takashi Iwaiee423812005-11-17 14:21:36 +01001398int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
1400 unsigned short scfg;
1401
1402 // patch for Analog Devices
1403 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1404 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1405 return 0;
1406}
1407
Takashi Iwaiee423812005-11-17 14:21:36 +01001408static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409{
1410 unsigned short val;
1411
1412 // test for unchained codec
1413 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1414 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1415 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1416 if ((val & 0xff40) != 0x5340)
1417 return 0;
1418 ac97->spec.ad18xx.unchained[idx] = mask;
1419 ac97->spec.ad18xx.id[idx] = val;
1420 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1421 return mask;
1422}
1423
Takashi Iwaiee423812005-11-17 14:21:36 +01001424static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
1426 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1427 unsigned short val;
1428
1429 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1430 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1431 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1432 if ((val & 0xff40) != 0x5340)
1433 return 0;
1434 if (codec_bits)
1435 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1436 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1437 ac97->spec.ad18xx.id[idx] = val;
1438 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1439 return 1;
1440}
1441
Takashi Iwaiee423812005-11-17 14:21:36 +01001442static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
1444 // already detected?
1445 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1446 cidx1 = -1;
1447 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1448 cidx2 = -1;
1449 if (cidx1 < 0 && cidx2 < 0)
1450 return;
1451 // test for chained codecs
1452 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1453 ac97->spec.ad18xx.unchained[unchained_idx]);
1454 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1455 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1456 if (cidx1 >= 0) {
1457 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1458 patch_ad1881_chained1(ac97, cidx2, 0);
1459 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1460 patch_ad1881_chained1(ac97, cidx1, 0);
1461 } else if (cidx2 >= 0) {
1462 patch_ad1881_chained1(ac97, cidx2, 0);
1463 }
1464}
1465
1466static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1467#ifdef CONFIG_PM
1468 .resume = ad18xx_resume
1469#endif
1470};
1471
Takashi Iwaiee423812005-11-17 14:21:36 +01001472int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 static const char cfg_idxs[3][2] = {
1475 {2, 1},
1476 {0, 2},
1477 {0, 1}
1478 };
1479
1480 // patch for Analog Devices
1481 unsigned short codecs[3];
1482 unsigned short val;
1483 int idx, num;
1484
1485 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1486 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1487 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1488 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1489 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1490
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001491 if (! (codecs[0] || codecs[1] || codecs[2]))
1492 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 for (idx = 0; idx < 3; idx++)
1495 if (ac97->spec.ad18xx.unchained[idx])
1496 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1497
1498 if (ac97->spec.ad18xx.id[1]) {
1499 ac97->flags |= AC97_AD_MULTI;
1500 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1501 }
1502 if (ac97->spec.ad18xx.id[2]) {
1503 ac97->flags |= AC97_AD_MULTI;
1504 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1505 }
1506
1507 __end:
1508 /* select all codecs */
1509 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1510 /* check if only one codec is present */
1511 for (idx = num = 0; idx < 3; idx++)
1512 if (ac97->spec.ad18xx.id[idx])
1513 num++;
1514 if (num == 1) {
1515 /* ok, deselect all ID bits */
1516 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1517 ac97->spec.ad18xx.codec_cfg[0] =
1518 ac97->spec.ad18xx.codec_cfg[1] =
1519 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1520 }
1521 /* required for AD1886/AD1885 combination */
1522 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1523 if (ac97->spec.ad18xx.id[0]) {
1524 ac97->id &= 0xffff0000;
1525 ac97->id |= ac97->spec.ad18xx.id[0];
1526 }
1527 ac97->build_ops = &patch_ad1881_build_ops;
1528 return 0;
1529}
1530
Takashi Iwaiee423812005-11-17 14:21:36 +01001531static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1533 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1534 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1535 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1536 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1537 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1538};
1539
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001540static DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
1541
Takashi Iwaiee423812005-11-17 14:21:36 +01001542static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
1544 int err;
1545
1546 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1547 return err;
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001548 reset_tlv(ac97, "Headphone Playback Volume",
1549 db_scale_6bit_6db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return 0;
1551}
1552
1553static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1554 .build_specific = &patch_ad1885_specific,
1555#ifdef CONFIG_PM
1556 .resume = ad18xx_resume
1557#endif
1558};
1559
Takashi Iwaiee423812005-11-17 14:21:36 +01001560int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
1562 patch_ad1881(ac97);
1563 /* This is required to deal with the Intel D815EEAL2 */
1564 /* i.e. Line out is actually headphone out from codec */
1565
1566 /* set default */
1567 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1568
1569 ac97->build_ops = &patch_ad1885_build_ops;
1570 return 0;
1571}
1572
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001573static int patch_ad1886_specific(struct snd_ac97 * ac97)
1574{
1575 reset_tlv(ac97, "Headphone Playback Volume",
1576 db_scale_6bit_6db_max);
1577 return 0;
1578}
1579
1580static struct snd_ac97_build_ops patch_ad1886_build_ops = {
1581 .build_specific = &patch_ad1886_specific,
1582#ifdef CONFIG_PM
1583 .resume = ad18xx_resume
1584#endif
1585};
1586
Takashi Iwaiee423812005-11-17 14:21:36 +01001587int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
1589 patch_ad1881(ac97);
1590 /* Presario700 workaround */
1591 /* for Jack Sense/SPDIF Register misetting causing */
1592 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
Takashi Iwai2f3482f2006-08-21 18:44:31 +02001593 ac97->build_ops = &patch_ad1886_build_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return 0;
1595}
1596
1597/* MISC bits */
1598#define AC97_AD198X_MBC 0x0003 /* mic boost */
1599#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1600#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1601#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1602#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1603#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1604#define AC97_AD198X_VREF_0 0x000c /* 0V */
1605#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1606#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1607#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1608#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1609#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1610#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1611#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1612#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1613#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1614#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1615#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1616#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1617
1618
Takashi Iwaiee423812005-11-17 14:21:36 +01001619static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
1621 static char *texts[2] = { "AC-Link", "A/D Converter" };
1622
1623 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1624 uinfo->count = 1;
1625 uinfo->value.enumerated.items = 2;
1626 if (uinfo->value.enumerated.item > 1)
1627 uinfo->value.enumerated.item = 1;
1628 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1629 return 0;
1630}
1631
Takashi Iwaiee423812005-11-17 14:21:36 +01001632static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Takashi Iwaiee423812005-11-17 14:21:36 +01001634 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 unsigned short val;
1636
1637 val = ac97->regs[AC97_AD_SERIAL_CFG];
1638 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1639 return 0;
1640}
1641
Takashi Iwaiee423812005-11-17 14:21:36 +01001642static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Takashi Iwaiee423812005-11-17 14:21:36 +01001644 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 unsigned short val;
1646
1647 if (ucontrol->value.enumerated.item[0] > 1)
1648 return -EINVAL;
1649 val = ucontrol->value.enumerated.item[0] << 2;
1650 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1651}
1652
Takashi Iwaiee423812005-11-17 14:21:36 +01001653static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1655 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1656 .info = snd_ac97_ad198x_spdif_source_info,
1657 .get = snd_ac97_ad198x_spdif_source_get,
1658 .put = snd_ac97_ad198x_spdif_source_put,
1659};
1660
Takashi Iwaiee423812005-11-17 14:21:36 +01001661static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
1663 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1664}
1665
Takashi Iwaiee423812005-11-17 14:21:36 +01001666static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1668 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1669};
1670
Takashi Iwai128a46a2006-01-11 18:15:43 +01001671/* black list to avoid HP/Line jack-sense controls
1672 * (SS vendor << 16 | device)
1673 */
1674static unsigned int ad1981_jacks_blacklist[] = {
Takashi Iwaia43c4d42006-06-01 17:16:41 +02001675 0x10140537, /* Thinkpad T41p */
Takashi Iwai128a46a2006-01-11 18:15:43 +01001676 0x10140554, /* Thinkpad T42p/R50p */
1677 0 /* end */
1678};
1679
1680static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1681{
1682 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1683 for (; *list; list++)
1684 if (*list == subid)
1685 return 1;
1686 return 0;
1687}
1688
Takashi Iwaiee423812005-11-17 14:21:36 +01001689static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001691 if (check_list(ac97, ad1981_jacks_blacklist))
1692 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1694 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1695}
1696
1697static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1698 .build_post_spdif = patch_ad198x_post_spdif,
1699 .build_specific = patch_ad1981a_specific,
1700#ifdef CONFIG_PM
1701 .resume = ad18xx_resume
1702#endif
1703};
1704
Takashi Iwai128a46a2006-01-11 18:15:43 +01001705/* white list to enable HP jack-sense bits
1706 * (SS vendor << 16 | device)
1707 */
1708static unsigned int ad1981_jacks_whitelist[] = {
1709 0x0e11005a, /* HP nc4000/4010 */
1710 0x103c0890, /* HP nc6000 */
1711 0x103c0938, /* HP nc4220 */
1712 0x103c099c, /* HP nx6110 */
1713 0x103c0944, /* HP nc6220 */
1714 0x103c0934, /* HP nc8220 */
1715 0x103c006d, /* HP nx9105 */
1716 0x17340088, /* FSC Scenic-W */
1717 0 /* end */
1718};
1719
Takashi Iwaiee423812005-11-17 14:21:36 +01001720static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001722 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 /* enable headphone jack sense */
1724 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Takashi Iwaiee423812005-11-17 14:21:36 +01001727int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728{
1729 patch_ad1881(ac97);
1730 ac97->build_ops = &patch_ad1981a_build_ops;
1731 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1732 ac97->flags |= AC97_STEREO_MUTES;
1733 check_ad1981_hp_jack_sense(ac97);
1734 return 0;
1735}
1736
Takashi Iwaiee423812005-11-17 14:21:36 +01001737static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1739
Takashi Iwaiee423812005-11-17 14:21:36 +01001740static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
1742 int err;
1743
1744 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1745 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001746 if (check_list(ac97, ad1981_jacks_blacklist))
1747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1749 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1750}
1751
1752static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1753 .build_post_spdif = patch_ad198x_post_spdif,
1754 .build_specific = patch_ad1981b_specific,
1755#ifdef CONFIG_PM
1756 .resume = ad18xx_resume
1757#endif
1758};
1759
Takashi Iwaiee423812005-11-17 14:21:36 +01001760int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 patch_ad1881(ac97);
1763 ac97->build_ops = &patch_ad1981b_build_ops;
1764 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1765 ac97->flags |= AC97_STEREO_MUTES;
1766 check_ad1981_hp_jack_sense(ac97);
1767 return 0;
1768}
1769
Takashi Iwaiee423812005-11-17 14:21:36 +01001770static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
1772 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1773 uinfo->count = 1;
1774 uinfo->value.integer.min = 0;
1775 uinfo->value.integer.max = 1;
1776 return 0;
1777}
1778
Takashi Iwaiee423812005-11-17 14:21:36 +01001779static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Takashi Iwaiee423812005-11-17 14:21:36 +01001781 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 unsigned short val;
1783
1784 val = ac97->regs[AC97_AD_MISC];
1785 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1786 return 0;
1787}
1788
Takashi Iwaiee423812005-11-17 14:21:36 +01001789static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790{
Takashi Iwaiee423812005-11-17 14:21:36 +01001791 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 unsigned short val;
1793
1794 val = !ucontrol->value.integer.value[0]
1795 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1796 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1797 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1798}
1799
Takashi Iwaiee423812005-11-17 14:21:36 +01001800static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1803
1804 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1805 uinfo->count = 1;
1806 uinfo->value.enumerated.items = 3;
1807 if (uinfo->value.enumerated.item > 2)
1808 uinfo->value.enumerated.item = 2;
1809 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1810 return 0;
1811}
1812
Takashi Iwaiee423812005-11-17 14:21:36 +01001813static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
Takashi Iwaiee423812005-11-17 14:21:36 +01001815 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 unsigned short val;
1817
1818 val = ac97->regs[AC97_AD_MISC];
1819 if (!(val & AC97_AD198X_DMIX1))
1820 ucontrol->value.enumerated.item[0] = 0;
1821 else
1822 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1823 return 0;
1824}
1825
Takashi Iwaiee423812005-11-17 14:21:36 +01001826static int snd_ac97_ad1888_downmix_put(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 if (ucontrol->value.enumerated.item[0] > 2)
1832 return -EINVAL;
1833 if (ucontrol->value.enumerated.item[0] == 0)
1834 val = 0;
1835 else
1836 val = AC97_AD198X_DMIX1 |
1837 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1838 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1839 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1840}
1841
Takashi Iwaiee423812005-11-17 14:21:36 +01001842static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001843{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001844 unsigned short val = 0;
1845 if (! is_shared_linein(ac97))
1846 val |= (1 << 12);
1847 if (! is_shared_micin(ac97))
1848 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001849 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001850 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001851}
1852
Takashi Iwaiee423812005-11-17 14:21:36 +01001853static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 {
1855 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1856 .name = "Exchange Front/Surround",
1857 .info = snd_ac97_ad1888_lohpsel_info,
1858 .get = snd_ac97_ad1888_lohpsel_get,
1859 .put = snd_ac97_ad1888_lohpsel_put
1860 },
Jaya Kumar02856b52006-06-23 15:18:41 +02001861 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1862 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1864 {
1865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1866 .name = "Downmix",
1867 .info = snd_ac97_ad1888_downmix_info,
1868 .get = snd_ac97_ad1888_downmix_get,
1869 .put = snd_ac97_ad1888_downmix_put
1870 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001871 AC97_SURROUND_JACK_MODE_CTL,
1872 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001873
1874 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1875 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876};
1877
Takashi Iwaiee423812005-11-17 14:21:36 +01001878static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879{
1880 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1881 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1882 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1883 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1884}
1885
1886static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1887 .build_post_spdif = patch_ad198x_post_spdif,
1888 .build_specific = patch_ad1888_specific,
1889#ifdef CONFIG_PM
Jaya Kumar1561f092006-06-19 15:06:14 +02001890 .resume = ad1888_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001892 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893};
1894
Takashi Iwaiee423812005-11-17 14:21:36 +01001895int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896{
1897 unsigned short misc;
1898
1899 patch_ad1881(ac97);
1900 ac97->build_ops = &patch_ad1888_build_ops;
1901 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1902 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1903 /* AD-compatible mode */
1904 /* Stereo mutes enabled */
1905 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1906 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1907 AC97_AD198X_LOSEL |
1908 AC97_AD198X_HPSEL |
1909 AC97_AD198X_MSPLT |
1910 AC97_AD198X_AC97NC);
1911 ac97->flags |= AC97_STEREO_MUTES;
1912 return 0;
1913}
1914
Takashi Iwaiee423812005-11-17 14:21:36 +01001915static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
1917 int err;
1918
1919 if ((err = patch_ad1888_specific(ac97)) < 0)
1920 return err;
1921 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1922}
1923
1924static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1925 .build_post_spdif = patch_ad198x_post_spdif,
1926 .build_specific = patch_ad1980_specific,
1927#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001928 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001930 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931};
1932
Takashi Iwaiee423812005-11-17 14:21:36 +01001933int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
1935 patch_ad1888(ac97);
1936 ac97->build_ops = &patch_ad1980_build_ops;
1937 return 0;
1938}
1939
Takashi Iwaiee423812005-11-17 14:21:36 +01001940static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1942};
1943
Takashi Iwaiee423812005-11-17 14:21:36 +01001944static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001945{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001946 ad1888_update_jacks(ac97);
Takashi Iwaifc232c62005-05-27 10:42:45 +02001947 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1948 is_shared_micin(ac97) ? 0 : 1 << 9);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001949}
1950
Takashi Iwaiee423812005-11-17 14:21:36 +01001951static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952{
1953 int err;
1954
1955 if ((err = patch_ad1980_specific(ac97)) < 0)
1956 return err;
1957 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1958}
1959
1960static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1961 .build_post_spdif = patch_ad198x_post_spdif,
1962 .build_specific = patch_ad1985_specific,
1963#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001964 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001966 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967};
1968
Takashi Iwaiee423812005-11-17 14:21:36 +01001969int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
1971 unsigned short misc;
1972
1973 patch_ad1881(ac97);
1974 ac97->build_ops = &patch_ad1985_build_ops;
1975 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1976 /* switch front/surround line-out/hp-out */
1977 /* center/LFE, mic in 3.75V mode */
1978 /* AD-compatible mode */
1979 /* Stereo mutes enabled */
1980 /* in accordance with ADI driver: misc | 0x5c28 */
1981 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1982 AC97_AD198X_VREFH |
1983 AC97_AD198X_LOSEL |
1984 AC97_AD198X_HPSEL |
1985 AC97_AD198X_CLDIS |
1986 AC97_AD198X_LODIS |
1987 AC97_AD198X_MSPLT |
1988 AC97_AD198X_AC97NC);
1989 ac97->flags |= AC97_STEREO_MUTES;
1990 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1991 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1992 return 0;
1993}
1994
1995/*
1996 * realtek ALC65x/850 codecs
1997 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001998static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002000 int shared;
2001
2002 /* shared Line-In */
2003 shared = is_shared_linein(ac97);
2004 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2005 shared ? (1 << 9) : 0);
2006 /* update shared Mic */
2007 shared = is_shared_micin(ac97);
2008 /* disable/enable vref */
2009 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2010 shared ? (1 << 12) : 0);
2011 /* turn on/off center-on-mic */
2012 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2013 shared ? (1 << 10) : 0);
2014 /* GPIO0 high for mic */
2015 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2016 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017}
2018
Takashi Iwaiee423812005-11-17 14:21:36 +01002019static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2021 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2022 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2023 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2024 /* 4: Analog Input To Surround */
2025 /* 5: Analog Input To Center/LFE */
2026 /* 6: Independent Master Volume Right */
2027 /* 7: Independent Master Volume Left */
2028 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002029 /* 9: Line-In/Surround share */
2030 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 /* 11-13: in IEC958 controls */
2032 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
2033#if 0 /* always set in patch_alc650 */
2034 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2035 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2036 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2037 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2038 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2039 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2040#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002041 AC97_SURROUND_JACK_MODE_CTL,
2042 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043};
2044
Takashi Iwaiee423812005-11-17 14:21:36 +01002045static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002046 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2048 /* disable this controls since it doesn't work as expected */
2049 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2050};
2051
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002052static DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
2053
Takashi Iwaiee423812005-11-17 14:21:36 +01002054static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
2056 int err;
2057
2058 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2059 return err;
2060 if (ac97->ext_id & AC97_EI_SPDIF) {
2061 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2062 return err;
2063 }
Takashi Iwai2f3482f2006-08-21 18:44:31 +02002064 if (ac97->id != AC97_ID_ALC650F)
2065 reset_tlv(ac97, "Master Playback Volume",
2066 db_scale_5bit_3db_max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068}
2069
2070static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002071 .build_specific = patch_alc650_specific,
2072 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073};
2074
Takashi Iwaiee423812005-11-17 14:21:36 +01002075int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 unsigned short val;
2078
2079 ac97->build_ops = &patch_alc650_ops;
2080
2081 /* determine the revision */
2082 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2083 if (val < 3)
2084 ac97->id = 0x414c4720; /* Old version */
2085 else if (val < 0x10)
2086 ac97->id = 0x414c4721; /* D version */
2087 else if (val < 0x20)
2088 ac97->id = 0x414c4722; /* E version */
2089 else if (val < 0x30)
2090 ac97->id = 0x414c4723; /* F version */
2091
2092 /* revision E or F */
2093 /* FIXME: what about revision D ? */
2094 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2095 ac97->id == 0x414c4723);
2096
2097 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2098 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2099 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2100
2101 /* Enable SPDIF-IN only on Rev.E and above */
2102 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2103 /* SPDIF IN with pin 47 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002104 if (ac97->spec.dev_flags &&
2105 /* ASUS A6KM requires EAPD */
2106 ! (ac97->subsystem_vendor == 0x1043 &&
2107 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 val |= 0x03; /* enable */
2109 else
2110 val &= ~0x03; /* disable */
2111 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2112
2113 /* set default: slot 3,4,7,8,6,9
2114 spdif-in monitor off, analog-spdif off, spdif-in off
2115 center on mic off, surround on line-in off
2116 downmix off, duplicate front off
2117 */
2118 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2119
2120 /* set GPIO0 for mic bias */
2121 /* GPIO0 pin output, no interrupt, high */
2122 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2123 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2124 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2125 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2126
2127 /* full DAC volume */
2128 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2129 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2130 return 0;
2131}
2132
Takashi Iwaiee423812005-11-17 14:21:36 +01002133static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002135 int shared;
2136
2137 /* shared Line-In */
2138 shared = is_shared_linein(ac97);
2139 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2140 shared ? (1 << 9) : 0, 0);
2141 /* update shared mic */
2142 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 /* misc control; vrefout disable */
2144 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002145 shared ? (1 << 12) : 0);
2146 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2147 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
Takashi Iwaiee423812005-11-17 14:21:36 +01002150static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002152 AC97_SURROUND_JACK_MODE_CTL,
2153 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154};
2155
Takashi Iwaiee423812005-11-17 14:21:36 +01002156static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
2158 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2159 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002160 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2163 uinfo->count = 1;
2164 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2165 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2166 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2167 strcpy(uinfo->value.enumerated.name,
2168 ac97->spec.dev_flags ?
2169 texts_658[uinfo->value.enumerated.item] :
2170 texts_655[uinfo->value.enumerated.item]);
2171 return 0;
2172}
2173
Takashi Iwaiee423812005-11-17 14:21:36 +01002174static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
Takashi Iwaiee423812005-11-17 14:21:36 +01002176 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 unsigned short val;
2178
2179 val = ac97->regs[AC97_ALC650_MULTICH];
2180 val = (val >> 12) & 3;
2181 if (ac97->spec.dev_flags && val == 3)
2182 val = 0;
2183 ucontrol->value.enumerated.item[0] = val;
2184 return 0;
2185}
2186
Takashi Iwaiee423812005-11-17 14:21:36 +01002187static int alc655_iec958_route_put(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
2191 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2192 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2193 0);
2194}
2195
Takashi Iwaiee423812005-11-17 14:21:36 +01002196static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002197 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 /* disable this controls since it doesn't work as expected */
2199 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2200 {
2201 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002202 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .info = alc655_iec958_route_info,
2204 .get = alc655_iec958_route_get,
2205 .put = alc655_iec958_route_put,
2206 },
2207};
2208
Takashi Iwaiee423812005-11-17 14:21:36 +01002209static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210{
2211 int err;
2212
2213 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2214 return err;
2215 if (ac97->ext_id & AC97_EI_SPDIF) {
2216 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2217 return err;
2218 }
2219 return 0;
2220}
2221
2222static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002223 .build_specific = patch_alc655_specific,
2224 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225};
2226
Takashi Iwaiee423812005-11-17 14:21:36 +01002227int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
2229 unsigned int val;
2230
Takashi Iwaia5022b02005-09-02 14:03:05 +02002231 if (ac97->id == AC97_ID_ALC658) {
2232 ac97->spec.dev_flags = 1; /* ALC658 */
2233 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2234 ac97->id = AC97_ID_ALC658D;
2235 ac97->spec.dev_flags = 2;
2236 }
2237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
2239 ac97->build_ops = &patch_alc655_ops;
2240
2241 /* assume only page 0 for writing cache */
2242 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2243
2244 /* adjust default values */
2245 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002246 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002248 else { /* ALC655 */
2249 if (ac97->subsystem_vendor == 0x1462 &&
Magnus Sandind244bf82006-08-16 15:25:23 +02002250 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2251 ac97->subsystem_device == 0x0161)) /* LG K1 Express */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002252 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2253 else
2254 val |= (1 << 1); /* Pin 47 is spdif input pin */
2255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 val &= ~(1 << 12); /* vref enable */
2257 snd_ac97_write_cache(ac97, 0x7a, val);
2258 /* set default: spdif-in enabled,
2259 spdif-in monitor off, spdif-in PCM off
2260 center on mic off, surround on line-in off
2261 duplicate front off
2262 */
2263 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2264
2265 /* full DAC volume */
2266 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2267 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002268
2269 /* update undocumented bit... */
2270 if (ac97->id == AC97_ID_ALC658D)
2271 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 return 0;
2274}
2275
2276
2277#define AC97_ALC850_JACK_SELECT 0x76
2278#define AC97_ALC850_MISC1 0x7a
2279
Takashi Iwaiee423812005-11-17 14:21:36 +01002280static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002282 int shared;
2283
2284 /* shared Line-In */
2285 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 /* SURR 1kOhm (bit4), Amp (bit5) */
2287 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002288 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002290 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2291 shared ? (2<<12) : (0<<12));
2292 /* update shared mic */
2293 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 /* Vref disable (bit12), 1kOhm (bit13) */
2295 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002296 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002297 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002298 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002299 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
Takashi Iwaiee423812005-11-17 14:21:36 +01002302static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002304 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002305 AC97_SURROUND_JACK_MODE_CTL,
2306 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307};
2308
Takashi Iwaiee423812005-11-17 14:21:36 +01002309static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
2311 int err;
2312
2313 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2314 return err;
2315 if (ac97->ext_id & AC97_EI_SPDIF) {
2316 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2317 return err;
2318 }
2319 return 0;
2320}
2321
2322static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002323 .build_specific = patch_alc850_specific,
2324 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325};
2326
Takashi Iwaiee423812005-11-17 14:21:36 +01002327int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
2329 ac97->build_ops = &patch_alc850_ops;
2330
2331 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2332
2333 /* assume only page 0 for writing cache */
2334 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2335
2336 /* adjust default values */
2337 /* set default: spdif-in enabled,
2338 spdif-in monitor off, spdif-in PCM off
2339 center on mic off, surround on line-in off
2340 duplicate front off
2341 */
2342 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2343 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2344 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2345 */
2346 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2347 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2348 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2349 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2350 */
2351 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2352 (1<<11)|(0<<12)|(1<<15));
2353
2354 /* full DAC volume */
2355 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2356 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2357 return 0;
2358}
2359
2360
2361/*
2362 * C-Media CM97xx codecs
2363 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002364static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002365{
2366 /* shared Line-In */
2367 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2368 is_shared_linein(ac97) ? (1 << 10) : 0);
2369}
2370
Takashi Iwaiee423812005-11-17 14:21:36 +01002371static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002373 AC97_SURROUND_JACK_MODE_CTL,
2374 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375};
2376
Takashi Iwaiee423812005-11-17 14:21:36 +01002377static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378{
2379 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2380}
2381
2382static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002383 .build_specific = patch_cm9738_specific,
2384 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385};
2386
Takashi Iwaiee423812005-11-17 14:21:36 +01002387int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
2389 ac97->build_ops = &patch_cm9738_ops;
2390 /* FIXME: can anyone confirm below? */
2391 /* CM9738 has no PCM volume although the register reacts */
2392 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2393 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2394
2395 return 0;
2396}
2397
Takashi Iwaiee423812005-11-17 14:21:36 +01002398static 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 -07002399{
2400 static char *texts[] = { "Analog", "Digital" };
2401
2402 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2403 uinfo->count = 1;
2404 uinfo->value.enumerated.items = 2;
2405 if (uinfo->value.enumerated.item > 1)
2406 uinfo->value.enumerated.item = 1;
2407 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2408 return 0;
2409}
2410
Takashi Iwaiee423812005-11-17 14:21:36 +01002411static 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 -07002412{
Takashi Iwaiee423812005-11-17 14:21:36 +01002413 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 unsigned short val;
2415
2416 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2417 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2418 return 0;
2419}
2420
Takashi Iwaiee423812005-11-17 14:21:36 +01002421static 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 -07002422{
Takashi Iwaiee423812005-11-17 14:21:36 +01002423 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2426 0x01 << 1,
2427 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2428}
2429
Takashi Iwaiee423812005-11-17 14:21:36 +01002430static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 /* BIT 0: SPDI_EN - always true */
2432 { /* BIT 1: SPDIFS */
2433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2434 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2435 .info = snd_ac97_cmedia_spdif_playback_source_info,
2436 .get = snd_ac97_cmedia_spdif_playback_source_get,
2437 .put = snd_ac97_cmedia_spdif_playback_source_put,
2438 },
2439 /* BIT 2: IG_SPIV */
2440 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2441 /* BIT 3: SPI2F */
2442 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2443 /* BIT 4: SPI2SDI */
2444 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2445 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2446};
2447
Takashi Iwaiee423812005-11-17 14:21:36 +01002448static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002450 /* shared Line-In */
2451 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2452 is_shared_linein(ac97) ? (1 << 10) : 0);
2453 /* shared Mic */
2454 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2455 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456}
2457
Takashi Iwaiee423812005-11-17 14:21:36 +01002458static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002459 AC97_SURROUND_JACK_MODE_CTL,
2460 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461};
2462
Takashi Iwaiee423812005-11-17 14:21:36 +01002463static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
2465 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2466}
2467
Takashi Iwaiee423812005-11-17 14:21:36 +01002468static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469{
2470 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2471}
2472
2473static struct snd_ac97_build_ops patch_cm9739_ops = {
2474 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002475 .build_post_spdif = patch_cm9739_post_spdif,
2476 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477};
2478
Takashi Iwaiee423812005-11-17 14:21:36 +01002479int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
2481 unsigned short val;
2482
2483 ac97->build_ops = &patch_cm9739_ops;
2484
2485 /* CM9739/A has no Master and PCM volume although the register reacts */
2486 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2487 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2488 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2489
2490 /* check spdif */
2491 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2492 if (val & AC97_EA_SPCV) {
2493 /* enable spdif in */
2494 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2495 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2496 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2497 } else {
2498 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2499 ac97->rates[AC97_RATES_SPDIF] = 0;
2500 }
2501
2502 /* set-up multi channel */
2503 /* bit 14: 0 = SPDIF, 1 = EAPD */
2504 /* bit 13: enable internal vref output for mic */
2505 /* bit 12: disable center/lfe (swithable) */
2506 /* bit 10: disable surround/line (switchable) */
2507 /* bit 9: mix 2 surround off */
2508 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2509 /* bit 3: undocumented; surround? */
2510 /* bit 0: dB */
2511 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2512 val |= (1 << 3);
2513 val |= (1 << 13);
2514 if (! (ac97->ext_id & AC97_EI_SPDIF))
2515 val |= (1 << 14);
2516 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2517
2518 /* FIXME: set up GPIO */
2519 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2520 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2521 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2522 if (ac97->pci &&
2523 ac97->subsystem_vendor == 0x1043 &&
2524 ac97->subsystem_device == 0x1843) {
2525 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2526 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2527 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2528 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2529 }
2530
2531 return 0;
2532}
2533
2534#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002535#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536#define AC97_CM9761_SPDIF_CTRL 0x6c
2537
Takashi Iwaiee423812005-11-17 14:21:36 +01002538static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002540 /* FIXME: check the bits for each model
2541 * model 83 is confirmed to work
2542 */
2543 static unsigned short surr_on[3][2] = {
2544 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2545 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2546 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002548 static unsigned short clfe_on[3][2] = {
2549 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2550 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2551 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002553 static unsigned short surr_shared[3][2] = {
2554 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2555 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2556 { 0x0000, 0x0400 }, /* 9761-83 */
2557 };
2558 static unsigned short clfe_shared[3][2] = {
2559 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2560 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2561 { 0x2000, 0x0800 }, /* 9761-83 */
2562 };
2563 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002564
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002565 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2566 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2567 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2568 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2569
2570 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
Takashi Iwaiee423812005-11-17 14:21:36 +01002573static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002574 AC97_SURROUND_JACK_MODE_CTL,
2575 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576};
2577
Takashi Iwaiee423812005-11-17 14:21:36 +01002578static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002579{
2580 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2581
2582 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2583 uinfo->count = 1;
2584 uinfo->value.enumerated.items = 3;
2585 if (uinfo->value.enumerated.item > 2)
2586 uinfo->value.enumerated.item = 2;
2587 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2588 return 0;
2589}
2590
Takashi Iwaiee423812005-11-17 14:21:36 +01002591static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002592{
Takashi Iwaiee423812005-11-17 14:21:36 +01002593 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002594
2595 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2596 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2597 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2598 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2599 else
2600 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2601 return 0;
2602}
2603
Takashi Iwaiee423812005-11-17 14:21:36 +01002604static int cm9761_spdif_out_source_put(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 (ucontrol->value.enumerated.item[0] == 2)
2609 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2610 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2611 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2612 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2613}
2614
2615static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2616static const struct ac97_enum cm9761_dac_clock_enum =
2617 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2618
Takashi Iwaiee423812005-11-17 14:21:36 +01002619static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002620 { /* BIT 1: SPDIFS */
2621 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2622 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2623 .info = cm9761_spdif_out_source_info,
2624 .get = cm9761_spdif_out_source_get,
2625 .put = cm9761_spdif_out_source_put,
2626 },
2627 /* BIT 2: IG_SPIV */
2628 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2629 /* BIT 3: SPI2F */
2630 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2631 /* BIT 4: SPI2SDI */
2632 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2633 /* BIT 9-10: DAC_CTL */
2634 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2635};
2636
Takashi Iwaiee423812005-11-17 14:21:36 +01002637static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002638{
2639 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2640}
2641
Takashi Iwaiee423812005-11-17 14:21:36 +01002642static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643{
2644 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2645}
2646
2647static struct snd_ac97_build_ops patch_cm9761_ops = {
2648 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002649 .build_post_spdif = patch_cm9761_post_spdif,
2650 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651};
2652
Takashi Iwaiee423812005-11-17 14:21:36 +01002653int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654{
2655 unsigned short val;
2656
2657 /* CM9761 has no PCM volume although the register reacts */
2658 /* Master volume seems to have _some_ influence on the analog
2659 * input sounds
2660 */
2661 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2662 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2663 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2664
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002665 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 if (ac97->id == AC97_ID_CM9761_82) {
2667 unsigned short tmp;
2668 /* check page 1, reg 0x60 */
2669 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2670 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2671 tmp = snd_ac97_read(ac97, 0x60);
2672 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2673 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002674 } else if (ac97->id == AC97_ID_CM9761_83)
2675 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
2677 ac97->build_ops = &patch_cm9761_ops;
2678
2679 /* enable spdif */
2680 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2681 ac97->ext_id |= AC97_EI_SPDIF;
2682 /* to be sure: we overwrite the ext status bits */
2683 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2684 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002685 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2687
2688 /* set-up multi channel */
2689 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002690 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002692 * bit 12: CLFE control (reverted on rev B)
2693 * bit 11: Mic/center share (reverted on rev B)
2694 * bit 10: suddound/line share
2695 * bit 9: Analog-in mix -> surround
2696 * bit 8: Analog-in mix -> CLFE
2697 * bit 7: Mic/LFE share (mic/center/lfe)
2698 * bit 5: vref select (9761A)
2699 * bit 4: front control
2700 * bit 3: surround control (revereted with rev B)
2701 * bit 2: front mic
2702 * bit 1: stereo mic
2703 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 */
2705
2706#if 0
2707 if (ac97->spec.dev_flags)
2708 val = 0x0214;
2709 else
2710 val = 0x321c;
2711#endif
2712 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2713 val |= (1 << 4); /* front on */
2714 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2715
2716 /* FIXME: set up GPIO */
2717 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2718 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2719
2720 return 0;
2721}
2722
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002723#define AC97_CM9780_SIDE 0x60
2724#define AC97_CM9780_JACK 0x62
2725#define AC97_CM9780_MIXER 0x64
2726#define AC97_CM9780_MULTI_CHAN 0x66
2727#define AC97_CM9780_SPDIF 0x6c
2728
2729static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2730static const struct ac97_enum cm9780_ch_select_enum =
2731 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01002732static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002733 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2734 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2735 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2736};
2737
Takashi Iwaiee423812005-11-17 14:21:36 +01002738static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002739{
2740 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2741}
2742
2743static struct snd_ac97_build_ops patch_cm9780_ops = {
2744 .build_specific = patch_cm9780_specific,
2745 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2746};
2747
Takashi Iwaiee423812005-11-17 14:21:36 +01002748int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002749{
2750 unsigned short val;
2751
2752 ac97->build_ops = &patch_cm9780_ops;
2753
2754 /* enable spdif */
2755 if (ac97->ext_id & AC97_EI_SPDIF) {
2756 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2757 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2758 val |= 0x1; /* SPDI_EN */
2759 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2760 }
2761
2762 return 0;
2763}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
2765/*
2766 * VIA VT1616 codec
2767 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002768static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2770AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2771AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2772AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2773};
2774
Takashi Iwaiee423812005-11-17 14:21:36 +01002775static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776{
2777 int err;
2778
2779 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2780 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2781 return err;
2782 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2783 return err;
2784 return 0;
2785}
2786
2787static struct snd_ac97_build_ops patch_vt1616_ops = {
2788 .build_specific = patch_vt1616_specific
2789};
2790
Takashi Iwaiee423812005-11-17 14:21:36 +01002791int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792{
2793 ac97->build_ops = &patch_vt1616_ops;
2794 return 0;
2795}
2796
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002797/*
Philip Prindeville4b499482005-08-12 16:46:17 +02002798 * VT1617A codec
2799 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002800int patch_vt1617a(struct snd_ac97 * ac97)
Philip Prindeville4b499482005-08-12 16:46:17 +02002801{
2802 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2803 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2804 return 0;
2805}
2806
2807/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002808 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002809static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002810{
2811 /* shared Line-In */
2812 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2813 is_shared_linein(ac97) ? (1<<9) : 0);
2814 /* shared Mic */
2815 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2816 is_shared_micin(ac97) ? (1<<10) : 0);
2817}
2818
Takashi Iwaiee423812005-11-17 14:21:36 +01002819static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002820 AC97_SURROUND_JACK_MODE_CTL,
2821 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822};
2823
Takashi Iwaiee423812005-11-17 14:21:36 +01002824static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002825 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2827 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2828};
2829
Takashi Iwaiee423812005-11-17 14:21:36 +01002830static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831{
2832 int err;
2833 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2834 return err;
2835 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2836 return err;
2837 return 0;
2838}
2839
2840static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002841 .build_specific = patch_it2646_specific,
2842 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843};
2844
Takashi Iwaiee423812005-11-17 14:21:36 +01002845int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846{
2847 ac97->build_ops = &patch_it2646_ops;
2848 /* full DAC volume */
2849 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2850 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2851 return 0;
2852}
2853
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002854/*
2855 * Si3036 codec
2856 */
2857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002859#define AC97_SI3036_LINE_CFG 0x5c
2860
Takashi Iwaiee423812005-11-17 14:21:36 +01002861static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002862AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2863};
2864
Takashi Iwaiee423812005-11-17 14:21:36 +01002865static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002866{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02002867 int idx, err;
2868 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2869 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2870 return err;
2871 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002872}
2873
2874static struct snd_ac97_build_ops patch_si3036_ops = {
2875 .build_specific = patch_si3036_specific,
2876};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
Takashi Iwaiee423812005-11-17 14:21:36 +01002878int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002880 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2882 snd_ac97_write_cache(ac97, 0x68, 0);
2883 return 0;
2884}
Charl Coetzeeba224292006-02-09 11:48:21 +01002885
2886/*
2887 * LM 4550 Codec
2888 *
2889 * We use a static resolution table since LM4550 codec cannot be
2890 * properly autoprobed to determine the resolution via
2891 * check_volume_resolution().
2892 */
2893
2894static struct snd_ac97_res_table lm4550_restbl[] = {
2895 { AC97_MASTER, 0x1f1f },
2896 { AC97_HEADPHONE, 0x1f1f },
2897 { AC97_MASTER_MONO, 0x001f },
2898 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2899 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01002900 { AC97_MIC, 0x001f },
2901 { AC97_LINE, 0x1f1f },
2902 { AC97_CD, 0x1f1f },
2903 { AC97_VIDEO, 0x1f1f },
2904 { AC97_AUX, 0x1f1f },
2905 { AC97_PCM, 0x1f1f },
2906 { AC97_REC_GAIN, 0x0f0f },
2907 { } /* terminator */
2908};
2909
2910int patch_lm4550(struct snd_ac97 *ac97)
2911{
2912 ac97->res_table = lm4550_restbl;
2913 return 0;
2914}
Mike Rapoport82466ad2006-06-29 17:15:33 +02002915
2916/*
2917 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
2918 */
2919static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
2920/* enable/disable headphone driver which allows direct connection to
2921 stereo headphone without the use of external DC blocking
2922 capacitors */
2923AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
2924/* Filter used to compensate the DC offset is added in the ADC to remove idle
2925 tones from the audio band. */
2926AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
2927/* Control smart-low-power mode feature. Allows automatic power down
2928 of unused blocks in the ADC analog front end and the PLL. */
2929AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
2930};
2931
2932static int patch_ucb1400_specific(struct snd_ac97 * ac97)
2933{
2934 int idx, err;
2935 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
2936 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
2937 return err;
2938 return 0;
2939}
2940
2941static struct snd_ac97_build_ops patch_ucb1400_ops = {
2942 .build_specific = patch_ucb1400_specific,
2943};
2944
2945int patch_ucb1400(struct snd_ac97 * ac97)
2946{
2947 ac97->build_ops = &patch_ucb1400_ops;
2948 /* enable headphone driver and smart low power mode by default */
2949 snd_ac97_write(ac97, 0x6a, 0x0050);
2950 snd_ac97_write(ac97, 0x6c, 0x0030);
2951 return 0;
2952}