blob: 720b419e0c63d219c0c06a7ab529f217efd3ea35 [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),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100566AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200567
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),
James Courtier-Duttond7f6f112006-04-11 21:47:27 +0100656AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
Liam Girdwood3998b702005-07-29 11:41:55 +0200657AC97_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 */
Takashi Iwaieed65642006-05-02 18:22:06 +02002051 if (ac97->spec.dev_flags &&
2052 /* ASUS A6KM requires EAPD */
2053 ! (ac97->subsystem_vendor == 0x1043 &&
2054 ac97->subsystem_device == 0x1103))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 val |= 0x03; /* enable */
2056 else
2057 val &= ~0x03; /* disable */
2058 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2059
2060 /* set default: slot 3,4,7,8,6,9
2061 spdif-in monitor off, analog-spdif off, spdif-in off
2062 center on mic off, surround on line-in off
2063 downmix off, duplicate front off
2064 */
2065 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2066
2067 /* set GPIO0 for mic bias */
2068 /* GPIO0 pin output, no interrupt, high */
2069 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2070 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2071 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2072 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2073
2074 /* full DAC volume */
2075 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2076 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2077 return 0;
2078}
2079
Takashi Iwaiee423812005-11-17 14:21:36 +01002080static void alc655_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002082 int shared;
2083
2084 /* shared Line-In */
2085 shared = is_shared_linein(ac97);
2086 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2087 shared ? (1 << 9) : 0, 0);
2088 /* update shared mic */
2089 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 /* misc control; vrefout disable */
2091 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002092 shared ? (1 << 12) : 0);
2093 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2094 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
Takashi Iwaiee423812005-11-17 14:21:36 +01002097static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002099 AC97_SURROUND_JACK_MODE_CTL,
2100 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101};
2102
Takashi Iwaiee423812005-11-17 14:21:36 +01002103static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
2105 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2106 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
Takashi Iwaiee423812005-11-17 14:21:36 +01002107 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2110 uinfo->count = 1;
2111 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2112 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2113 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2114 strcpy(uinfo->value.enumerated.name,
2115 ac97->spec.dev_flags ?
2116 texts_658[uinfo->value.enumerated.item] :
2117 texts_655[uinfo->value.enumerated.item]);
2118 return 0;
2119}
2120
Takashi Iwaiee423812005-11-17 14:21:36 +01002121static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Takashi Iwaiee423812005-11-17 14:21:36 +01002123 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 unsigned short val;
2125
2126 val = ac97->regs[AC97_ALC650_MULTICH];
2127 val = (val >> 12) & 3;
2128 if (ac97->spec.dev_flags && val == 3)
2129 val = 0;
2130 ucontrol->value.enumerated.item[0] = val;
2131 return 0;
2132}
2133
Takashi Iwaiee423812005-11-17 14:21:36 +01002134static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135{
Takashi Iwaiee423812005-11-17 14:21:36 +01002136 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2139 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2140 0);
2141}
2142
Takashi Iwaiee423812005-11-17 14:21:36 +01002143static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002144 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 /* disable this controls since it doesn't work as expected */
2146 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2147 {
2148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai031c95d2005-12-05 20:51:43 +01002149 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 .info = alc655_iec958_route_info,
2151 .get = alc655_iec958_route_get,
2152 .put = alc655_iec958_route_put,
2153 },
2154};
2155
Takashi Iwaiee423812005-11-17 14:21:36 +01002156static int patch_alc655_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
2158 int err;
2159
2160 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2161 return err;
2162 if (ac97->ext_id & AC97_EI_SPDIF) {
2163 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2164 return err;
2165 }
2166 return 0;
2167}
2168
2169static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002170 .build_specific = patch_alc655_specific,
2171 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172};
2173
Takashi Iwaiee423812005-11-17 14:21:36 +01002174int patch_alc655(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
2176 unsigned int val;
2177
Takashi Iwaia5022b02005-09-02 14:03:05 +02002178 if (ac97->id == AC97_ID_ALC658) {
2179 ac97->spec.dev_flags = 1; /* ALC658 */
2180 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2181 ac97->id = AC97_ID_ALC658D;
2182 ac97->spec.dev_flags = 2;
2183 }
2184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
2186 ac97->build_ops = &patch_alc655_ops;
2187
2188 /* assume only page 0 for writing cache */
2189 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2190
2191 /* adjust default values */
2192 val = snd_ac97_read(ac97, 0x7a); /* misc control */
Takashi Iwaia5022b02005-09-02 14:03:05 +02002193 if (ac97->spec.dev_flags) /* ALC658 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
Takashi Iwaiee71508e2005-08-31 17:31:07 +02002195 else { /* ALC655 */
2196 if (ac97->subsystem_vendor == 0x1462 &&
2197 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */
2198 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2199 else
2200 val |= (1 << 1); /* Pin 47 is spdif input pin */
2201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 val &= ~(1 << 12); /* vref enable */
2203 snd_ac97_write_cache(ac97, 0x7a, val);
2204 /* set default: spdif-in enabled,
2205 spdif-in monitor off, spdif-in PCM off
2206 center on mic off, surround on line-in off
2207 duplicate front off
2208 */
2209 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2210
2211 /* full DAC volume */
2212 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2213 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
Takashi Iwaia5022b02005-09-02 14:03:05 +02002214
2215 /* update undocumented bit... */
2216 if (ac97->id == AC97_ID_ALC658D)
2217 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2218
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 return 0;
2220}
2221
2222
2223#define AC97_ALC850_JACK_SELECT 0x76
2224#define AC97_ALC850_MISC1 0x7a
2225
Takashi Iwaiee423812005-11-17 14:21:36 +01002226static void alc850_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002228 int shared;
2229
2230 /* shared Line-In */
2231 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 /* SURR 1kOhm (bit4), Amp (bit5) */
2233 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002234 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002236 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2237 shared ? (2<<12) : (0<<12));
2238 /* update shared mic */
2239 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 /* Vref disable (bit12), 1kOhm (bit13) */
2241 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002242 shared ? (1<<12) : (1<<13));
Takashi Iwaida79e442006-01-12 11:45:51 +01002243 /* MIC-IN = 1, CENTER-LFE = 5 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002244 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
Takashi Iwaida79e442006-01-12 11:45:51 +01002245 shared ? (5<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
Takashi Iwaiee423812005-11-17 14:21:36 +01002248static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002250 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002251 AC97_SURROUND_JACK_MODE_CTL,
2252 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253};
2254
Takashi Iwaiee423812005-11-17 14:21:36 +01002255static int patch_alc850_specific(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 int err;
2258
2259 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2260 return err;
2261 if (ac97->ext_id & AC97_EI_SPDIF) {
2262 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2263 return err;
2264 }
2265 return 0;
2266}
2267
2268static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002269 .build_specific = patch_alc850_specific,
2270 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271};
2272
Takashi Iwaiee423812005-11-17 14:21:36 +01002273int patch_alc850(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
2275 ac97->build_ops = &patch_alc850_ops;
2276
2277 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2278
2279 /* assume only page 0 for writing cache */
2280 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2281
2282 /* adjust default values */
2283 /* set default: spdif-in enabled,
2284 spdif-in monitor off, spdif-in PCM off
2285 center on mic off, surround on line-in off
2286 duplicate front off
2287 */
2288 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2289 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2290 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2291 */
2292 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2293 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2294 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2295 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2296 */
2297 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2298 (1<<11)|(0<<12)|(1<<15));
2299
2300 /* full DAC volume */
2301 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2302 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2303 return 0;
2304}
2305
2306
2307/*
2308 * C-Media CM97xx codecs
2309 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002310static void cm9738_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002311{
2312 /* shared Line-In */
2313 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2314 is_shared_linein(ac97) ? (1 << 10) : 0);
2315}
2316
Takashi Iwaiee423812005-11-17 14:21:36 +01002317static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002319 AC97_SURROUND_JACK_MODE_CTL,
2320 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321};
2322
Takashi Iwaiee423812005-11-17 14:21:36 +01002323static int patch_cm9738_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
2325 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2326}
2327
2328static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002329 .build_specific = patch_cm9738_specific,
2330 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331};
2332
Takashi Iwaiee423812005-11-17 14:21:36 +01002333int patch_cm9738(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
2335 ac97->build_ops = &patch_cm9738_ops;
2336 /* FIXME: can anyone confirm below? */
2337 /* CM9738 has no PCM volume although the register reacts */
2338 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2339 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2340
2341 return 0;
2342}
2343
Takashi Iwaiee423812005-11-17 14:21:36 +01002344static 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 -07002345{
2346 static char *texts[] = { "Analog", "Digital" };
2347
2348 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2349 uinfo->count = 1;
2350 uinfo->value.enumerated.items = 2;
2351 if (uinfo->value.enumerated.item > 1)
2352 uinfo->value.enumerated.item = 1;
2353 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2354 return 0;
2355}
2356
Takashi Iwaiee423812005-11-17 14:21:36 +01002357static 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 -07002358{
Takashi Iwaiee423812005-11-17 14:21:36 +01002359 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 unsigned short val;
2361
2362 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2363 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2364 return 0;
2365}
2366
Takashi Iwaiee423812005-11-17 14:21:36 +01002367static 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 -07002368{
Takashi Iwaiee423812005-11-17 14:21:36 +01002369 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
2371 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2372 0x01 << 1,
2373 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2374}
2375
Takashi Iwaiee423812005-11-17 14:21:36 +01002376static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 /* BIT 0: SPDI_EN - always true */
2378 { /* BIT 1: SPDIFS */
2379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2380 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2381 .info = snd_ac97_cmedia_spdif_playback_source_info,
2382 .get = snd_ac97_cmedia_spdif_playback_source_get,
2383 .put = snd_ac97_cmedia_spdif_playback_source_put,
2384 },
2385 /* BIT 2: IG_SPIV */
2386 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2387 /* BIT 3: SPI2F */
2388 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2389 /* BIT 4: SPI2SDI */
2390 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2391 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2392};
2393
Takashi Iwaiee423812005-11-17 14:21:36 +01002394static void cm9739_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002396 /* shared Line-In */
2397 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2398 is_shared_linein(ac97) ? (1 << 10) : 0);
2399 /* shared Mic */
2400 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2401 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
Takashi Iwaiee423812005-11-17 14:21:36 +01002404static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002405 AC97_SURROUND_JACK_MODE_CTL,
2406 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407};
2408
Takashi Iwaiee423812005-11-17 14:21:36 +01002409static int patch_cm9739_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
2411 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2412}
2413
Takashi Iwaiee423812005-11-17 14:21:36 +01002414static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
2416 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2417}
2418
2419static struct snd_ac97_build_ops patch_cm9739_ops = {
2420 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002421 .build_post_spdif = patch_cm9739_post_spdif,
2422 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423};
2424
Takashi Iwaiee423812005-11-17 14:21:36 +01002425int patch_cm9739(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
2427 unsigned short val;
2428
2429 ac97->build_ops = &patch_cm9739_ops;
2430
2431 /* CM9739/A has no Master and PCM volume although the register reacts */
2432 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2433 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2434 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2435
2436 /* check spdif */
2437 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2438 if (val & AC97_EA_SPCV) {
2439 /* enable spdif in */
2440 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2441 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2442 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2443 } else {
2444 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2445 ac97->rates[AC97_RATES_SPDIF] = 0;
2446 }
2447
2448 /* set-up multi channel */
2449 /* bit 14: 0 = SPDIF, 1 = EAPD */
2450 /* bit 13: enable internal vref output for mic */
2451 /* bit 12: disable center/lfe (swithable) */
2452 /* bit 10: disable surround/line (switchable) */
2453 /* bit 9: mix 2 surround off */
2454 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2455 /* bit 3: undocumented; surround? */
2456 /* bit 0: dB */
2457 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2458 val |= (1 << 3);
2459 val |= (1 << 13);
2460 if (! (ac97->ext_id & AC97_EI_SPDIF))
2461 val |= (1 << 14);
2462 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2463
2464 /* FIXME: set up GPIO */
2465 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2466 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2467 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2468 if (ac97->pci &&
2469 ac97->subsystem_vendor == 0x1043 &&
2470 ac97->subsystem_device == 0x1843) {
2471 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2472 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2473 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2474 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2475 }
2476
2477 return 0;
2478}
2479
2480#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002481#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482#define AC97_CM9761_SPDIF_CTRL 0x6c
2483
Takashi Iwaiee423812005-11-17 14:21:36 +01002484static void cm9761_update_jacks(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002486 /* FIXME: check the bits for each model
2487 * model 83 is confirmed to work
2488 */
2489 static unsigned short surr_on[3][2] = {
2490 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2491 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2492 { 0x0000, 0x0008 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002494 static unsigned short clfe_on[3][2] = {
2495 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2496 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2497 { 0x0000, 0x1000 }, /* 9761-83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 };
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002499 static unsigned short surr_shared[3][2] = {
2500 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2501 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2502 { 0x0000, 0x0400 }, /* 9761-83 */
2503 };
2504 static unsigned short clfe_shared[3][2] = {
2505 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2506 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2507 { 0x2000, 0x0800 }, /* 9761-83 */
2508 };
2509 unsigned short val = 0;
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002510
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002511 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2512 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2513 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2514 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2515
2516 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
Takashi Iwaiee423812005-11-17 14:21:36 +01002519static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002520 AC97_SURROUND_JACK_MODE_CTL,
2521 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522};
2523
Takashi Iwaiee423812005-11-17 14:21:36 +01002524static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002525{
2526 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2527
2528 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2529 uinfo->count = 1;
2530 uinfo->value.enumerated.items = 3;
2531 if (uinfo->value.enumerated.item > 2)
2532 uinfo->value.enumerated.item = 2;
2533 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2534 return 0;
2535}
2536
Takashi Iwaiee423812005-11-17 14:21:36 +01002537static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002538{
Takashi Iwaiee423812005-11-17 14:21:36 +01002539 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002540
2541 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2542 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2543 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2544 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2545 else
2546 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2547 return 0;
2548}
2549
Takashi Iwaiee423812005-11-17 14:21:36 +01002550static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002551{
Takashi Iwaiee423812005-11-17 14:21:36 +01002552 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002553
2554 if (ucontrol->value.enumerated.item[0] == 2)
2555 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2556 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2557 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2558 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2559}
2560
2561static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2562static const struct ac97_enum cm9761_dac_clock_enum =
2563 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2564
Takashi Iwaiee423812005-11-17 14:21:36 +01002565static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002566 { /* BIT 1: SPDIFS */
2567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2568 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2569 .info = cm9761_spdif_out_source_info,
2570 .get = cm9761_spdif_out_source_get,
2571 .put = cm9761_spdif_out_source_put,
2572 },
2573 /* BIT 2: IG_SPIV */
2574 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2575 /* BIT 3: SPI2F */
2576 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2577 /* BIT 4: SPI2SDI */
2578 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2579 /* BIT 9-10: DAC_CTL */
2580 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2581};
2582
Takashi Iwaiee423812005-11-17 14:21:36 +01002583static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002584{
2585 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2586}
2587
Takashi Iwaiee423812005-11-17 14:21:36 +01002588static int patch_cm9761_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
2590 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2591}
2592
2593static struct snd_ac97_build_ops patch_cm9761_ops = {
2594 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002595 .build_post_spdif = patch_cm9761_post_spdif,
2596 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597};
2598
Takashi Iwaiee423812005-11-17 14:21:36 +01002599int patch_cm9761(struct snd_ac97 *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
2601 unsigned short val;
2602
2603 /* CM9761 has no PCM volume although the register reacts */
2604 /* Master volume seems to have _some_ influence on the analog
2605 * input sounds
2606 */
2607 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2608 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2609 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2610
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002611 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 if (ac97->id == AC97_ID_CM9761_82) {
2613 unsigned short tmp;
2614 /* check page 1, reg 0x60 */
2615 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2616 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2617 tmp = snd_ac97_read(ac97, 0x60);
2618 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2619 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
Takashi Iwai4525c9f2005-09-13 11:47:07 +02002620 } else if (ac97->id == AC97_ID_CM9761_83)
2621 ac97->spec.dev_flags = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
2623 ac97->build_ops = &patch_cm9761_ops;
2624
2625 /* enable spdif */
2626 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2627 ac97->ext_id |= AC97_EI_SPDIF;
2628 /* to be sure: we overwrite the ext status bits */
2629 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2630 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002631 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2633
2634 /* set-up multi channel */
2635 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002636 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002638 * bit 12: CLFE control (reverted on rev B)
2639 * bit 11: Mic/center share (reverted on rev B)
2640 * bit 10: suddound/line share
2641 * bit 9: Analog-in mix -> surround
2642 * bit 8: Analog-in mix -> CLFE
2643 * bit 7: Mic/LFE share (mic/center/lfe)
2644 * bit 5: vref select (9761A)
2645 * bit 4: front control
2646 * bit 3: surround control (revereted with rev B)
2647 * bit 2: front mic
2648 * bit 1: stereo mic
2649 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 */
2651
2652#if 0
2653 if (ac97->spec.dev_flags)
2654 val = 0x0214;
2655 else
2656 val = 0x321c;
2657#endif
2658 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2659 val |= (1 << 4); /* front on */
2660 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2661
2662 /* FIXME: set up GPIO */
2663 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2664 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2665
2666 return 0;
2667}
2668
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002669#define AC97_CM9780_SIDE 0x60
2670#define AC97_CM9780_JACK 0x62
2671#define AC97_CM9780_MIXER 0x64
2672#define AC97_CM9780_MULTI_CHAN 0x66
2673#define AC97_CM9780_SPDIF 0x6c
2674
2675static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2676static const struct ac97_enum cm9780_ch_select_enum =
2677 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
Takashi Iwaiee423812005-11-17 14:21:36 +01002678static const struct snd_kcontrol_new cm9780_controls[] = {
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002679 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2680 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2681 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2682};
2683
Takashi Iwaiee423812005-11-17 14:21:36 +01002684static int patch_cm9780_specific(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002685{
2686 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2687}
2688
2689static struct snd_ac97_build_ops patch_cm9780_ops = {
2690 .build_specific = patch_cm9780_specific,
2691 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2692};
2693
Takashi Iwaiee423812005-11-17 14:21:36 +01002694int patch_cm9780(struct snd_ac97 *ac97)
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002695{
2696 unsigned short val;
2697
2698 ac97->build_ops = &patch_cm9780_ops;
2699
2700 /* enable spdif */
2701 if (ac97->ext_id & AC97_EI_SPDIF) {
2702 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2703 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2704 val |= 0x1; /* SPDI_EN */
2705 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2706 }
2707
2708 return 0;
2709}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711/*
2712 * VIA VT1616 codec
2713 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002714static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2716AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2717AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2718AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2719};
2720
Takashi Iwaiee423812005-11-17 14:21:36 +01002721static int patch_vt1616_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722{
2723 int err;
2724
2725 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2726 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2727 return err;
2728 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2729 return err;
2730 return 0;
2731}
2732
2733static struct snd_ac97_build_ops patch_vt1616_ops = {
2734 .build_specific = patch_vt1616_specific
2735};
2736
Takashi Iwaiee423812005-11-17 14:21:36 +01002737int patch_vt1616(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738{
2739 ac97->build_ops = &patch_vt1616_ops;
2740 return 0;
2741}
2742
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002743/*
Philip Prindeville4b499482005-08-12 16:46:17 +02002744 * VT1617A codec
2745 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002746int patch_vt1617a(struct snd_ac97 * ac97)
Philip Prindeville4b499482005-08-12 16:46:17 +02002747{
2748 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2749 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2750 return 0;
2751}
2752
2753/*
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002754 */
Takashi Iwaiee423812005-11-17 14:21:36 +01002755static void it2646_update_jacks(struct snd_ac97 *ac97)
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002756{
2757 /* shared Line-In */
2758 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2759 is_shared_linein(ac97) ? (1<<9) : 0);
2760 /* shared Mic */
2761 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2762 is_shared_micin(ac97) ? (1<<10) : 0);
2763}
2764
Takashi Iwaiee423812005-11-17 14:21:36 +01002765static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002766 AC97_SURROUND_JACK_MODE_CTL,
2767 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768};
2769
Takashi Iwaiee423812005-11-17 14:21:36 +01002770static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002771 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2773 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2774};
2775
Takashi Iwaiee423812005-11-17 14:21:36 +01002776static int patch_it2646_specific(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777{
2778 int err;
2779 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2780 return err;
2781 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2782 return err;
2783 return 0;
2784}
2785
2786static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002787 .build_specific = patch_it2646_specific,
2788 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789};
2790
Takashi Iwaiee423812005-11-17 14:21:36 +01002791int patch_it2646(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792{
2793 ac97->build_ops = &patch_it2646_ops;
2794 /* full DAC volume */
2795 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2796 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2797 return 0;
2798}
2799
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002800/*
2801 * Si3036 codec
2802 */
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002805#define AC97_SI3036_LINE_CFG 0x5c
2806
Takashi Iwaiee423812005-11-17 14:21:36 +01002807static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002808AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2809};
2810
Takashi Iwaiee423812005-11-17 14:21:36 +01002811static int patch_si3036_specific(struct snd_ac97 * ac97)
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002812{
Sasha Khapyorsky27bcaa62005-09-13 11:23:13 +02002813 int idx, err;
2814 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2815 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2816 return err;
2817 return 0;
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002818}
2819
2820static struct snd_ac97_build_ops patch_si3036_ops = {
2821 .build_specific = patch_si3036_specific,
2822};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
Takashi Iwaiee423812005-11-17 14:21:36 +01002824int mpatch_si3036(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002826 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2828 snd_ac97_write_cache(ac97, 0x68, 0);
2829 return 0;
2830}
Charl Coetzeeba224292006-02-09 11:48:21 +01002831
2832/*
2833 * LM 4550 Codec
2834 *
2835 * We use a static resolution table since LM4550 codec cannot be
2836 * properly autoprobed to determine the resolution via
2837 * check_volume_resolution().
2838 */
2839
2840static struct snd_ac97_res_table lm4550_restbl[] = {
2841 { AC97_MASTER, 0x1f1f },
2842 { AC97_HEADPHONE, 0x1f1f },
2843 { AC97_MASTER_MONO, 0x001f },
2844 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
2845 { AC97_PHONE, 0x001f },
Charl Coetzeeba224292006-02-09 11:48:21 +01002846 { AC97_MIC, 0x001f },
2847 { AC97_LINE, 0x1f1f },
2848 { AC97_CD, 0x1f1f },
2849 { AC97_VIDEO, 0x1f1f },
2850 { AC97_AUX, 0x1f1f },
2851 { AC97_PCM, 0x1f1f },
2852 { AC97_REC_GAIN, 0x0f0f },
2853 { } /* terminator */
2854};
2855
2856int patch_lm4550(struct snd_ac97 *ac97)
2857{
2858 ac97->res_table = lm4550_restbl;
2859 return 0;
2860}