blob: 4d9cf37300f75ae8e0f70b786a4566e81bfc4e7c [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>
35#include <sound/ac97_codec.h>
36#include "ac97_patch.h"
37#include "ac97_id.h"
38#include "ac97_local.h"
39
40/*
41 * Chip specific initialization
42 */
43
Takashi Iwaiee423812005-11-17 14:21:36 +010044static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 int idx, err;
47
48 for (idx = 0; idx < count; idx++)
49 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
50 return err;
51 return 0;
52}
53
54/* set to the page, update bits and restore the page */
Takashi Iwaiee423812005-11-17 14:21:36 +010055static 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 -070056{
57 unsigned short page_save;
58 int ret;
59
Ingo Molnar62932df2006-01-16 16:34:20 +010060 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
63 ret = snd_ac97_update_bits(ac97, reg, mask, value);
64 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
Ingo Molnar62932df2006-01-16 16:34:20 +010065 mutex_unlock(&ac97->page_mutex); /* unlock paging */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return ret;
67}
68
Takashi Iwaieb8caf32005-04-13 14:32:57 +020069/*
70 * shared line-in/mic controls
71 */
Takashi Iwaiee423812005-11-17 14:21:36 +010072static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
Takashi Iwaieb8caf32005-04-13 14:32:57 +020073 const char **texts, unsigned int nums)
74{
75 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
76 uinfo->count = 1;
77 uinfo->value.enumerated.items = nums;
78 if (uinfo->value.enumerated.item > nums - 1)
79 uinfo->value.enumerated.item = nums - 1;
80 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
81 return 0;
82}
83
Takashi Iwaiee423812005-11-17 14:21:36 +010084static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020085{
86 static const char *texts[] = { "Shared", "Independent" };
87 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
88}
89
Takashi Iwaiee423812005-11-17 14:21:36 +010090static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020091{
Takashi Iwaiee423812005-11-17 14:21:36 +010092 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +020093
94 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
95 return 0;
96}
97
Takashi Iwaiee423812005-11-17 14:21:36 +010098static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +020099{
Takashi Iwaiee423812005-11-17 14:21:36 +0100100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200101 unsigned char indep = !!ucontrol->value.enumerated.item[0];
102
103 if (indep != ac97->indep_surround) {
104 ac97->indep_surround = indep;
105 if (ac97->build_ops->update_jacks)
106 ac97->build_ops->update_jacks(ac97);
107 return 1;
108 }
109 return 0;
110}
111
Takashi Iwaiee423812005-11-17 14:21:36 +0100112static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200113{
114 static const char *texts[] = { "2ch", "4ch", "6ch" };
115 if (kcontrol->private_value)
116 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
117 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
118}
119
Takashi Iwaiee423812005-11-17 14:21:36 +0100120static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200121{
Takashi Iwaiee423812005-11-17 14:21:36 +0100122 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200123
124 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
125 return 0;
126}
127
Takashi Iwaiee423812005-11-17 14:21:36 +0100128static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200129{
Takashi Iwaiee423812005-11-17 14:21:36 +0100130 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200131 unsigned char mode = ucontrol->value.enumerated.item[0];
132
133 if (mode != ac97->channel_mode) {
134 ac97->channel_mode = mode;
135 if (ac97->build_ops->update_jacks)
136 ac97->build_ops->update_jacks(ac97);
137 return 1;
138 }
139 return 0;
140}
141
142#define AC97_SURROUND_JACK_MODE_CTL \
143 { \
144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
145 .name = "Surround Jack Mode", \
146 .info = ac97_surround_jack_mode_info, \
147 .get = ac97_surround_jack_mode_get, \
148 .put = ac97_surround_jack_mode_put, \
149 }
150#define AC97_CHANNEL_MODE_CTL \
151 { \
152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
153 .name = "Channel Mode", \
154 .info = ac97_channel_mode_info, \
155 .get = ac97_channel_mode_get, \
156 .put = ac97_channel_mode_put, \
157 }
158#define AC97_CHANNEL_MODE_4CH_CTL \
159 { \
160 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
161 .name = "Channel Mode", \
162 .info = ac97_channel_mode_info, \
163 .get = ac97_channel_mode_get, \
164 .put = ac97_channel_mode_put, \
165 .private_value = 1, \
166 }
167
Takashi Iwaiee423812005-11-17 14:21:36 +0100168static inline int is_surround_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200169{
170 return ac97->channel_mode >= 1;
171}
172
Takashi Iwaiee423812005-11-17 14:21:36 +0100173static inline int is_clfe_on(struct snd_ac97 *ac97)
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200174{
Takashi Iwaieb9b4142005-09-13 18:39:21 +0200175 return ac97->channel_mode >= 2;
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200176}
177
Takashi Iwaiee423812005-11-17 14:21:36 +0100178static inline int is_shared_linein(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200179{
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200180 return ! ac97->indep_surround && is_surround_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200181}
182
Takashi Iwaiee423812005-11-17 14:21:36 +0100183static inline int is_shared_micin(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200184{
Takashi Iwai4525c9f2005-09-13 11:47:07 +0200185 return ! ac97->indep_surround && is_clfe_on(ac97);
Takashi Iwaieb8caf32005-04-13 14:32:57 +0200186}
187
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
190
191/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100192static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 static char *texts[3] = {
195 "Standard", "Small", "Smaller"
196 };
197
198 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
199 uinfo->count = 1;
200 uinfo->value.enumerated.items = 3;
201 if (uinfo->value.enumerated.item > 2)
202 uinfo->value.enumerated.item = 2;
203 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
204 return 0;
205}
206
Takashi Iwaiee423812005-11-17 14:21:36 +0100207static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Takashi Iwaiee423812005-11-17 14:21:36 +0100209 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 unsigned short val;
211
212 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
213 val = (val >> 10) & 3;
214 if (val > 0) /* 0 = invalid */
215 val--;
216 ucontrol->value.enumerated.item[0] = val;
217 return 0;
218}
219
Takashi Iwaiee423812005-11-17 14:21:36 +0100220static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Takashi Iwaiee423812005-11-17 14:21:36 +0100222 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 unsigned short val;
224
225 if (ucontrol->value.enumerated.item[0] > 2)
226 return -EINVAL;
227 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
228 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
229}
230
Takashi Iwaiee423812005-11-17 14:21:36 +0100231static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
234 .name = "3D Control - Speaker",
235 .info = snd_ac97_ymf753_info_speaker,
236 .get = snd_ac97_ymf753_get_speaker,
237 .put = snd_ac97_ymf753_put_speaker,
238};
239
240/* 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 +0100241static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 static char *texts[2] = { "AC-Link", "A/D Converter" };
244
245 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
246 uinfo->count = 1;
247 uinfo->value.enumerated.items = 2;
248 if (uinfo->value.enumerated.item > 1)
249 uinfo->value.enumerated.item = 1;
250 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
251 return 0;
252}
253
Takashi Iwaiee423812005-11-17 14:21:36 +0100254static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Takashi Iwaiee423812005-11-17 14:21:36 +0100256 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 unsigned short val;
258
259 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
260 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
261 return 0;
262}
263
Takashi Iwaiee423812005-11-17 14:21:36 +0100264static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Takashi Iwaiee423812005-11-17 14:21:36 +0100266 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 unsigned short val;
268
269 if (ucontrol->value.enumerated.item[0] > 1)
270 return -EINVAL;
271 val = ucontrol->value.enumerated.item[0] << 1;
272 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
273}
274
275/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
276 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
277 By default, no output pin is selected, and the S/PDIF signal is not output.
278 There is also a bit to mute S/PDIF output in a vendor-specific register. */
Takashi Iwaiee423812005-11-17 14:21:36 +0100279static 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 -0700280{
281 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
282
283 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
284 uinfo->count = 1;
285 uinfo->value.enumerated.items = 3;
286 if (uinfo->value.enumerated.item > 2)
287 uinfo->value.enumerated.item = 2;
288 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
289 return 0;
290}
291
Takashi Iwaiee423812005-11-17 14:21:36 +0100292static 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 -0700293{
Takashi Iwaiee423812005-11-17 14:21:36 +0100294 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 unsigned short val;
296
297 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
298 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
299 return 0;
300}
301
Takashi Iwaiee423812005-11-17 14:21:36 +0100302static 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 -0700303{
Takashi Iwaiee423812005-11-17 14:21:36 +0100304 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 unsigned short val;
306
307 if (ucontrol->value.enumerated.item[0] > 2)
308 return -EINVAL;
309 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
310 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
311 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
312 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
313 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
314}
315
Takashi Iwaiee423812005-11-17 14:21:36 +0100316static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 {
318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
319 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
320 .info = snd_ac97_ymf753_spdif_source_info,
321 .get = snd_ac97_ymf753_spdif_source_get,
322 .put = snd_ac97_ymf753_spdif_source_put,
323 },
324 {
325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
326 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
327 .info = snd_ac97_ymf753_spdif_output_pin_info,
328 .get = snd_ac97_ymf753_spdif_output_pin_get,
329 .put = snd_ac97_ymf753_spdif_output_pin_put,
330 },
331 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
332};
333
Takashi Iwaiee423812005-11-17 14:21:36 +0100334static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Takashi Iwaiee423812005-11-17 14:21:36 +0100336 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 int err;
338
339 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
340 return err;
341 strcpy(kctl->id.name, "3D Control - Wide");
342 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
343 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
344 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
345 return err;
346 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
347 return 0;
348}
349
Takashi Iwaiee423812005-11-17 14:21:36 +0100350static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
352 int err;
353
354 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
355 return err;
356 return 0;
357}
358
359static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
360 .build_3d = patch_yamaha_ymf753_3d,
361 .build_post_spdif = patch_yamaha_ymf753_post_spdif
362};
363
Takashi Iwaiee423812005-11-17 14:21:36 +0100364int patch_yamaha_ymf753(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
366 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
367 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
368 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
369 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
370 By default, no output pin is selected, and the S/PDIF signal is not output.
371 There is also a bit to mute S/PDIF output in a vendor-specific register.
372 */
373 ac97->build_ops = &patch_yamaha_ymf753_ops;
374 ac97->caps |= AC97_BC_BASS_TREBLE;
375 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
376 return 0;
377}
378
379/*
380 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
381 * removed broken wolfson00 patch.
382 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
383 */
384
Takashi Iwaiee423812005-11-17 14:21:36 +0100385static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200386AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
387AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
388};
389
Takashi Iwaiee423812005-11-17 14:21:36 +0100390static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200393 * Randolph Bentson <bentson@holmsjoen.com>
394 * WM9703/9707/9708/9717
395 */
396 int err, i;
397
398 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
399 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
400 return err;
401 }
402 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return 0;
404}
Liam Girdwood3998b702005-07-29 11:41:55 +0200405
406static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
407 .build_specific = patch_wolfson_wm9703_specific,
408};
409
Takashi Iwaiee423812005-11-17 14:21:36 +0100410int patch_wolfson03(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200411{
412 ac97->build_ops = &patch_wolfson_wm9703_ops;
413 return 0;
414}
415
Takashi Iwaiee423812005-11-17 14:21:36 +0100416static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200417AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
418AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
419AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
420AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
421AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
422AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
423};
424
Takashi Iwaiee423812005-11-17 14:21:36 +0100425static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200426{
427 int err, i;
428 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
429 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
430 return err;
431 }
432 /* patch for DVD noise */
433 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
434 return 0;
435}
436
437static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
438 .build_specific = patch_wolfson_wm9704_specific,
439};
440
Takashi Iwaiee423812005-11-17 14:21:36 +0100441int patch_wolfson04(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Liam Girdwood3998b702005-07-29 11:41:55 +0200443 /* WM9704M/9704Q */
444 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
Liam Girdwood3998b702005-07-29 11:41:55 +0200447
Takashi Iwaiee423812005-11-17 14:21:36 +0100448static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200449{
450 int err, i;
451 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
452 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
453 return err;
454 }
455 snd_ac97_write_cache(ac97, 0x72, 0x0808);
456 return 0;
457}
458
459static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
460 .build_specific = patch_wolfson_wm9705_specific,
461};
462
Takashi Iwaiee423812005-11-17 14:21:36 +0100463int patch_wolfson05(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Liam Girdwood3998b702005-07-29 11:41:55 +0200465 /* WM9705, WM9710 */
466 ac97->build_ops = &patch_wolfson_wm9705_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return 0;
468}
469
Liam Girdwood3998b702005-07-29 11:41:55 +0200470static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
471static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
472static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
473static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
474static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
475static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
476static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
477static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
478static const char* wm9711_rec_sel[] =
479 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
480static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
481
482static const struct ac97_enum wm9711_enum[] = {
483AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
484AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
485AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
486AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
487AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
488AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
489AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
490AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
491AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
492AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
493};
494
Takashi Iwaiee423812005-11-17 14:21:36 +0100495static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200496AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
497AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
498AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
499AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
500AC97_ENUM("ALC Function", wm9711_enum[0]),
501AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
502AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
503AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
504AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
505AC97_ENUM("ALC NG Type", wm9711_enum[9]),
506AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
507
508AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
509AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
510AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
511AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
512
513AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
514AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
515AC97_ENUM("Out3 Mux", wm9711_enum[2]),
516AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
517AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
518
519AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
520AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
521AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
522AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
523AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
524AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
525
526AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
527AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
528AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
529AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
530AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
531AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
532
533AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
534AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
535
536AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
537AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
538AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
539
540AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
541AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
542AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
543
544AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
545AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
546AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
547AC97_ENUM("Capture Select", wm9711_enum[8]),
548
549AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
550AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
551
552AC97_ENUM("Bass Control", wm9711_enum[5]),
553AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
554AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
555AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
556
557AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
558AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
559AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
560AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
561
562AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
563AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
564AC97_ENUM("Mic Select Source", wm9711_enum[7]),
565AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
566AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
567
568AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
569AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
570AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
571};
572
Takashi Iwaiee423812005-11-17 14:21:36 +0100573static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200574{
575 int err, i;
576
577 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
578 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
579 return err;
580 }
581 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
582 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
583 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
584 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
585 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
586 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
587 return 0;
588}
589
590static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
591 .build_specific = patch_wolfson_wm9711_specific,
592};
593
Takashi Iwaiee423812005-11-17 14:21:36 +0100594int patch_wolfson11(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Liam Girdwood3998b702005-07-29 11:41:55 +0200596 /* WM9711, WM9712 */
597 ac97->build_ops = &patch_wolfson_wm9711_ops;
598
599 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
600 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return 0;
603}
604
Liam Girdwood3998b702005-07-29 11:41:55 +0200605static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200607static const char* wm9713_rec_src[] =
608 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
609 "Mono Mix", "Zh"};
610static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
611static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
612static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
613static const char* wm9713_spk_pga[] =
614 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
615static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
616static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
617static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
618static const char* wm9713_dac_inv[] =
619 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
620 "Headphone Mix Mono", "NC", "Vmid"};
621static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
622static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624static const struct ac97_enum wm9713_enum[] = {
625AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
626AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
627AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200628AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
629AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
630AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
631AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
632AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
633AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
634AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
635AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
636AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
637AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
638AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639};
640
Takashi Iwaiee423812005-11-17 14:21:36 +0100641static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200643AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
644AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
645AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
646
647AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
648AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
649AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
650AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
651
652AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
653AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
654AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
655AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
656AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
657AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
658AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
659
660AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
661AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
662AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
663AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
664
665AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
666AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
667AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
668AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
669AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
670AC97_ENUM("Capture Select", wm9713_enum[3]),
671
672AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
673AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
674AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
675AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
676AC97_ENUM("ALC Function", wm9713_enum[5]),
677AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
678AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
679AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
680AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
681AC97_ENUM("ALC NG Type", wm9713_enum[13]),
682AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
683
684AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
685AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
686AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
687AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
688AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
689AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
690
691AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
692AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
693AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
694AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
695AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
696AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
697
698AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
699AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
700AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
701AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
702AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
703AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
704
705AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
706AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
707AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
708AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
709AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
710AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
711
712AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
713AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
714AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
715AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
716AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
717AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
718
719AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
720AC97_ENUM("Master Input Mux", wm9713_enum[7]),
721AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
722AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
723AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
724
725AC97_ENUM("Bass Control", wm9713_enum[12]),
726AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
727AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
728AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
729AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
730AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731};
732
Takashi Iwaiee423812005-11-17 14:21:36 +0100733static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
Liam Girdwood3998b702005-07-29 11:41:55 +0200734AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
735AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
736AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
737AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738};
739
Takashi Iwaiee423812005-11-17 14:21:36 +0100740static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
Liam Girdwood3998b702005-07-29 11:41:55 +0200741{
742 int err, i;
743
744 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
745 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
746 return err;
747 }
748 return 0;
749}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Takashi Iwaiee423812005-11-17 14:21:36 +0100751static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
753 int err, i;
754
Liam Girdwood3998b702005-07-29 11:41:55 +0200755 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
756 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 -0700757 return err;
758 }
759 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
762 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
765 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 return 0;
767}
768
769#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +0100770static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
773 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
774}
775
Takashi Iwaiee423812005-11-17 14:21:36 +0100776static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777{
778 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
779 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
780 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
781}
782#endif
783
784static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
785 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200786 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787#ifdef CONFIG_PM
788 .suspend = patch_wolfson_wm9713_suspend,
789 .resume = patch_wolfson_wm9713_resume
790#endif
791};
792
Takashi Iwaiee423812005-11-17 14:21:36 +0100793int patch_wolfson13(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Liam Girdwood3998b702005-07-29 11:41:55 +0200795 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 ac97->build_ops = &patch_wolfson_wm9713_ops;
797
798 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200799 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
800 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200801 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
804 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
805 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
806
807 return 0;
808}
809
810/*
811 * Tritech codec
812 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100813int patch_tritech_tr28028(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 snd_ac97_write_cache(ac97, 0x26, 0x0300);
816 snd_ac97_write_cache(ac97, 0x26, 0x0000);
817 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
818 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
819 return 0;
820}
821
822/*
823 * Sigmatel STAC97xx codecs
824 */
Takashi Iwaiee423812005-11-17 14:21:36 +0100825static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Takashi Iwaiee423812005-11-17 14:21:36 +0100827 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 int err;
829
830 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
831 return err;
832 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
833 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
834 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
835 return 0;
836}
837
Takashi Iwaiee423812005-11-17 14:21:36 +0100838static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Takashi Iwaiee423812005-11-17 14:21:36 +0100840 struct snd_kcontrol *kctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 int err;
842
843 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
844 return err;
845 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
846 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
847 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
848 return err;
849 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
850 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
851 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
852 return 0;
853}
854
Takashi Iwaiee423812005-11-17 14:21:36 +0100855static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
857
Takashi Iwaiee423812005-11-17 14:21:36 +0100858static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
860
Takashi Iwaiee423812005-11-17 14:21:36 +0100861static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
863AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
864};
865
Takashi Iwaiee423812005-11-17 14:21:36 +0100866static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
868 int err;
869
870 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
871 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
872 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
873 return err;
874 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
875 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
876 return err;
877 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
878 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
879 return err;
880 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
881 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
882 return err;
883 return 0;
884}
885
886static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
887 .build_3d = patch_sigmatel_stac9700_3d,
888 .build_specific = patch_sigmatel_stac97xx_specific
889};
890
Takashi Iwaiee423812005-11-17 14:21:36 +0100891int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892{
893 ac97->build_ops = &patch_sigmatel_stac9700_ops;
894 return 0;
895}
896
Takashi Iwaiee423812005-11-17 14:21:36 +0100897static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Takashi Iwaiee423812005-11-17 14:21:36 +0100899 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 int err;
901
Ingo Molnar62932df2006-01-16 16:34:20 +0100902 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
904 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
905 (ucontrol->value.integer.value[0] & 1) << 4);
906 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
Ingo Molnar62932df2006-01-16 16:34:20 +0100907 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return err;
909}
910
Takashi Iwaiee423812005-11-17 14:21:36 +0100911static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
913 .name = "Sigmatel Output Bias Switch",
914 .info = snd_ac97_info_volsw,
915 .get = snd_ac97_get_volsw,
916 .put = snd_ac97_stac9708_put_bias,
917 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
918};
919
Takashi Iwaiee423812005-11-17 14:21:36 +0100920static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
922 int err;
923
924 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
925 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
926 return err;
927 return patch_sigmatel_stac97xx_specific(ac97);
928}
929
930static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
931 .build_3d = patch_sigmatel_stac9708_3d,
932 .build_specific = patch_sigmatel_stac9708_specific
933};
934
Takashi Iwaiee423812005-11-17 14:21:36 +0100935int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 unsigned int codec72, codec6c;
938
939 ac97->build_ops = &patch_sigmatel_stac9708_ops;
940 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
941
942 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
943 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
944
945 if ((codec72==0) && (codec6c==0)) {
946 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
947 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
948 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
949 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
950 } else if ((codec72==0x8000) && (codec6c==0)) {
951 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
952 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
953 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
954 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
955 /* nothing */
956 }
957 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
958 return 0;
959}
960
Takashi Iwaiee423812005-11-17 14:21:36 +0100961int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 ac97->build_ops = &patch_sigmatel_stac9700_ops;
964 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
965 // patch for SigmaTel
966 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
968 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
970 }
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
972 return 0;
973}
974
Takashi Iwaiee423812005-11-17 14:21:36 +0100975int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 // patch for SigmaTel
978 ac97->build_ops = &patch_sigmatel_stac9700_ops;
979 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
980 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
981 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
982 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
983 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
984 return 0;
985}
986
Takashi Iwaiee423812005-11-17 14:21:36 +0100987int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 // patch for SigmaTel
990 ac97->build_ops = &patch_sigmatel_stac9700_ops;
991 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
992 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
993 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
994 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
995 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
996 return 0;
997}
998
Takashi Iwaiee423812005-11-17 14:21:36 +0100999static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 static char *texts[5] = { "Input/Disabled", "Front Output",
1002 "Rear Output", "Center/LFE Output", "Mixer Output" };
1003
1004 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1005 uinfo->count = 1;
1006 uinfo->value.enumerated.items = 5;
1007 if (uinfo->value.enumerated.item > 4)
1008 uinfo->value.enumerated.item = 4;
1009 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1010 return 0;
1011}
1012
Takashi Iwaiee423812005-11-17 14:21:36 +01001013static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Takashi Iwaiee423812005-11-17 14:21:36 +01001015 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 int shift = kcontrol->private_value;
1017 unsigned short val;
1018
1019 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1020 if (!(val & 4))
1021 ucontrol->value.enumerated.item[0] = 0;
1022 else
1023 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1024 return 0;
1025}
1026
Takashi Iwaiee423812005-11-17 14:21:36 +01001027static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Takashi Iwaiee423812005-11-17 14:21:36 +01001029 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 int shift = kcontrol->private_value;
1031 unsigned short val;
1032
1033 if (ucontrol->value.enumerated.item[0] > 4)
1034 return -EINVAL;
1035 if (ucontrol->value.enumerated.item[0] == 0)
1036 val = 0;
1037 else
1038 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1039 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1040 7 << shift, val << shift, 0);
1041}
1042
Takashi Iwaiee423812005-11-17 14:21:36 +01001043static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1046 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1047
1048 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1049 uinfo->count = 1;
1050 uinfo->value.enumerated.items = 7;
1051 if (uinfo->value.enumerated.item > 6)
1052 uinfo->value.enumerated.item = 6;
1053 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1054 return 0;
1055}
1056
Takashi Iwaiee423812005-11-17 14:21:36 +01001057static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Takashi Iwaiee423812005-11-17 14:21:36 +01001059 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 int shift = kcontrol->private_value;
1061 unsigned short val;
1062
1063 val = ac97->regs[AC97_SIGMATEL_INSEL];
1064 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1065 return 0;
1066}
1067
Takashi Iwaiee423812005-11-17 14:21:36 +01001068static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Takashi Iwaiee423812005-11-17 14:21:36 +01001070 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 int shift = kcontrol->private_value;
1072
1073 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1074 ucontrol->value.enumerated.item[0] << shift, 0);
1075}
1076
Takashi Iwaiee423812005-11-17 14:21:36 +01001077static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
1079 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1080
1081 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1082 uinfo->count = 1;
1083 uinfo->value.enumerated.items = 3;
1084 if (uinfo->value.enumerated.item > 2)
1085 uinfo->value.enumerated.item = 2;
1086 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1087 return 0;
1088}
1089
Takashi Iwaiee423812005-11-17 14:21:36 +01001090static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Takashi Iwaiee423812005-11-17 14:21:36 +01001092 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1095 return 0;
1096}
1097
Takashi Iwaiee423812005-11-17 14:21:36 +01001098static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Takashi Iwaiee423812005-11-17 14:21:36 +01001100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1103 ucontrol->value.enumerated.item[0], 0);
1104}
1105
1106#define STAC9758_OUTPUT_JACK(xname, shift) \
1107{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1108 .info = snd_ac97_stac9758_output_jack_info, \
1109 .get = snd_ac97_stac9758_output_jack_get, \
1110 .put = snd_ac97_stac9758_output_jack_put, \
1111 .private_value = shift }
1112#define STAC9758_INPUT_JACK(xname, shift) \
1113{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1114 .info = snd_ac97_stac9758_input_jack_info, \
1115 .get = snd_ac97_stac9758_input_jack_get, \
1116 .put = snd_ac97_stac9758_input_jack_put, \
1117 .private_value = shift }
Takashi Iwaiee423812005-11-17 14:21:36 +01001118static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1120 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1121 STAC9758_OUTPUT_JACK("Front Jack", 7),
1122 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1123 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1124 STAC9758_INPUT_JACK("Mic Input Source", 0),
1125 STAC9758_INPUT_JACK("Line Input Source", 8),
1126 {
1127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1128 .name = "Headphone Amp",
1129 .info = snd_ac97_stac9758_phonesel_info,
1130 .get = snd_ac97_stac9758_phonesel_get,
1131 .put = snd_ac97_stac9758_phonesel_put
1132 },
1133 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1134 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1135};
1136
Takashi Iwaiee423812005-11-17 14:21:36 +01001137static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
1139 int err;
1140
1141 err = patch_sigmatel_stac97xx_specific(ac97);
1142 if (err < 0)
1143 return err;
1144 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1145 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1146 if (err < 0)
1147 return err;
1148 /* DAC-A direct */
1149 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1150 /* DAC-A to Mix = PCM */
1151 /* DAC-B direct = Surround */
1152 /* DAC-B to Mix */
1153 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1154 /* DAC-C direct = Center/LFE */
1155
1156 return 0;
1157}
1158
1159static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1160 .build_3d = patch_sigmatel_stac9700_3d,
1161 .build_specific = patch_sigmatel_stac9758_specific
1162};
1163
Takashi Iwaiee423812005-11-17 14:21:36 +01001164int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
1166 static unsigned short regs[4] = {
1167 AC97_SIGMATEL_OUTSEL,
1168 AC97_SIGMATEL_IOMISC,
1169 AC97_SIGMATEL_INSEL,
1170 AC97_SIGMATEL_VARIOUS
1171 };
1172 static unsigned short def_regs[4] = {
1173 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1174 /* IOMISC */ 0x2001,
1175 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1176 /* VARIOUS */ 0x0040
1177 };
1178 static unsigned short m675_regs[4] = {
1179 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1180 /* IOMISC */ 0x2102, /* HP amp on */
1181 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1182 /* VARIOUS */ 0x0041 /* stereo mic */
1183 };
1184 unsigned short *pregs = def_regs;
1185 int i;
1186
1187 /* Gateway M675 notebook */
1188 if (ac97->pci &&
1189 ac97->subsystem_vendor == 0x107b &&
1190 ac97->subsystem_device == 0x0601)
1191 pregs = m675_regs;
1192
1193 // patch for SigmaTel
1194 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1195 /* FIXME: assume only page 0 for writing cache */
1196 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1197 for (i = 0; i < 4; i++)
1198 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1199
1200 ac97->flags |= AC97_STEREO_MUTES;
1201 return 0;
1202}
1203
1204/*
1205 * Cirrus Logic CS42xx codecs
1206 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001207static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1209 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1210};
1211
Takashi Iwaiee423812005-11-17 14:21:36 +01001212static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214 int err;
1215
1216 /* con mask, pro mask, default */
1217 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1218 return err;
1219 /* switch, spsa */
1220 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1221 return err;
1222 switch (ac97->id & AC97_ID_CS_MASK) {
1223 case AC97_ID_CS4205:
1224 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1225 return err;
1226 break;
1227 }
1228 /* set default PCM S/PDIF params */
1229 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1230 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1231 return 0;
1232}
1233
1234static struct snd_ac97_build_ops patch_cirrus_ops = {
1235 .build_spdif = patch_cirrus_build_spdif
1236};
1237
Takashi Iwaiee423812005-11-17 14:21:36 +01001238int patch_cirrus_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
1240 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1241 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1242 - sp/dif EA ID is not set, but sp/dif is always present.
1243 - enable/disable is spdif register bit 15.
1244 - sp/dif control register is 0x68. differs from AC97:
1245 - valid is bit 14 (vs 15)
1246 - no DRS
1247 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1248 - sp/dif ssource select is in 0x5e bits 0,1.
1249 */
1250
1251 ac97->build_ops = &patch_cirrus_ops;
1252 ac97->flags |= AC97_CS_SPDIF;
1253 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1254 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1255 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1256 return 0;
1257}
1258
Takashi Iwaiee423812005-11-17 14:21:36 +01001259int patch_cirrus_cs4299(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
1261 /* force the detection of PC Beep */
1262 ac97->flags |= AC97_HAS_PC_BEEP;
1263
1264 return patch_cirrus_spdif(ac97);
1265}
1266
1267/*
1268 * Conexant codecs
1269 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001270static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1272};
1273
Takashi Iwaiee423812005-11-17 14:21:36 +01001274static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
1276 int err;
1277
1278 /* con mask, pro mask, default */
1279 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1280 return err;
1281 /* switch */
1282 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1283 return err;
1284 /* set default PCM S/PDIF params */
1285 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1286 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1287 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1288 return 0;
1289}
1290
1291static struct snd_ac97_build_ops patch_conexant_ops = {
1292 .build_spdif = patch_conexant_build_spdif
1293};
1294
Takashi Iwaiee423812005-11-17 14:21:36 +01001295int patch_conexant(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
1297 ac97->build_ops = &patch_conexant_ops;
1298 ac97->flags |= AC97_CX_SPDIF;
1299 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1300 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1301 return 0;
1302}
1303
1304/*
1305 * Analog Device AD18xx, AD19xx codecs
1306 */
1307#ifdef CONFIG_PM
Takashi Iwaiee423812005-11-17 14:21:36 +01001308static void ad18xx_resume(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
1310 static unsigned short setup_regs[] = {
1311 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1312 };
1313 int i, codec;
1314
1315 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1316 unsigned short reg = setup_regs[i];
1317 if (test_bit(reg, ac97->reg_accessed)) {
1318 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1319 snd_ac97_read(ac97, reg);
1320 }
1321 }
1322
1323 if (! (ac97->flags & AC97_AD_MULTI))
1324 /* normal restore */
1325 snd_ac97_restore_status(ac97);
1326 else {
1327 /* restore the AD18xx codec configurations */
1328 for (codec = 0; codec < 3; codec++) {
1329 if (! ac97->spec.ad18xx.id[codec])
1330 continue;
1331 /* select single codec */
1332 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1333 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1334 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1335 }
1336 /* select all codecs */
1337 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1338
1339 /* restore status */
1340 for (i = 2; i < 0x7c ; i += 2) {
1341 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1342 continue;
1343 if (test_bit(i, ac97->reg_accessed)) {
1344 /* handle multi codecs for AD18xx */
1345 if (i == AC97_PCM) {
1346 for (codec = 0; codec < 3; codec++) {
1347 if (! ac97->spec.ad18xx.id[codec])
1348 continue;
1349 /* select single codec */
1350 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1351 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1352 /* update PCM bits */
1353 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1354 }
1355 /* select all codecs */
1356 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1357 continue;
1358 } else if (i == AC97_AD_TEST ||
1359 i == AC97_AD_CODEC_CFG ||
1360 i == AC97_AD_SERIAL_CFG)
1361 continue; /* ignore */
1362 }
1363 snd_ac97_write(ac97, i, ac97->regs[i]);
1364 snd_ac97_read(ac97, i);
1365 }
1366 }
1367
1368 snd_ac97_restore_iec958(ac97);
1369}
1370#endif
1371
Takashi Iwaiee423812005-11-17 14:21:36 +01001372int patch_ad1819(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
1374 unsigned short scfg;
1375
1376 // patch for Analog Devices
1377 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1378 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1379 return 0;
1380}
1381
Takashi Iwaiee423812005-11-17 14:21:36 +01001382static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 unsigned short val;
1385
1386 // test for unchained codec
1387 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1388 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1389 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1390 if ((val & 0xff40) != 0x5340)
1391 return 0;
1392 ac97->spec.ad18xx.unchained[idx] = mask;
1393 ac97->spec.ad18xx.id[idx] = val;
1394 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1395 return mask;
1396}
1397
Takashi Iwaiee423812005-11-17 14:21:36 +01001398static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
1400 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1401 unsigned short val;
1402
1403 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1404 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1405 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1406 if ((val & 0xff40) != 0x5340)
1407 return 0;
1408 if (codec_bits)
1409 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1410 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1411 ac97->spec.ad18xx.id[idx] = val;
1412 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1413 return 1;
1414}
1415
Takashi Iwaiee423812005-11-17 14:21:36 +01001416static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
1418 // already detected?
1419 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1420 cidx1 = -1;
1421 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1422 cidx2 = -1;
1423 if (cidx1 < 0 && cidx2 < 0)
1424 return;
1425 // test for chained codecs
1426 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1427 ac97->spec.ad18xx.unchained[unchained_idx]);
1428 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1429 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1430 if (cidx1 >= 0) {
1431 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1432 patch_ad1881_chained1(ac97, cidx2, 0);
1433 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1434 patch_ad1881_chained1(ac97, cidx1, 0);
1435 } else if (cidx2 >= 0) {
1436 patch_ad1881_chained1(ac97, cidx2, 0);
1437 }
1438}
1439
1440static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1441#ifdef CONFIG_PM
1442 .resume = ad18xx_resume
1443#endif
1444};
1445
Takashi Iwaiee423812005-11-17 14:21:36 +01001446int patch_ad1881(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448 static const char cfg_idxs[3][2] = {
1449 {2, 1},
1450 {0, 2},
1451 {0, 1}
1452 };
1453
1454 // patch for Analog Devices
1455 unsigned short codecs[3];
1456 unsigned short val;
1457 int idx, num;
1458
1459 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1460 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1461 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1462 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1463 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1464
Takashi Iwai7c22f1a2005-10-10 11:46:31 +02001465 if (! (codecs[0] || codecs[1] || codecs[2]))
1466 goto __end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 for (idx = 0; idx < 3; idx++)
1469 if (ac97->spec.ad18xx.unchained[idx])
1470 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1471
1472 if (ac97->spec.ad18xx.id[1]) {
1473 ac97->flags |= AC97_AD_MULTI;
1474 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1475 }
1476 if (ac97->spec.ad18xx.id[2]) {
1477 ac97->flags |= AC97_AD_MULTI;
1478 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1479 }
1480
1481 __end:
1482 /* select all codecs */
1483 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1484 /* check if only one codec is present */
1485 for (idx = num = 0; idx < 3; idx++)
1486 if (ac97->spec.ad18xx.id[idx])
1487 num++;
1488 if (num == 1) {
1489 /* ok, deselect all ID bits */
1490 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1491 ac97->spec.ad18xx.codec_cfg[0] =
1492 ac97->spec.ad18xx.codec_cfg[1] =
1493 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1494 }
1495 /* required for AD1886/AD1885 combination */
1496 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1497 if (ac97->spec.ad18xx.id[0]) {
1498 ac97->id &= 0xffff0000;
1499 ac97->id |= ac97->spec.ad18xx.id[0];
1500 }
1501 ac97->build_ops = &patch_ad1881_build_ops;
1502 return 0;
1503}
1504
Takashi Iwaiee423812005-11-17 14:21:36 +01001505static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1507 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1508 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1509 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1510 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1511 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1512};
1513
Takashi Iwaiee423812005-11-17 14:21:36 +01001514static int patch_ad1885_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 int err;
1517
1518 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1519 return err;
1520 return 0;
1521}
1522
1523static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1524 .build_specific = &patch_ad1885_specific,
1525#ifdef CONFIG_PM
1526 .resume = ad18xx_resume
1527#endif
1528};
1529
Takashi Iwaiee423812005-11-17 14:21:36 +01001530int patch_ad1885(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
1532 patch_ad1881(ac97);
1533 /* This is required to deal with the Intel D815EEAL2 */
1534 /* i.e. Line out is actually headphone out from codec */
1535
1536 /* set default */
1537 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1538
1539 ac97->build_ops = &patch_ad1885_build_ops;
1540 return 0;
1541}
1542
Takashi Iwaiee423812005-11-17 14:21:36 +01001543int patch_ad1886(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
1545 patch_ad1881(ac97);
1546 /* Presario700 workaround */
1547 /* for Jack Sense/SPDIF Register misetting causing */
1548 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1549 return 0;
1550}
1551
1552/* MISC bits */
1553#define AC97_AD198X_MBC 0x0003 /* mic boost */
1554#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1555#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1556#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1557#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1558#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1559#define AC97_AD198X_VREF_0 0x000c /* 0V */
1560#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1561#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1562#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1563#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1564#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1565#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1566#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1567#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1568#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1569#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1570#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1571#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1572
1573
Takashi Iwaiee423812005-11-17 14:21:36 +01001574static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
1576 static char *texts[2] = { "AC-Link", "A/D Converter" };
1577
1578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1579 uinfo->count = 1;
1580 uinfo->value.enumerated.items = 2;
1581 if (uinfo->value.enumerated.item > 1)
1582 uinfo->value.enumerated.item = 1;
1583 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1584 return 0;
1585}
1586
Takashi Iwaiee423812005-11-17 14:21:36 +01001587static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
Takashi Iwaiee423812005-11-17 14:21:36 +01001589 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 unsigned short val;
1591
1592 val = ac97->regs[AC97_AD_SERIAL_CFG];
1593 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1594 return 0;
1595}
1596
Takashi Iwaiee423812005-11-17 14:21:36 +01001597static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598{
Takashi Iwaiee423812005-11-17 14:21:36 +01001599 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 unsigned short val;
1601
1602 if (ucontrol->value.enumerated.item[0] > 1)
1603 return -EINVAL;
1604 val = ucontrol->value.enumerated.item[0] << 2;
1605 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1606}
1607
Takashi Iwaiee423812005-11-17 14:21:36 +01001608static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1610 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1611 .info = snd_ac97_ad198x_spdif_source_info,
1612 .get = snd_ac97_ad198x_spdif_source_get,
1613 .put = snd_ac97_ad198x_spdif_source_put,
1614};
1615
Takashi Iwaiee423812005-11-17 14:21:36 +01001616static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
1618 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1619}
1620
Takashi Iwaiee423812005-11-17 14:21:36 +01001621static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1623 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1624};
1625
Takashi Iwai128a46a2006-01-11 18:15:43 +01001626/* black list to avoid HP/Line jack-sense controls
1627 * (SS vendor << 16 | device)
1628 */
1629static unsigned int ad1981_jacks_blacklist[] = {
1630 0x10140554, /* Thinkpad T42p/R50p */
1631 0 /* end */
1632};
1633
1634static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1635{
1636 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1637 for (; *list; list++)
1638 if (*list == subid)
1639 return 1;
1640 return 0;
1641}
1642
Takashi Iwaiee423812005-11-17 14:21:36 +01001643static int patch_ad1981a_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001645 if (check_list(ac97, ad1981_jacks_blacklist))
1646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1648 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1649}
1650
1651static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1652 .build_post_spdif = patch_ad198x_post_spdif,
1653 .build_specific = patch_ad1981a_specific,
1654#ifdef CONFIG_PM
1655 .resume = ad18xx_resume
1656#endif
1657};
1658
Takashi Iwai128a46a2006-01-11 18:15:43 +01001659/* white list to enable HP jack-sense bits
1660 * (SS vendor << 16 | device)
1661 */
1662static unsigned int ad1981_jacks_whitelist[] = {
1663 0x0e11005a, /* HP nc4000/4010 */
1664 0x103c0890, /* HP nc6000 */
1665 0x103c0938, /* HP nc4220 */
1666 0x103c099c, /* HP nx6110 */
1667 0x103c0944, /* HP nc6220 */
1668 0x103c0934, /* HP nc8220 */
1669 0x103c006d, /* HP nx9105 */
1670 0x17340088, /* FSC Scenic-W */
1671 0 /* end */
1672};
1673
Takashi Iwaiee423812005-11-17 14:21:36 +01001674static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Takashi Iwai128a46a2006-01-11 18:15:43 +01001676 if (check_list(ac97, ad1981_jacks_whitelist))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 /* enable headphone jack sense */
1678 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Takashi Iwaiee423812005-11-17 14:21:36 +01001681int patch_ad1981a(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 patch_ad1881(ac97);
1684 ac97->build_ops = &patch_ad1981a_build_ops;
1685 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1686 ac97->flags |= AC97_STEREO_MUTES;
1687 check_ad1981_hp_jack_sense(ac97);
1688 return 0;
1689}
1690
Takashi Iwaiee423812005-11-17 14:21:36 +01001691static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1693
Takashi Iwaiee423812005-11-17 14:21:36 +01001694static int patch_ad1981b_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
1696 int err;
1697
1698 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1699 return err;
Takashi Iwai128a46a2006-01-11 18:15:43 +01001700 if (check_list(ac97, ad1981_jacks_blacklist))
1701 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1703 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1704}
1705
1706static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1707 .build_post_spdif = patch_ad198x_post_spdif,
1708 .build_specific = patch_ad1981b_specific,
1709#ifdef CONFIG_PM
1710 .resume = ad18xx_resume
1711#endif
1712};
1713
Takashi Iwaiee423812005-11-17 14:21:36 +01001714int patch_ad1981b(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715{
1716 patch_ad1881(ac97);
1717 ac97->build_ops = &patch_ad1981b_build_ops;
1718 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1719 ac97->flags |= AC97_STEREO_MUTES;
1720 check_ad1981_hp_jack_sense(ac97);
1721 return 0;
1722}
1723
Takashi Iwaiee423812005-11-17 14:21:36 +01001724static int snd_ac97_ad1888_lohpsel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
1726 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1727 uinfo->count = 1;
1728 uinfo->value.integer.min = 0;
1729 uinfo->value.integer.max = 1;
1730 return 0;
1731}
1732
Takashi Iwaiee423812005-11-17 14:21:36 +01001733static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
Takashi Iwaiee423812005-11-17 14:21:36 +01001735 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 unsigned short val;
1737
1738 val = ac97->regs[AC97_AD_MISC];
1739 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1740 return 0;
1741}
1742
Takashi Iwaiee423812005-11-17 14:21:36 +01001743static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Takashi Iwaiee423812005-11-17 14:21:36 +01001745 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 unsigned short val;
1747
1748 val = !ucontrol->value.integer.value[0]
1749 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1750 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1751 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1752}
1753
Takashi Iwaiee423812005-11-17 14:21:36 +01001754static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
1756 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1757
1758 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1759 uinfo->count = 1;
1760 uinfo->value.enumerated.items = 3;
1761 if (uinfo->value.enumerated.item > 2)
1762 uinfo->value.enumerated.item = 2;
1763 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1764 return 0;
1765}
1766
Takashi Iwaiee423812005-11-17 14:21:36 +01001767static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
Takashi Iwaiee423812005-11-17 14:21:36 +01001769 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 unsigned short val;
1771
1772 val = ac97->regs[AC97_AD_MISC];
1773 if (!(val & AC97_AD198X_DMIX1))
1774 ucontrol->value.enumerated.item[0] = 0;
1775 else
1776 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1777 return 0;
1778}
1779
Takashi Iwaiee423812005-11-17 14:21:36 +01001780static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
Takashi Iwaiee423812005-11-17 14:21:36 +01001782 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 unsigned short val;
1784
1785 if (ucontrol->value.enumerated.item[0] > 2)
1786 return -EINVAL;
1787 if (ucontrol->value.enumerated.item[0] == 0)
1788 val = 0;
1789 else
1790 val = AC97_AD198X_DMIX1 |
1791 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1792 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1793 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1794}
1795
Takashi Iwaiee423812005-11-17 14:21:36 +01001796static void ad1888_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001797{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001798 unsigned short val = 0;
1799 if (! is_shared_linein(ac97))
1800 val |= (1 << 12);
1801 if (! is_shared_micin(ac97))
1802 val |= (1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001803 /* shared Line-In */
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001804 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001805}
1806
Takashi Iwaiee423812005-11-17 14:21:36 +01001807static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 {
1809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1810 .name = "Exchange Front/Surround",
1811 .info = snd_ac97_ad1888_lohpsel_info,
1812 .get = snd_ac97_ad1888_lohpsel_get,
1813 .put = snd_ac97_ad1888_lohpsel_put
1814 },
1815 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1816 {
1817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1818 .name = "Downmix",
1819 .info = snd_ac97_ad1888_downmix_info,
1820 .get = snd_ac97_ad1888_downmix_get,
1821 .put = snd_ac97_ad1888_downmix_put
1822 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001823 AC97_SURROUND_JACK_MODE_CTL,
1824 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001825
1826 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1827 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828};
1829
Takashi Iwaiee423812005-11-17 14:21:36 +01001830static int patch_ad1888_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
1832 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1833 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1834 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1835 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1836}
1837
1838static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1839 .build_post_spdif = patch_ad198x_post_spdif,
1840 .build_specific = patch_ad1888_specific,
1841#ifdef CONFIG_PM
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001842 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001844 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845};
1846
Takashi Iwaiee423812005-11-17 14:21:36 +01001847int patch_ad1888(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
1849 unsigned short misc;
1850
1851 patch_ad1881(ac97);
1852 ac97->build_ops = &patch_ad1888_build_ops;
1853 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1854 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1855 /* AD-compatible mode */
1856 /* Stereo mutes enabled */
1857 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1858 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1859 AC97_AD198X_LOSEL |
1860 AC97_AD198X_HPSEL |
1861 AC97_AD198X_MSPLT |
1862 AC97_AD198X_AC97NC);
1863 ac97->flags |= AC97_STEREO_MUTES;
1864 return 0;
1865}
1866
Takashi Iwaiee423812005-11-17 14:21:36 +01001867static int patch_ad1980_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
1869 int err;
1870
1871 if ((err = patch_ad1888_specific(ac97)) < 0)
1872 return err;
1873 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1874}
1875
1876static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1877 .build_post_spdif = patch_ad198x_post_spdif,
1878 .build_specific = patch_ad1980_specific,
1879#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001880 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001882 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883};
1884
Takashi Iwaiee423812005-11-17 14:21:36 +01001885int patch_ad1980(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886{
1887 patch_ad1888(ac97);
1888 ac97->build_ops = &patch_ad1980_build_ops;
1889 return 0;
1890}
1891
Takashi Iwaiee423812005-11-17 14:21:36 +01001892static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1894};
1895
Takashi Iwaiee423812005-11-17 14:21:36 +01001896static void ad1985_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001897{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02001898 ad1888_update_jacks(ac97);
Takashi Iwaifc232c62005-05-27 10:42:45 +02001899 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1900 is_shared_micin(ac97) ? 0 : 1 << 9);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001901}
1902
Takashi Iwaiee423812005-11-17 14:21:36 +01001903static int patch_ad1985_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
1905 int err;
1906
1907 if ((err = patch_ad1980_specific(ac97)) < 0)
1908 return err;
1909 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1910}
1911
1912static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1913 .build_post_spdif = patch_ad198x_post_spdif,
1914 .build_specific = patch_ad1985_specific,
1915#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001916 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001918 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919};
1920
Takashi Iwaiee423812005-11-17 14:21:36 +01001921int patch_ad1985(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
1923 unsigned short misc;
1924
1925 patch_ad1881(ac97);
1926 ac97->build_ops = &patch_ad1985_build_ops;
1927 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1928 /* switch front/surround line-out/hp-out */
1929 /* center/LFE, mic in 3.75V mode */
1930 /* AD-compatible mode */
1931 /* Stereo mutes enabled */
1932 /* in accordance with ADI driver: misc | 0x5c28 */
1933 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1934 AC97_AD198X_VREFH |
1935 AC97_AD198X_LOSEL |
1936 AC97_AD198X_HPSEL |
1937 AC97_AD198X_CLDIS |
1938 AC97_AD198X_LODIS |
1939 AC97_AD198X_MSPLT |
1940 AC97_AD198X_AC97NC);
1941 ac97->flags |= AC97_STEREO_MUTES;
1942 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1943 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1944 return 0;
1945}
1946
1947/*
1948 * realtek ALC65x/850 codecs
1949 */
Takashi Iwaiee423812005-11-17 14:21:36 +01001950static void alc650_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001952 int shared;
1953
1954 /* shared Line-In */
1955 shared = is_shared_linein(ac97);
1956 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1957 shared ? (1 << 9) : 0);
1958 /* update shared Mic */
1959 shared = is_shared_micin(ac97);
1960 /* disable/enable vref */
1961 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1962 shared ? (1 << 12) : 0);
1963 /* turn on/off center-on-mic */
1964 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1965 shared ? (1 << 10) : 0);
1966 /* GPIO0 high for mic */
1967 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1968 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
Takashi Iwaiee423812005-11-17 14:21:36 +01001971static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1973 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1974 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1975 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1976 /* 4: Analog Input To Surround */
1977 /* 5: Analog Input To Center/LFE */
1978 /* 6: Independent Master Volume Right */
1979 /* 7: Independent Master Volume Left */
1980 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001981 /* 9: Line-In/Surround share */
1982 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 /* 11-13: in IEC958 controls */
1984 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1985#if 0 /* always set in patch_alc650 */
1986 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1987 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1988 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1989 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1990 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1991 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1992#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001993 AC97_SURROUND_JACK_MODE_CTL,
1994 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995};
1996
Takashi Iwaiee423812005-11-17 14:21:36 +01001997static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001998 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2000 /* disable this controls since it doesn't work as expected */
2001 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2002};
2003
Takashi Iwaiee423812005-11-17 14:21:36 +01002004static int patch_alc650_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005{
2006 int err;
2007
2008 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2009 return err;
2010 if (ac97->ext_id & AC97_EI_SPDIF) {
2011 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2012 return err;
2013 }
2014 return 0;
2015}
2016
2017static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002018 .build_specific = patch_alc650_specific,
2019 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020};
2021
Takashi Iwaiee423812005-11-17 14:21:36 +01002022int patch_alc650(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023{
2024 unsigned short val;
2025
2026 ac97->build_ops = &patch_alc650_ops;
2027
2028 /* determine the revision */
2029 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2030 if (val < 3)
2031 ac97->id = 0x414c4720; /* Old version */
2032 else if (val < 0x10)
2033 ac97->id = 0x414c4721; /* D version */
2034 else if (val < 0x20)
2035 ac97->id = 0x414c4722; /* E version */
2036 else if (val < 0x30)
2037 ac97->id = 0x414c4723; /* F version */
2038
2039 /* revision E or F */
2040 /* FIXME: what about revision D ? */
2041 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2042 ac97->id == 0x414c4723);
2043
2044 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2045 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2046 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2047
2048 /* Enable SPDIF-IN only on Rev.E and above */
2049 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2050 /* SPDIF IN with pin 47 */
2051 if (ac97->spec.dev_flags)
2052 val |= 0x03; /* enable */
2053 else
2054 val &= ~0x03; /* disable */
2055 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2056
2057 /* set default: slot 3,4,7,8,6,9
2058 spdif-in monitor off, analog-spdif off, spdif-in off
2059 center on mic off, surround on line-in off
2060 downmix off, duplicate front off
2061 */
2062 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2063
2064 /* set GPIO0 for mic bias */
2065 /* GPIO0 pin output, no interrupt, high */
2066 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2067 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2068 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2069 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2070
2071 /* full DAC volume */
2072 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2073 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2074 return 0;
2075}
2076
Takashi Iwaiee423812005-11-17 14:21:36 +01002077static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002079 int shared;
2080
2081 /* shared Line-In */
2082 shared = is_shared_linein(ac97);
2083 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2084 shared ? (1 << 9) : 0, 0);
2085 /* update shared mic */
2086 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 /* misc control; vrefout disable */
2088 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002089 shared ? (1 << 12) : 0);
2090 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2091 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092}
2093
Takashi Iwaiee423812005-11-17 14:21:36 +01002094static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002096 AC97_SURROUND_JACK_MODE_CTL,
2097 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098};
2099
Takashi Iwaiee423812005-11-17 14:21:36 +01002100static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101{
2102 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2103 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002104 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2107 uinfo->count = 1;
2108 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2109 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2110 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2111 strcpy(uinfo->value.enumerated.name,
2112 ac97->spec.dev_flags ?
2113 texts_658[uinfo->value.enumerated.item] :
2114 texts_655[uinfo->value.enumerated.item]);
2115 return 0;
2116}
2117
Takashi Iwaiee423812005-11-17 14:21:36 +01002118static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
Takashi Iwaiee423812005-11-17 14:21:36 +01002120 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 unsigned short val;
2122
2123 val = ac97->regs[AC97_ALC650_MULTICH];
2124 val = (val >> 12) & 3;
2125 if (ac97->spec.dev_flags && val == 3)
2126 val = 0;
2127 ucontrol->value.enumerated.item[0] = val;
2128 return 0;
2129}
2130
Takashi Iwaiee423812005-11-17 14:21:36 +01002131static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Takashi Iwaiee423812005-11-17 14:21:36 +01002133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
2135 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2136 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2137 0);
2138}
2139
Takashi Iwaiee423812005-11-17 14:21:36 +01002140static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002141 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 /* disable this controls since it doesn't work as expected */
2143 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2144 {
2145 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002146 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 .info = alc655_iec958_route_info,
2148 .get = alc655_iec958_route_get,
2149 .put = alc655_iec958_route_put,
2150 },
2151};
2152
Takashi Iwaiee423812005-11-17 14:21:36 +01002153static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
2155 int err;
2156
2157 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2158 return err;
2159 if (ac97->ext_id & AC97_EI_SPDIF) {
2160 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2161 return err;
2162 }
2163 return 0;
2164}
2165
2166static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002167 .build_specific = patch_alc655_specific,
2168 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169};
2170
Takashi Iwaiee423812005-11-17 14:21:36 +01002171int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
2173 unsigned int val;
2174
Takashi Iwaia5022b02005-09-02 14:03:05 +02002175 if (ac97->id == AC97_ID_ALC658) {
2176 ac97->spec.dev_flags = 1; /* ALC658 */
2177 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2178 ac97->id = AC97_ID_ALC658D;
2179 ac97->spec.dev_flags = 2;
2180 }
2181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183 ac97->build_ops = &patch_alc655_ops;
2184
2185 /* assume only page 0 for writing cache */
2186 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2187
2188 /* adjust default values */
2189 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002190 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002192 else { /* ALC655 */
2193 if (ac97->subsystem_vendor == 0x1462 &&
2194 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */
2195 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2196 else
2197 val |= (1 << 1); /* Pin 47 is spdif input pin */
2198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 val &= ~(1 << 12); /* vref enable */
2200 snd_ac97_write_cache(ac97, 0x7a, val);
2201 /* set default: spdif-in enabled,
2202 spdif-in monitor off, spdif-in PCM off
2203 center on mic off, surround on line-in off
2204 duplicate front off
2205 */
2206 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2207
2208 /* full DAC volume */
2209 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2210 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002211
2212 /* update undocumented bit... */
2213 if (ac97->id == AC97_ID_ALC658D)
2214 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 return 0;
2217}
2218
2219
2220#define AC97_ALC850_JACK_SELECT 0x76
2221#define AC97_ALC850_MISC1 0x7a
2222
Takashi Iwaiee423812005-11-17 14:21:36 +01002223static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002225 int shared;
2226
2227 /* shared Line-In */
2228 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 /* SURR 1kOhm (bit4), Amp (bit5) */
2230 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002231 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002233 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2234 shared ? (2<<12) : (0<<12));
2235 /* update shared mic */
2236 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 /* Vref disable (bit12), 1kOhm (bit13) */
2238 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002239 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002240 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002241 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002242 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243}
2244
Takashi Iwaiee423812005-11-17 14:21:36 +01002245static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002247 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002248 AC97_SURROUND_JACK_MODE_CTL,
2249 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250};
2251
Takashi Iwaiee423812005-11-17 14:21:36 +01002252static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
2254 int err;
2255
2256 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2257 return err;
2258 if (ac97->ext_id & AC97_EI_SPDIF) {
2259 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2260 return err;
2261 }
2262 return 0;
2263}
2264
2265static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002266 .build_specific = patch_alc850_specific,
2267 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268};
2269
Takashi Iwaiee423812005-11-17 14:21:36 +01002270int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
2272 ac97->build_ops = &patch_alc850_ops;
2273
2274 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2275
2276 /* assume only page 0 for writing cache */
2277 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2278
2279 /* adjust default values */
2280 /* set default: spdif-in enabled,
2281 spdif-in monitor off, spdif-in PCM off
2282 center on mic off, surround on line-in off
2283 duplicate front off
2284 */
2285 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2286 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2287 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2288 */
2289 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2290 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2291 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2292 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2293 */
2294 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2295 (1<<11)|(0<<12)|(1<<15));
2296
2297 /* full DAC volume */
2298 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2299 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2300 return 0;
2301}
2302
2303
2304/*
2305 * C-Media CM97xx codecs
2306 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002307static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002308{
2309 /* shared Line-In */
2310 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2311 is_shared_linein(ac97) ? (1 << 10) : 0);
2312}
2313
Takashi Iwaiee423812005-11-17 14:21:36 +01002314static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002316 AC97_SURROUND_JACK_MODE_CTL,
2317 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318};
2319
Takashi Iwaiee423812005-11-17 14:21:36 +01002320static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
2322 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2323}
2324
2325static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002326 .build_specific = patch_cm9738_specific,
2327 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328};
2329
Takashi Iwaiee423812005-11-17 14:21:36 +01002330int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
2332 ac97->build_ops = &patch_cm9738_ops;
2333 /* FIXME: can anyone confirm below? */
2334 /* CM9738 has no PCM volume although the register reacts */
2335 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2336 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2337
2338 return 0;
2339}
2340
Takashi Iwaiee423812005-11-17 14:21:36 +01002341static 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 -07002342{
2343 static char *texts[] = { "Analog", "Digital" };
2344
2345 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2346 uinfo->count = 1;
2347 uinfo->value.enumerated.items = 2;
2348 if (uinfo->value.enumerated.item > 1)
2349 uinfo->value.enumerated.item = 1;
2350 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2351 return 0;
2352}
2353
Takashi Iwaiee423812005-11-17 14:21:36 +01002354static 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 -07002355{
Takashi Iwaiee423812005-11-17 14:21:36 +01002356 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 unsigned short val;
2358
2359 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2360 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2361 return 0;
2362}
2363
Takashi Iwaiee423812005-11-17 14:21:36 +01002364static 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 -07002365{
Takashi Iwaiee423812005-11-17 14:21:36 +01002366 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
2368 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2369 0x01 << 1,
2370 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2371}
2372
Takashi Iwaiee423812005-11-17 14:21:36 +01002373static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 /* BIT 0: SPDI_EN - always true */
2375 { /* BIT 1: SPDIFS */
2376 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2377 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2378 .info = snd_ac97_cmedia_spdif_playback_source_info,
2379 .get = snd_ac97_cmedia_spdif_playback_source_get,
2380 .put = snd_ac97_cmedia_spdif_playback_source_put,
2381 },
2382 /* BIT 2: IG_SPIV */
2383 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2384 /* BIT 3: SPI2F */
2385 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2386 /* BIT 4: SPI2SDI */
2387 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2388 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2389};
2390
Takashi Iwaiee423812005-11-17 14:21:36 +01002391static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002393 /* shared Line-In */
2394 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2395 is_shared_linein(ac97) ? (1 << 10) : 0);
2396 /* shared Mic */
2397 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2398 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
Takashi Iwaiee423812005-11-17 14:21:36 +01002401static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002402 AC97_SURROUND_JACK_MODE_CTL,
2403 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404};
2405
Takashi Iwaiee423812005-11-17 14:21:36 +01002406static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407{
2408 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2409}
2410
Takashi Iwaiee423812005-11-17 14:21:36 +01002411static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412{
2413 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2414}
2415
2416static struct snd_ac97_build_ops patch_cm9739_ops = {
2417 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002418 .build_post_spdif = patch_cm9739_post_spdif,
2419 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420};
2421
Takashi Iwaiee423812005-11-17 14:21:36 +01002422int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
2424 unsigned short val;
2425
2426 ac97->build_ops = &patch_cm9739_ops;
2427
2428 /* CM9739/A has no Master and PCM volume although the register reacts */
2429 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2430 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2431 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2432
2433 /* check spdif */
2434 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2435 if (val & AC97_EA_SPCV) {
2436 /* enable spdif in */
2437 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2438 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2439 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2440 } else {
2441 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2442 ac97->rates[AC97_RATES_SPDIF] = 0;
2443 }
2444
2445 /* set-up multi channel */
2446 /* bit 14: 0 = SPDIF, 1 = EAPD */
2447 /* bit 13: enable internal vref output for mic */
2448 /* bit 12: disable center/lfe (swithable) */
2449 /* bit 10: disable surround/line (switchable) */
2450 /* bit 9: mix 2 surround off */
2451 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2452 /* bit 3: undocumented; surround? */
2453 /* bit 0: dB */
2454 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2455 val |= (1 << 3);
2456 val |= (1 << 13);
2457 if (! (ac97->ext_id & AC97_EI_SPDIF))
2458 val |= (1 << 14);
2459 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2460
2461 /* FIXME: set up GPIO */
2462 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2463 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2464 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2465 if (ac97->pci &&
2466 ac97->subsystem_vendor == 0x1043 &&
2467 ac97->subsystem_device == 0x1843) {
2468 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2469 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2470 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2471 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2472 }
2473
2474 return 0;
2475}
2476
2477#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002478#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479#define AC97_CM9761_SPDIF_CTRL 0x6c
2480
Takashi Iwaiee423812005-11-17 14:21:36 +01002481static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002483 /* FIXME: check the bits for each model
2484 * model 83 is confirmed to work
2485 */
2486 static unsigned short surr_on[3][2] = {
2487 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2488 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2489 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002491 static unsigned short clfe_on[3][2] = {
2492 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2493 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2494 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002496 static unsigned short surr_shared[3][2] = {
2497 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2498 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2499 { 0x0000, 0x0400 }, /* 9761-83 */
2500 };
2501 static unsigned short clfe_shared[3][2] = {
2502 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2503 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2504 { 0x2000, 0x0800 }, /* 9761-83 */
2505 };
2506 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002507
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002508 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2509 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2510 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2511 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2512
2513 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514}
2515
Takashi Iwaiee423812005-11-17 14:21:36 +01002516static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002517 AC97_SURROUND_JACK_MODE_CTL,
2518 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519};
2520
Takashi Iwaiee423812005-11-17 14:21:36 +01002521static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002522{
2523 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2524
2525 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2526 uinfo->count = 1;
2527 uinfo->value.enumerated.items = 3;
2528 if (uinfo->value.enumerated.item > 2)
2529 uinfo->value.enumerated.item = 2;
2530 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2531 return 0;
2532}
2533
Takashi Iwaiee423812005-11-17 14:21:36 +01002534static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002535{
Takashi Iwaiee423812005-11-17 14:21:36 +01002536 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002537
2538 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2539 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2540 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2541 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2542 else
2543 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2544 return 0;
2545}
2546
Takashi Iwaiee423812005-11-17 14:21:36 +01002547static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002548{
Takashi Iwaiee423812005-11-17 14:21:36 +01002549 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002550
2551 if (ucontrol->value.enumerated.item[0] == 2)
2552 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2553 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2554 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2555 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2556}
2557
2558static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2559static const struct ac97_enum cm9761_dac_clock_enum =
2560 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2561
Takashi Iwaiee423812005-11-17 14:21:36 +01002562static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002563 { /* BIT 1: SPDIFS */
2564 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2565 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2566 .info = cm9761_spdif_out_source_info,
2567 .get = cm9761_spdif_out_source_get,
2568 .put = cm9761_spdif_out_source_put,
2569 },
2570 /* BIT 2: IG_SPIV */
2571 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2572 /* BIT 3: SPI2F */
2573 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2574 /* BIT 4: SPI2SDI */
2575 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2576 /* BIT 9-10: DAC_CTL */
2577 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2578};
2579
Takashi Iwaiee423812005-11-17 14:21:36 +01002580static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002581{
2582 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2583}
2584
Takashi Iwaiee423812005-11-17 14:21:36 +01002585static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586{
2587 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2588}
2589
2590static struct snd_ac97_build_ops patch_cm9761_ops = {
2591 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002592 .build_post_spdif = patch_cm9761_post_spdif,
2593 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594};
2595
Takashi Iwaiee423812005-11-17 14:21:36 +01002596int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
2598 unsigned short val;
2599
2600 /* CM9761 has no PCM volume although the register reacts */
2601 /* Master volume seems to have _some_ influence on the analog
2602 * input sounds
2603 */
2604 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2605 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2606 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2607
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002608 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 if (ac97->id == AC97_ID_CM9761_82) {
2610 unsigned short tmp;
2611 /* check page 1, reg 0x60 */
2612 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2613 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2614 tmp = snd_ac97_read(ac97, 0x60);
2615 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2616 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002617 } else if (ac97->id == AC97_ID_CM9761_83)
2618 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
2620 ac97->build_ops = &patch_cm9761_ops;
2621
2622 /* enable spdif */
2623 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2624 ac97->ext_id |= AC97_EI_SPDIF;
2625 /* to be sure: we overwrite the ext status bits */
2626 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2627 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002628 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2630
2631 /* set-up multi channel */
2632 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002633 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002635 * bit 12: CLFE control (reverted on rev B)
2636 * bit 11: Mic/center share (reverted on rev B)
2637 * bit 10: suddound/line share
2638 * bit 9: Analog-in mix -> surround
2639 * bit 8: Analog-in mix -> CLFE
2640 * bit 7: Mic/LFE share (mic/center/lfe)
2641 * bit 5: vref select (9761A)
2642 * bit 4: front control
2643 * bit 3: surround control (revereted with rev B)
2644 * bit 2: front mic
2645 * bit 1: stereo mic
2646 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 */
2648
2649#if 0
2650 if (ac97->spec.dev_flags)
2651 val = 0x0214;
2652 else
2653 val = 0x321c;
2654#endif
2655 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2656 val |= (1 << 4); /* front on */
2657 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2658
2659 /* FIXME: set up GPIO */
2660 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2661 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2662
2663 return 0;
2664}
2665
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002666#define AC97_CM9780_SIDE 0x60
2667#define AC97_CM9780_JACK 0x62
2668#define AC97_CM9780_MIXER 0x64
2669#define AC97_CM9780_MULTI_CHAN 0x66
2670#define AC97_CM9780_SPDIF 0x6c
2671
2672static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2673static const struct ac97_enum cm9780_ch_select_enum =
2674 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01002675static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002676 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2677 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2678 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2679};
2680
Takashi Iwaiee423812005-11-17 14:21:36 +01002681static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002682{
2683 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2684}
2685
2686static struct snd_ac97_build_ops patch_cm9780_ops = {
2687 .build_specific = patch_cm9780_specific,
2688 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2689};
2690
Takashi Iwaiee423812005-11-17 14:21:36 +01002691int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002692{
2693 unsigned short val;
2694
2695 ac97->build_ops = &patch_cm9780_ops;
2696
2697 /* enable spdif */
2698 if (ac97->ext_id & AC97_EI_SPDIF) {
2699 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2700 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2701 val |= 0x1; /* SPDI_EN */
2702 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2703 }
2704
2705 return 0;
2706}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
2708/*
2709 * VIA VT1616 codec
2710 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002711static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2713AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2714AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2715AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2716};
2717
Takashi Iwaiee423812005-11-17 14:21:36 +01002718static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719{
2720 int err;
2721
2722 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2723 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2724 return err;
2725 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2726 return err;
2727 return 0;
2728}
2729
2730static struct snd_ac97_build_ops patch_vt1616_ops = {
2731 .build_specific = patch_vt1616_specific
2732};
2733
Takashi Iwaiee423812005-11-17 14:21:36 +01002734int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735{
2736 ac97->build_ops = &patch_vt1616_ops;
2737 return 0;
2738}
2739
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002740/*
Philip Prindeville4b499482005-08-12 16:46:17 +02002741 * VT1617A codec
2742 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002743int patch_vt1617a(struct snd_ac97 * ac97)
Philip Prindeville4b499482005-08-12 16:46:17 +02002744{
2745 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2746 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2747 return 0;
2748}
2749
2750/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002751 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002752static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002753{
2754 /* shared Line-In */
2755 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2756 is_shared_linein(ac97) ? (1<<9) : 0);
2757 /* shared Mic */
2758 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2759 is_shared_micin(ac97) ? (1<<10) : 0);
2760}
2761
Takashi Iwaiee423812005-11-17 14:21:36 +01002762static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002763 AC97_SURROUND_JACK_MODE_CTL,
2764 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765};
2766
Takashi Iwaiee423812005-11-17 14:21:36 +01002767static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002768 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2770 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2771};
2772
Takashi Iwaiee423812005-11-17 14:21:36 +01002773static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774{
2775 int err;
2776 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2777 return err;
2778 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2779 return err;
2780 return 0;
2781}
2782
2783static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002784 .build_specific = patch_it2646_specific,
2785 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786};
2787
Takashi Iwaiee423812005-11-17 14:21:36 +01002788int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789{
2790 ac97->build_ops = &patch_it2646_ops;
2791 /* full DAC volume */
2792 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2793 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2794 return 0;
2795}
2796
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002797/*
2798 * Si3036 codec
2799 */
2800
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002802#define AC97_SI3036_LINE_CFG 0x5c
2803
Takashi Iwaiee423812005-11-17 14:21:36 +01002804static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002805AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2806};
2807
Takashi Iwaiee423812005-11-17 14:21:36 +01002808static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002809{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02002810 int idx, err;
2811 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2812 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2813 return err;
2814 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002815}
2816
2817static struct snd_ac97_build_ops patch_si3036_ops = {
2818 .build_specific = patch_si3036_specific,
2819};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
Takashi Iwaiee423812005-11-17 14:21:36 +01002821int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002823 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2825 snd_ac97_write_cache(ac97, 0x68, 0);
2826 return 0;
2827}
Charl Coetzeeba224292006-02-09 11:48:21 +01002828
2829/*
2830 * LM 4550 Codec
2831 *
2832 * We use a static resolution table since LM4550 codec cannot be
2833 * properly autoprobed to determine the resolution via
2834 * check_volume_resolution().
2835 */
2836
2837static struct snd_ac97_res_table lm4550_restbl[] = {
2838 { AC97_MASTER, 0x1f1f },
2839 { AC97_HEADPHONE, 0x1f1f },
2840 { AC97_MASTER_MONO, 0x001f },
2841 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2842 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01002843 { AC97_MIC, 0x001f },
2844 { AC97_LINE, 0x1f1f },
2845 { AC97_CD, 0x1f1f },
2846 { AC97_VIDEO, 0x1f1f },
2847 { AC97_AUX, 0x1f1f },
2848 { AC97_PCM, 0x1f1f },
2849 { AC97_REC_GAIN, 0x0f0f },
2850 { } /* terminator */
2851};
2852
2853int patch_lm4550(struct snd_ac97 *ac97)
2854{
2855 ac97->res_table = lm4550_restbl;
2856 return 0;
2857}