blob: a51b61d5066b926be9356becbf9634e729002550 [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>
30#include <sound/core.h>
31#include <sound/pcm.h>
32#include <sound/control.h>
33#include <sound/ac97_codec.h>
34#include "ac97_patch.h"
35#include "ac97_id.h"
36#include "ac97_local.h"
37
38/*
39 * Chip specific initialization
40 */
41
42static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count)
43{
44 int idx, err;
45
46 for (idx = 0; idx < count; idx++)
47 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
48 return err;
49 return 0;
50}
51
52/* set to the page, update bits and restore the page */
53static int ac97_update_bits_page(ac97_t *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
54{
55 unsigned short page_save;
56 int ret;
57
58 down(&ac97->page_mutex);
59 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
60 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
61 ret = snd_ac97_update_bits(ac97, reg, mask, value);
62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
63 up(&ac97->page_mutex); /* unlock paging */
64 return ret;
65}
66
Takashi Iwaieb8caf32005-04-13 14:32:57 +020067/*
68 * shared line-in/mic controls
69 */
70static int ac97_enum_text_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo,
71 const char **texts, unsigned int nums)
72{
73 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
74 uinfo->count = 1;
75 uinfo->value.enumerated.items = nums;
76 if (uinfo->value.enumerated.item > nums - 1)
77 uinfo->value.enumerated.item = nums - 1;
78 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
79 return 0;
80}
81
82static int ac97_surround_jack_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
83{
84 static const char *texts[] = { "Shared", "Independent" };
85 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
86}
87
88static int ac97_surround_jack_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
89{
90 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
91
92 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
93 return 0;
94}
95
96static int ac97_surround_jack_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
97{
98 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
99 unsigned char indep = !!ucontrol->value.enumerated.item[0];
100
101 if (indep != ac97->indep_surround) {
102 ac97->indep_surround = indep;
103 if (ac97->build_ops->update_jacks)
104 ac97->build_ops->update_jacks(ac97);
105 return 1;
106 }
107 return 0;
108}
109
110static int ac97_channel_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
111{
112 static const char *texts[] = { "2ch", "4ch", "6ch" };
113 if (kcontrol->private_value)
114 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
115 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
116}
117
118static int ac97_channel_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
119{
120 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
121
122 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
123 return 0;
124}
125
126static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
127{
128 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
129 unsigned char mode = ucontrol->value.enumerated.item[0];
130
131 if (mode != ac97->channel_mode) {
132 ac97->channel_mode = mode;
133 if (ac97->build_ops->update_jacks)
134 ac97->build_ops->update_jacks(ac97);
135 return 1;
136 }
137 return 0;
138}
139
140#define AC97_SURROUND_JACK_MODE_CTL \
141 { \
142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
143 .name = "Surround Jack Mode", \
144 .info = ac97_surround_jack_mode_info, \
145 .get = ac97_surround_jack_mode_get, \
146 .put = ac97_surround_jack_mode_put, \
147 }
148#define AC97_CHANNEL_MODE_CTL \
149 { \
150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
151 .name = "Channel Mode", \
152 .info = ac97_channel_mode_info, \
153 .get = ac97_channel_mode_get, \
154 .put = ac97_channel_mode_put, \
155 }
156#define AC97_CHANNEL_MODE_4CH_CTL \
157 { \
158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
159 .name = "Channel Mode", \
160 .info = ac97_channel_mode_info, \
161 .get = ac97_channel_mode_get, \
162 .put = ac97_channel_mode_put, \
163 .private_value = 1, \
164 }
165
166static inline int is_shared_linein(ac97_t *ac97)
167{
168 return ! ac97->indep_surround && ac97->channel_mode >= 1;
169}
170
171static inline int is_shared_micin(ac97_t *ac97)
172{
173 return ! ac97->indep_surround && ac97->channel_mode >= 2;
174}
175
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
178
179/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
180static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
181{
182 static char *texts[3] = {
183 "Standard", "Small", "Smaller"
184 };
185
186 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
187 uinfo->count = 1;
188 uinfo->value.enumerated.items = 3;
189 if (uinfo->value.enumerated.item > 2)
190 uinfo->value.enumerated.item = 2;
191 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
192 return 0;
193}
194
195static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
196{
197 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
198 unsigned short val;
199
200 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
201 val = (val >> 10) & 3;
202 if (val > 0) /* 0 = invalid */
203 val--;
204 ucontrol->value.enumerated.item[0] = val;
205 return 0;
206}
207
208static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
209{
210 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
211 unsigned short val;
212
213 if (ucontrol->value.enumerated.item[0] > 2)
214 return -EINVAL;
215 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
216 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
217}
218
219static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
220{
221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
222 .name = "3D Control - Speaker",
223 .info = snd_ac97_ymf753_info_speaker,
224 .get = snd_ac97_ymf753_get_speaker,
225 .put = snd_ac97_ymf753_put_speaker,
226};
227
228/* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
229static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
230{
231 static char *texts[2] = { "AC-Link", "A/D Converter" };
232
233 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
234 uinfo->count = 1;
235 uinfo->value.enumerated.items = 2;
236 if (uinfo->value.enumerated.item > 1)
237 uinfo->value.enumerated.item = 1;
238 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
239 return 0;
240}
241
242static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
243{
244 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
245 unsigned short val;
246
247 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
248 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
249 return 0;
250}
251
252static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
253{
254 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
255 unsigned short val;
256
257 if (ucontrol->value.enumerated.item[0] > 1)
258 return -EINVAL;
259 val = ucontrol->value.enumerated.item[0] << 1;
260 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
261}
262
263/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
264 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
265 By default, no output pin is selected, and the S/PDIF signal is not output.
266 There is also a bit to mute S/PDIF output in a vendor-specific register. */
267static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
268{
269 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
270
271 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
272 uinfo->count = 1;
273 uinfo->value.enumerated.items = 3;
274 if (uinfo->value.enumerated.item > 2)
275 uinfo->value.enumerated.item = 2;
276 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
277 return 0;
278}
279
280static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
281{
282 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
283 unsigned short val;
284
285 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
286 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
287 return 0;
288}
289
290static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
291{
292 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
293 unsigned short val;
294
295 if (ucontrol->value.enumerated.item[0] > 2)
296 return -EINVAL;
297 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
298 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
299 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
300 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
301 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
302}
303
304static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
305 {
306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
308 .info = snd_ac97_ymf753_spdif_source_info,
309 .get = snd_ac97_ymf753_spdif_source_get,
310 .put = snd_ac97_ymf753_spdif_source_put,
311 },
312 {
313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
314 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
315 .info = snd_ac97_ymf753_spdif_output_pin_info,
316 .get = snd_ac97_ymf753_spdif_output_pin_get,
317 .put = snd_ac97_ymf753_spdif_output_pin_put,
318 },
319 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
320};
321
322static int patch_yamaha_ymf753_3d(ac97_t * ac97)
323{
324 snd_kcontrol_t *kctl;
325 int err;
326
327 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
328 return err;
329 strcpy(kctl->id.name, "3D Control - Wide");
330 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
331 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
332 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
333 return err;
334 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
335 return 0;
336}
337
338static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97)
339{
340 int err;
341
342 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
343 return err;
344 return 0;
345}
346
347static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
348 .build_3d = patch_yamaha_ymf753_3d,
349 .build_post_spdif = patch_yamaha_ymf753_post_spdif
350};
351
352int patch_yamaha_ymf753(ac97_t * ac97)
353{
354 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
355 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
356 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
357 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
358 By default, no output pin is selected, and the S/PDIF signal is not output.
359 There is also a bit to mute S/PDIF output in a vendor-specific register.
360 */
361 ac97->build_ops = &patch_yamaha_ymf753_ops;
362 ac97->caps |= AC97_BC_BASS_TREBLE;
363 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
364 return 0;
365}
366
367/*
368 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
369 * removed broken wolfson00 patch.
370 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
371 */
372
Liam Girdwood3998b702005-07-29 11:41:55 +0200373static const snd_kcontrol_new_t wm97xx_snd_ac97_controls[] = {
374AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
375AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
376};
377
378int patch_wolfson_wm9703_specific(ac97_t * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 /* This is known to work for the ViewSonic ViewPad 1000
Liam Girdwood3998b702005-07-29 11:41:55 +0200381 * Randolph Bentson <bentson@holmsjoen.com>
382 * WM9703/9707/9708/9717
383 */
384 int err, i;
385
386 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
387 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
388 return err;
389 }
390 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return 0;
392}
Liam Girdwood3998b702005-07-29 11:41:55 +0200393
394static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
395 .build_specific = patch_wolfson_wm9703_specific,
396};
397
398int patch_wolfson03(ac97_t * ac97)
399{
400 ac97->build_ops = &patch_wolfson_wm9703_ops;
401 return 0;
402}
403
404static const snd_kcontrol_new_t wm9704_snd_ac97_controls[] = {
405AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
406AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
407AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
408AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
409AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
410AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
411};
412
413int patch_wolfson_wm9704_specific(ac97_t * ac97)
414{
415 int err, i;
416 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
417 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
418 return err;
419 }
420 /* patch for DVD noise */
421 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
422 return 0;
423}
424
425static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
426 .build_specific = patch_wolfson_wm9704_specific,
427};
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429int patch_wolfson04(ac97_t * ac97)
430{
Liam Girdwood3998b702005-07-29 11:41:55 +0200431 /* WM9704M/9704Q */
432 ac97->build_ops = &patch_wolfson_wm9704_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return 0;
434}
Liam Girdwood3998b702005-07-29 11:41:55 +0200435
436int patch_wolfson_wm9705_specific(ac97_t * ac97)
437{
438 int err, i;
439 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
440 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
441 return err;
442 }
443 snd_ac97_write_cache(ac97, 0x72, 0x0808);
444 return 0;
445}
446
447static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
448 .build_specific = patch_wolfson_wm9705_specific,
449};
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451int patch_wolfson05(ac97_t * ac97)
452{
Liam Girdwood3998b702005-07-29 11:41:55 +0200453 /* WM9705, WM9710 */
454 ac97->build_ops = &patch_wolfson_wm9705_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return 0;
456}
457
Liam Girdwood3998b702005-07-29 11:41:55 +0200458static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
459static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
460static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
461static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
462static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
463static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
464static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
465static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
466static const char* wm9711_rec_sel[] =
467 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
468static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
469
470static const struct ac97_enum wm9711_enum[] = {
471AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
472AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
473AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
474AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
475AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
476AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
477AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
478AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
479AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
480AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
481};
482
483static const snd_kcontrol_new_t wm9711_snd_ac97_controls[] = {
484AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
485AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
486AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
487AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
488AC97_ENUM("ALC Function", wm9711_enum[0]),
489AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
490AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
491AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
492AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
493AC97_ENUM("ALC NG Type", wm9711_enum[9]),
494AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
495
496AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
497AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
498AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
499AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
500
501AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
502AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
503AC97_ENUM("Out3 Mux", wm9711_enum[2]),
504AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
505AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
506
507AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
508AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
509AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
510AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
511AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
512AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
513
514AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
515AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
516AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
517AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
518AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
519AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
520
521AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
522AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
523
524AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
525AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
526AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
527
528AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
529AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
530AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
531
532AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
533AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
534AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
535AC97_ENUM("Capture Select", wm9711_enum[8]),
536
537AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
538AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
539
540AC97_ENUM("Bass Control", wm9711_enum[5]),
541AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
542AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
543AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
544
545AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
546AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
547AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
548AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
549
550AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
551AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
552AC97_ENUM("Mic Select Source", wm9711_enum[7]),
553AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
554AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
555
556AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
557AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
558AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
559};
560
561int patch_wolfson_wm9711_specific(ac97_t * ac97)
562{
563 int err, i;
564
565 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
566 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
567 return err;
568 }
569 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
570 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
571 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
572 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
573 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
574 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
575 return 0;
576}
577
578static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
579 .build_specific = patch_wolfson_wm9711_specific,
580};
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582int patch_wolfson11(ac97_t * ac97)
583{
Liam Girdwood3998b702005-07-29 11:41:55 +0200584 /* WM9711, WM9712 */
585 ac97->build_ops = &patch_wolfson_wm9711_ops;
586
587 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
588 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return 0;
591}
592
Liam Girdwood3998b702005-07-29 11:41:55 +0200593static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
Liam Girdwood3998b702005-07-29 11:41:55 +0200595static const char* wm9713_rec_src[] =
596 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
597 "Mono Mix", "Zh"};
598static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
599static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
600static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
601static const char* wm9713_spk_pga[] =
602 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
603static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
604static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
605static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
606static const char* wm9713_dac_inv[] =
607 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
608 "Headphone Mix Mono", "NC", "Vmid"};
609static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
610static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612static const struct ac97_enum wm9713_enum[] = {
613AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
614AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
615AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
Liam Girdwood3998b702005-07-29 11:41:55 +0200616AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
617AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
618AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
619AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
620AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
621AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
622AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
623AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
624AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
625AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
626AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627};
628
Liam Girdwood3998b702005-07-29 11:41:55 +0200629static const snd_kcontrol_new_t wm13_snd_ac97_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
Liam Girdwood3998b702005-07-29 11:41:55 +0200631AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
632AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
633AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
634
635AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
636AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
637AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
638AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
639
640AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
641AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
642AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
643AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
644AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
645AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
646AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
647
648AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
649AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
650AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
651AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
652
653AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
654AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
655AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
656AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
657AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
658AC97_ENUM("Capture Select", wm9713_enum[3]),
659
660AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
661AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
662AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
663AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
664AC97_ENUM("ALC Function", wm9713_enum[5]),
665AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
666AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
667AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
668AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
669AC97_ENUM("ALC NG Type", wm9713_enum[13]),
670AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
671
672AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
673AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
674AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
675AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
676AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
677AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
678
679AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
680AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
681AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
682AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
683AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
684AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
685
686AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
687AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
688AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
689AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
690AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
691AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
692
693AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
694AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
695AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
696AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
697AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
698AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
699
700AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
701AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
702AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
703AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
704AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
705AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
706
707AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
708AC97_ENUM("Master Input Mux", wm9713_enum[7]),
709AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
710AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
711AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
712
713AC97_ENUM("Bass Control", wm9713_enum[12]),
714AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
715AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
716AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
717AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
718AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719};
720
Liam Girdwood3998b702005-07-29 11:41:55 +0200721static const snd_kcontrol_new_t wm13_snd_ac97_controls_3d[] = {
722AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
723AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
724AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
725AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726};
727
Liam Girdwood3998b702005-07-29 11:41:55 +0200728static int patch_wolfson_wm9713_3d (ac97_t * ac97)
729{
730 int err, i;
731
732 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
733 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
734 return err;
735 }
736 return 0;
737}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739static int patch_wolfson_wm9713_specific(ac97_t * ac97)
740{
741 int err, i;
742
Liam Girdwood3998b702005-07-29 11:41:55 +0200743 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
744 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 -0700745 return err;
746 }
747 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
750 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
753 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 return 0;
755}
756
757#ifdef CONFIG_PM
758static void patch_wolfson_wm9713_suspend (ac97_t * ac97)
759{
760 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
761 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
762}
763
764static void patch_wolfson_wm9713_resume (ac97_t * ac97)
765{
766 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
767 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
768 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
769}
770#endif
771
772static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
773 .build_specific = patch_wolfson_wm9713_specific,
Liam Girdwood3998b702005-07-29 11:41:55 +0200774 .build_3d = patch_wolfson_wm9713_3d,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775#ifdef CONFIG_PM
776 .suspend = patch_wolfson_wm9713_suspend,
777 .resume = patch_wolfson_wm9713_resume
778#endif
779};
780
781int patch_wolfson13(ac97_t * ac97)
782{
Liam Girdwood3998b702005-07-29 11:41:55 +0200783 /* WM9713, WM9714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 ac97->build_ops = &patch_wolfson_wm9713_ops;
785
786 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
Liam Girdwood3998b702005-07-29 11:41:55 +0200787 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
788 AC97_HAS_NO_STD_PCM;
Liam Girdwood064d2112005-08-05 10:25:08 +0200789 ac97->scaps &= ~AC97_SCAP_MODEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
792 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
793 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
794
795 return 0;
796}
797
798/*
799 * Tritech codec
800 */
801int patch_tritech_tr28028(ac97_t * ac97)
802{
803 snd_ac97_write_cache(ac97, 0x26, 0x0300);
804 snd_ac97_write_cache(ac97, 0x26, 0x0000);
805 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
806 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
807 return 0;
808}
809
810/*
811 * Sigmatel STAC97xx codecs
812 */
813static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
814{
815 snd_kcontrol_t *kctl;
816 int err;
817
818 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
819 return err;
820 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
821 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
822 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
823 return 0;
824}
825
826static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
827{
828 snd_kcontrol_t *kctl;
829 int err;
830
831 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
832 return err;
833 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
834 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
835 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
836 return err;
837 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
838 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
839 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
840 return 0;
841}
842
843static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
844AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
845
846static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
847AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
848
849static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
850AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
851AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
852};
853
854static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
855{
856 int err;
857
858 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
859 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
860 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
861 return err;
862 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
863 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
864 return err;
865 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
866 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
867 return err;
868 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
869 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
870 return err;
871 return 0;
872}
873
874static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
875 .build_3d = patch_sigmatel_stac9700_3d,
876 .build_specific = patch_sigmatel_stac97xx_specific
877};
878
879int patch_sigmatel_stac9700(ac97_t * ac97)
880{
881 ac97->build_ops = &patch_sigmatel_stac9700_ops;
882 return 0;
883}
884
885static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
886{
887 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
888 int err;
889
890 down(&ac97->page_mutex);
891 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
892 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
893 (ucontrol->value.integer.value[0] & 1) << 4);
894 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
895 up(&ac97->page_mutex);
896 return err;
897}
898
899static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = {
900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
901 .name = "Sigmatel Output Bias Switch",
902 .info = snd_ac97_info_volsw,
903 .get = snd_ac97_get_volsw,
904 .put = snd_ac97_stac9708_put_bias,
905 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
906};
907
908static int patch_sigmatel_stac9708_specific(ac97_t *ac97)
909{
910 int err;
911
912 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
913 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
914 return err;
915 return patch_sigmatel_stac97xx_specific(ac97);
916}
917
918static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
919 .build_3d = patch_sigmatel_stac9708_3d,
920 .build_specific = patch_sigmatel_stac9708_specific
921};
922
923int patch_sigmatel_stac9708(ac97_t * ac97)
924{
925 unsigned int codec72, codec6c;
926
927 ac97->build_ops = &patch_sigmatel_stac9708_ops;
928 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
929
930 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
931 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
932
933 if ((codec72==0) && (codec6c==0)) {
934 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
935 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
936 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
937 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
938 } else if ((codec72==0x8000) && (codec6c==0)) {
939 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
940 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
941 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
942 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
943 /* nothing */
944 }
945 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
946 return 0;
947}
948
949int patch_sigmatel_stac9721(ac97_t * ac97)
950{
951 ac97->build_ops = &patch_sigmatel_stac9700_ops;
952 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
953 // patch for SigmaTel
954 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
955 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
956 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
957 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
958 }
959 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
960 return 0;
961}
962
963int patch_sigmatel_stac9744(ac97_t * ac97)
964{
965 // patch for SigmaTel
966 ac97->build_ops = &patch_sigmatel_stac9700_ops;
967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
968 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
970 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
972 return 0;
973}
974
975int patch_sigmatel_stac9756(ac97_t * ac97)
976{
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
987static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
988{
989 static char *texts[5] = { "Input/Disabled", "Front Output",
990 "Rear Output", "Center/LFE Output", "Mixer Output" };
991
992 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
993 uinfo->count = 1;
994 uinfo->value.enumerated.items = 5;
995 if (uinfo->value.enumerated.item > 4)
996 uinfo->value.enumerated.item = 4;
997 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
998 return 0;
999}
1000
1001static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1002{
1003 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1004 int shift = kcontrol->private_value;
1005 unsigned short val;
1006
1007 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1008 if (!(val & 4))
1009 ucontrol->value.enumerated.item[0] = 0;
1010 else
1011 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1012 return 0;
1013}
1014
1015static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1016{
1017 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1018 int shift = kcontrol->private_value;
1019 unsigned short val;
1020
1021 if (ucontrol->value.enumerated.item[0] > 4)
1022 return -EINVAL;
1023 if (ucontrol->value.enumerated.item[0] == 0)
1024 val = 0;
1025 else
1026 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1027 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1028 7 << shift, val << shift, 0);
1029}
1030
1031static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1032{
1033 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1034 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1035
1036 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1037 uinfo->count = 1;
1038 uinfo->value.enumerated.items = 7;
1039 if (uinfo->value.enumerated.item > 6)
1040 uinfo->value.enumerated.item = 6;
1041 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1042 return 0;
1043}
1044
1045static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1046{
1047 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1048 int shift = kcontrol->private_value;
1049 unsigned short val;
1050
1051 val = ac97->regs[AC97_SIGMATEL_INSEL];
1052 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1053 return 0;
1054}
1055
1056static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1057{
1058 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1059 int shift = kcontrol->private_value;
1060
1061 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1062 ucontrol->value.enumerated.item[0] << shift, 0);
1063}
1064
1065static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1066{
1067 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1068
1069 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1070 uinfo->count = 1;
1071 uinfo->value.enumerated.items = 3;
1072 if (uinfo->value.enumerated.item > 2)
1073 uinfo->value.enumerated.item = 2;
1074 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1075 return 0;
1076}
1077
1078static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1079{
1080 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1081
1082 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1083 return 0;
1084}
1085
1086static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1087{
1088 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1089
1090 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1091 ucontrol->value.enumerated.item[0], 0);
1092}
1093
1094#define STAC9758_OUTPUT_JACK(xname, shift) \
1095{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1096 .info = snd_ac97_stac9758_output_jack_info, \
1097 .get = snd_ac97_stac9758_output_jack_get, \
1098 .put = snd_ac97_stac9758_output_jack_put, \
1099 .private_value = shift }
1100#define STAC9758_INPUT_JACK(xname, shift) \
1101{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1102 .info = snd_ac97_stac9758_input_jack_info, \
1103 .get = snd_ac97_stac9758_input_jack_get, \
1104 .put = snd_ac97_stac9758_input_jack_put, \
1105 .private_value = shift }
1106static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = {
1107 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1108 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1109 STAC9758_OUTPUT_JACK("Front Jack", 7),
1110 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1111 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1112 STAC9758_INPUT_JACK("Mic Input Source", 0),
1113 STAC9758_INPUT_JACK("Line Input Source", 8),
1114 {
1115 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1116 .name = "Headphone Amp",
1117 .info = snd_ac97_stac9758_phonesel_info,
1118 .get = snd_ac97_stac9758_phonesel_get,
1119 .put = snd_ac97_stac9758_phonesel_put
1120 },
1121 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1122 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1123};
1124
1125static int patch_sigmatel_stac9758_specific(ac97_t *ac97)
1126{
1127 int err;
1128
1129 err = patch_sigmatel_stac97xx_specific(ac97);
1130 if (err < 0)
1131 return err;
1132 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1133 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1134 if (err < 0)
1135 return err;
1136 /* DAC-A direct */
1137 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1138 /* DAC-A to Mix = PCM */
1139 /* DAC-B direct = Surround */
1140 /* DAC-B to Mix */
1141 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1142 /* DAC-C direct = Center/LFE */
1143
1144 return 0;
1145}
1146
1147static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1148 .build_3d = patch_sigmatel_stac9700_3d,
1149 .build_specific = patch_sigmatel_stac9758_specific
1150};
1151
1152int patch_sigmatel_stac9758(ac97_t * ac97)
1153{
1154 static unsigned short regs[4] = {
1155 AC97_SIGMATEL_OUTSEL,
1156 AC97_SIGMATEL_IOMISC,
1157 AC97_SIGMATEL_INSEL,
1158 AC97_SIGMATEL_VARIOUS
1159 };
1160 static unsigned short def_regs[4] = {
1161 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1162 /* IOMISC */ 0x2001,
1163 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1164 /* VARIOUS */ 0x0040
1165 };
1166 static unsigned short m675_regs[4] = {
1167 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1168 /* IOMISC */ 0x2102, /* HP amp on */
1169 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1170 /* VARIOUS */ 0x0041 /* stereo mic */
1171 };
1172 unsigned short *pregs = def_regs;
1173 int i;
1174
1175 /* Gateway M675 notebook */
1176 if (ac97->pci &&
1177 ac97->subsystem_vendor == 0x107b &&
1178 ac97->subsystem_device == 0x0601)
1179 pregs = m675_regs;
1180
1181 // patch for SigmaTel
1182 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1183 /* FIXME: assume only page 0 for writing cache */
1184 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1185 for (i = 0; i < 4; i++)
1186 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1187
1188 ac97->flags |= AC97_STEREO_MUTES;
1189 return 0;
1190}
1191
1192/*
1193 * Cirrus Logic CS42xx codecs
1194 */
1195static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
1196 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1197 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1198};
1199
1200static int patch_cirrus_build_spdif(ac97_t * ac97)
1201{
1202 int err;
1203
1204 /* con mask, pro mask, default */
1205 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1206 return err;
1207 /* switch, spsa */
1208 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1209 return err;
1210 switch (ac97->id & AC97_ID_CS_MASK) {
1211 case AC97_ID_CS4205:
1212 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1213 return err;
1214 break;
1215 }
1216 /* set default PCM S/PDIF params */
1217 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1218 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1219 return 0;
1220}
1221
1222static struct snd_ac97_build_ops patch_cirrus_ops = {
1223 .build_spdif = patch_cirrus_build_spdif
1224};
1225
1226int patch_cirrus_spdif(ac97_t * ac97)
1227{
1228 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1229 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1230 - sp/dif EA ID is not set, but sp/dif is always present.
1231 - enable/disable is spdif register bit 15.
1232 - sp/dif control register is 0x68. differs from AC97:
1233 - valid is bit 14 (vs 15)
1234 - no DRS
1235 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1236 - sp/dif ssource select is in 0x5e bits 0,1.
1237 */
1238
1239 ac97->build_ops = &patch_cirrus_ops;
1240 ac97->flags |= AC97_CS_SPDIF;
1241 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1242 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1243 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1244 return 0;
1245}
1246
1247int patch_cirrus_cs4299(ac97_t * ac97)
1248{
1249 /* force the detection of PC Beep */
1250 ac97->flags |= AC97_HAS_PC_BEEP;
1251
1252 return patch_cirrus_spdif(ac97);
1253}
1254
1255/*
1256 * Conexant codecs
1257 */
1258static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
1259 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1260};
1261
1262static int patch_conexant_build_spdif(ac97_t * ac97)
1263{
1264 int err;
1265
1266 /* con mask, pro mask, default */
1267 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1268 return err;
1269 /* switch */
1270 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1271 return err;
1272 /* set default PCM S/PDIF params */
1273 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1274 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1275 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1276 return 0;
1277}
1278
1279static struct snd_ac97_build_ops patch_conexant_ops = {
1280 .build_spdif = patch_conexant_build_spdif
1281};
1282
1283int patch_conexant(ac97_t * ac97)
1284{
1285 ac97->build_ops = &patch_conexant_ops;
1286 ac97->flags |= AC97_CX_SPDIF;
1287 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1288 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1289 return 0;
1290}
1291
1292/*
1293 * Analog Device AD18xx, AD19xx codecs
1294 */
1295#ifdef CONFIG_PM
1296static void ad18xx_resume(ac97_t *ac97)
1297{
1298 static unsigned short setup_regs[] = {
1299 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1300 };
1301 int i, codec;
1302
1303 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1304 unsigned short reg = setup_regs[i];
1305 if (test_bit(reg, ac97->reg_accessed)) {
1306 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1307 snd_ac97_read(ac97, reg);
1308 }
1309 }
1310
1311 if (! (ac97->flags & AC97_AD_MULTI))
1312 /* normal restore */
1313 snd_ac97_restore_status(ac97);
1314 else {
1315 /* restore the AD18xx codec configurations */
1316 for (codec = 0; codec < 3; codec++) {
1317 if (! ac97->spec.ad18xx.id[codec])
1318 continue;
1319 /* select single codec */
1320 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1321 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1322 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1323 }
1324 /* select all codecs */
1325 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1326
1327 /* restore status */
1328 for (i = 2; i < 0x7c ; i += 2) {
1329 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1330 continue;
1331 if (test_bit(i, ac97->reg_accessed)) {
1332 /* handle multi codecs for AD18xx */
1333 if (i == AC97_PCM) {
1334 for (codec = 0; codec < 3; codec++) {
1335 if (! ac97->spec.ad18xx.id[codec])
1336 continue;
1337 /* select single codec */
1338 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1339 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1340 /* update PCM bits */
1341 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1342 }
1343 /* select all codecs */
1344 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1345 continue;
1346 } else if (i == AC97_AD_TEST ||
1347 i == AC97_AD_CODEC_CFG ||
1348 i == AC97_AD_SERIAL_CFG)
1349 continue; /* ignore */
1350 }
1351 snd_ac97_write(ac97, i, ac97->regs[i]);
1352 snd_ac97_read(ac97, i);
1353 }
1354 }
1355
1356 snd_ac97_restore_iec958(ac97);
1357}
1358#endif
1359
1360int patch_ad1819(ac97_t * ac97)
1361{
1362 unsigned short scfg;
1363
1364 // patch for Analog Devices
1365 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1366 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1367 return 0;
1368}
1369
1370static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
1371{
1372 unsigned short val;
1373
1374 // test for unchained codec
1375 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1376 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1377 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1378 if ((val & 0xff40) != 0x5340)
1379 return 0;
1380 ac97->spec.ad18xx.unchained[idx] = mask;
1381 ac97->spec.ad18xx.id[idx] = val;
1382 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1383 return mask;
1384}
1385
1386static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
1387{
1388 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1389 unsigned short val;
1390
1391 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1392 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1393 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1394 if ((val & 0xff40) != 0x5340)
1395 return 0;
1396 if (codec_bits)
1397 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1398 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1399 ac97->spec.ad18xx.id[idx] = val;
1400 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1401 return 1;
1402}
1403
1404static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
1405{
1406 // already detected?
1407 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1408 cidx1 = -1;
1409 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1410 cidx2 = -1;
1411 if (cidx1 < 0 && cidx2 < 0)
1412 return;
1413 // test for chained codecs
1414 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1415 ac97->spec.ad18xx.unchained[unchained_idx]);
1416 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1417 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1418 if (cidx1 >= 0) {
1419 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1420 patch_ad1881_chained1(ac97, cidx2, 0);
1421 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1422 patch_ad1881_chained1(ac97, cidx1, 0);
1423 } else if (cidx2 >= 0) {
1424 patch_ad1881_chained1(ac97, cidx2, 0);
1425 }
1426}
1427
1428static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1429#ifdef CONFIG_PM
1430 .resume = ad18xx_resume
1431#endif
1432};
1433
1434int patch_ad1881(ac97_t * ac97)
1435{
1436 static const char cfg_idxs[3][2] = {
1437 {2, 1},
1438 {0, 2},
1439 {0, 1}
1440 };
1441
1442 // patch for Analog Devices
1443 unsigned short codecs[3];
1444 unsigned short val;
1445 int idx, num;
1446
1447 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1448 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1449 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1450 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1451 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1452
1453 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
1454
1455 for (idx = 0; idx < 3; idx++)
1456 if (ac97->spec.ad18xx.unchained[idx])
1457 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1458
1459 if (ac97->spec.ad18xx.id[1]) {
1460 ac97->flags |= AC97_AD_MULTI;
1461 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1462 }
1463 if (ac97->spec.ad18xx.id[2]) {
1464 ac97->flags |= AC97_AD_MULTI;
1465 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1466 }
1467
1468 __end:
1469 /* select all codecs */
1470 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1471 /* check if only one codec is present */
1472 for (idx = num = 0; idx < 3; idx++)
1473 if (ac97->spec.ad18xx.id[idx])
1474 num++;
1475 if (num == 1) {
1476 /* ok, deselect all ID bits */
1477 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1478 ac97->spec.ad18xx.codec_cfg[0] =
1479 ac97->spec.ad18xx.codec_cfg[1] =
1480 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1481 }
1482 /* required for AD1886/AD1885 combination */
1483 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1484 if (ac97->spec.ad18xx.id[0]) {
1485 ac97->id &= 0xffff0000;
1486 ac97->id |= ac97->spec.ad18xx.id[0];
1487 }
1488 ac97->build_ops = &patch_ad1881_build_ops;
1489 return 0;
1490}
1491
1492static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
1493 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1494 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1495 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1496 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1497 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1498 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1499};
1500
1501static int patch_ad1885_specific(ac97_t * ac97)
1502{
1503 int err;
1504
1505 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1506 return err;
1507 return 0;
1508}
1509
1510static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1511 .build_specific = &patch_ad1885_specific,
1512#ifdef CONFIG_PM
1513 .resume = ad18xx_resume
1514#endif
1515};
1516
1517int patch_ad1885(ac97_t * ac97)
1518{
1519 patch_ad1881(ac97);
1520 /* This is required to deal with the Intel D815EEAL2 */
1521 /* i.e. Line out is actually headphone out from codec */
1522
1523 /* set default */
1524 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1525
1526 ac97->build_ops = &patch_ad1885_build_ops;
1527 return 0;
1528}
1529
1530int patch_ad1886(ac97_t * ac97)
1531{
1532 patch_ad1881(ac97);
1533 /* Presario700 workaround */
1534 /* for Jack Sense/SPDIF Register misetting causing */
1535 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1536 return 0;
1537}
1538
1539/* MISC bits */
1540#define AC97_AD198X_MBC 0x0003 /* mic boost */
1541#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1542#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1543#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1544#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1545#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1546#define AC97_AD198X_VREF_0 0x000c /* 0V */
1547#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1548#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1549#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1550#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1551#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1552#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1553#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1554#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1555#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1556#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1557#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1558#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1559
1560
1561static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1562{
1563 static char *texts[2] = { "AC-Link", "A/D Converter" };
1564
1565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1566 uinfo->count = 1;
1567 uinfo->value.enumerated.items = 2;
1568 if (uinfo->value.enumerated.item > 1)
1569 uinfo->value.enumerated.item = 1;
1570 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1571 return 0;
1572}
1573
1574static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1575{
1576 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1577 unsigned short val;
1578
1579 val = ac97->regs[AC97_AD_SERIAL_CFG];
1580 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1581 return 0;
1582}
1583
1584static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1585{
1586 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1587 unsigned short val;
1588
1589 if (ucontrol->value.enumerated.item[0] > 1)
1590 return -EINVAL;
1591 val = ucontrol->value.enumerated.item[0] << 2;
1592 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1593}
1594
1595static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
1596 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1597 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1598 .info = snd_ac97_ad198x_spdif_source_info,
1599 .get = snd_ac97_ad198x_spdif_source_get,
1600 .put = snd_ac97_ad198x_spdif_source_put,
1601};
1602
1603static int patch_ad198x_post_spdif(ac97_t * ac97)
1604{
1605 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1606}
1607
1608static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = {
1609 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1610 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1611};
1612
1613static int patch_ad1981a_specific(ac97_t * ac97)
1614{
1615 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1616 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1617}
1618
1619static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1620 .build_post_spdif = patch_ad198x_post_spdif,
1621 .build_specific = patch_ad1981a_specific,
1622#ifdef CONFIG_PM
1623 .resume = ad18xx_resume
1624#endif
1625};
1626
1627static void check_ad1981_hp_jack_sense(ac97_t *ac97)
1628{
1629 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1630 switch (subid) {
1631 case 0x103c0890: /* HP nc6000 */
1632 case 0x103c006d: /* HP nx9105 */
1633 case 0x17340088: /* FSC Scenic-W */
1634 /* enable headphone jack sense */
1635 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1636 break;
1637 }
1638}
1639
1640int patch_ad1981a(ac97_t *ac97)
1641{
1642 patch_ad1881(ac97);
1643 ac97->build_ops = &patch_ad1981a_build_ops;
1644 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1645 ac97->flags |= AC97_STEREO_MUTES;
1646 check_ad1981_hp_jack_sense(ac97);
1647 return 0;
1648}
1649
1650static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
1651AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1652
1653static int patch_ad1981b_specific(ac97_t *ac97)
1654{
1655 int err;
1656
1657 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1658 return err;
1659 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1660 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1661}
1662
1663static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1664 .build_post_spdif = patch_ad198x_post_spdif,
1665 .build_specific = patch_ad1981b_specific,
1666#ifdef CONFIG_PM
1667 .resume = ad18xx_resume
1668#endif
1669};
1670
1671int patch_ad1981b(ac97_t *ac97)
1672{
1673 patch_ad1881(ac97);
1674 ac97->build_ops = &patch_ad1981b_build_ops;
1675 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1676 ac97->flags |= AC97_STEREO_MUTES;
1677 check_ad1981_hp_jack_sense(ac97);
1678 return 0;
1679}
1680
1681static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1682{
1683 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1684 uinfo->count = 1;
1685 uinfo->value.integer.min = 0;
1686 uinfo->value.integer.max = 1;
1687 return 0;
1688}
1689
1690static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1691{
1692 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1693 unsigned short val;
1694
1695 val = ac97->regs[AC97_AD_MISC];
1696 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1697 return 0;
1698}
1699
1700static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1701{
1702 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1703 unsigned short val;
1704
1705 val = !ucontrol->value.integer.value[0]
1706 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1707 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1708 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1709}
1710
1711static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1712{
1713 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1714
1715 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1716 uinfo->count = 1;
1717 uinfo->value.enumerated.items = 3;
1718 if (uinfo->value.enumerated.item > 2)
1719 uinfo->value.enumerated.item = 2;
1720 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1721 return 0;
1722}
1723
1724static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1725{
1726 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1727 unsigned short val;
1728
1729 val = ac97->regs[AC97_AD_MISC];
1730 if (!(val & AC97_AD198X_DMIX1))
1731 ucontrol->value.enumerated.item[0] = 0;
1732 else
1733 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1734 return 0;
1735}
1736
1737static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1738{
1739 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1740 unsigned short val;
1741
1742 if (ucontrol->value.enumerated.item[0] > 2)
1743 return -EINVAL;
1744 if (ucontrol->value.enumerated.item[0] == 0)
1745 val = 0;
1746 else
1747 val = AC97_AD198X_DMIX1 |
1748 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1749 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1750 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1751}
1752
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001753static void ad1888_update_jacks(ac97_t *ac97)
1754{
1755 /* shared Line-In */
1756 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1757 is_shared_linein(ac97) ? 0 : 1 << 12);
1758 /* shared Mic */
1759 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
Clemens Ladisch32964802005-05-10 14:48:37 +02001760 is_shared_micin(ac97) ? 0 : 1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001761}
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
1764 {
1765 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1766 .name = "Exchange Front/Surround",
1767 .info = snd_ac97_ad1888_lohpsel_info,
1768 .get = snd_ac97_ad1888_lohpsel_get,
1769 .put = snd_ac97_ad1888_lohpsel_put
1770 },
1771 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1772 {
1773 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1774 .name = "Downmix",
1775 .info = snd_ac97_ad1888_downmix_info,
1776 .get = snd_ac97_ad1888_downmix_get,
1777 .put = snd_ac97_ad1888_downmix_put
1778 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001779 AC97_SURROUND_JACK_MODE_CTL,
1780 AC97_CHANNEL_MODE_CTL,
Sergey Ulanoveeacb542005-07-27 17:28:58 +02001781
1782 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1783 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784};
1785
1786static int patch_ad1888_specific(ac97_t *ac97)
1787{
1788 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1789 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1790 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1791 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1792}
1793
1794static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1795 .build_post_spdif = patch_ad198x_post_spdif,
1796 .build_specific = patch_ad1888_specific,
1797#ifdef CONFIG_PM
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001798 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001800 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801};
1802
1803int patch_ad1888(ac97_t * ac97)
1804{
1805 unsigned short misc;
1806
1807 patch_ad1881(ac97);
1808 ac97->build_ops = &patch_ad1888_build_ops;
1809 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1810 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1811 /* AD-compatible mode */
1812 /* Stereo mutes enabled */
1813 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1814 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1815 AC97_AD198X_LOSEL |
1816 AC97_AD198X_HPSEL |
1817 AC97_AD198X_MSPLT |
1818 AC97_AD198X_AC97NC);
1819 ac97->flags |= AC97_STEREO_MUTES;
1820 return 0;
1821}
1822
1823static int patch_ad1980_specific(ac97_t *ac97)
1824{
1825 int err;
1826
1827 if ((err = patch_ad1888_specific(ac97)) < 0)
1828 return err;
1829 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1830}
1831
1832static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1833 .build_post_spdif = patch_ad198x_post_spdif,
1834 .build_specific = patch_ad1980_specific,
1835#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001836 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001838 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839};
1840
1841int patch_ad1980(ac97_t * ac97)
1842{
1843 patch_ad1888(ac97);
1844 ac97->build_ops = &patch_ad1980_build_ops;
1845 return 0;
1846}
1847
1848static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1850};
1851
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001852static void ad1985_update_jacks(ac97_t *ac97)
1853{
1854 /* shared Line-In */
1855 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1856 is_shared_linein(ac97) ? 0 : 1 << 12);
1857 /* shared Mic */
1858 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1859 is_shared_micin(ac97) ? 0 : 1 << 11);
Takashi Iwaifc232c62005-05-27 10:42:45 +02001860 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1861 is_shared_micin(ac97) ? 0 : 1 << 9);
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001862}
1863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864static int patch_ad1985_specific(ac97_t *ac97)
1865{
1866 int err;
1867
1868 if ((err = patch_ad1980_specific(ac97)) < 0)
1869 return err;
1870 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1871}
1872
1873static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1874 .build_post_spdif = patch_ad198x_post_spdif,
1875 .build_specific = patch_ad1985_specific,
1876#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001877 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878#endif
Takashi Iwaie5b3f452005-05-17 17:17:57 +02001879 .update_jacks = ad1985_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880};
1881
1882int patch_ad1985(ac97_t * ac97)
1883{
1884 unsigned short misc;
1885
1886 patch_ad1881(ac97);
1887 ac97->build_ops = &patch_ad1985_build_ops;
1888 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1889 /* switch front/surround line-out/hp-out */
1890 /* center/LFE, mic in 3.75V mode */
1891 /* AD-compatible mode */
1892 /* Stereo mutes enabled */
1893 /* in accordance with ADI driver: misc | 0x5c28 */
1894 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1895 AC97_AD198X_VREFH |
1896 AC97_AD198X_LOSEL |
1897 AC97_AD198X_HPSEL |
1898 AC97_AD198X_CLDIS |
1899 AC97_AD198X_LODIS |
1900 AC97_AD198X_MSPLT |
1901 AC97_AD198X_AC97NC);
1902 ac97->flags |= AC97_STEREO_MUTES;
1903 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1904 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1905 return 0;
1906}
1907
1908/*
1909 * realtek ALC65x/850 codecs
1910 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001911static void alc650_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001913 int shared;
1914
1915 /* shared Line-In */
1916 shared = is_shared_linein(ac97);
1917 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1918 shared ? (1 << 9) : 0);
1919 /* update shared Mic */
1920 shared = is_shared_micin(ac97);
1921 /* disable/enable vref */
1922 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1923 shared ? (1 << 12) : 0);
1924 /* turn on/off center-on-mic */
1925 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1926 shared ? (1 << 10) : 0);
1927 /* GPIO0 high for mic */
1928 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1929 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930}
1931
1932static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1933 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1934 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1935 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1936 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1937 /* 4: Analog Input To Surround */
1938 /* 5: Analog Input To Center/LFE */
1939 /* 6: Independent Master Volume Right */
1940 /* 7: Independent Master Volume Left */
1941 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001942 /* 9: Line-In/Surround share */
1943 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 /* 11-13: in IEC958 controls */
1945 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1946#if 0 /* always set in patch_alc650 */
1947 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1948 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1949 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1950 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1951 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1952 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1953#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001954 AC97_SURROUND_JACK_MODE_CTL,
1955 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956};
1957
1958static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001959 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1961 /* disable this controls since it doesn't work as expected */
1962 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
1963};
1964
1965static int patch_alc650_specific(ac97_t * ac97)
1966{
1967 int err;
1968
1969 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1970 return err;
1971 if (ac97->ext_id & AC97_EI_SPDIF) {
1972 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1973 return err;
1974 }
1975 return 0;
1976}
1977
1978static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001979 .build_specific = patch_alc650_specific,
1980 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981};
1982
1983int patch_alc650(ac97_t * ac97)
1984{
1985 unsigned short val;
1986
1987 ac97->build_ops = &patch_alc650_ops;
1988
1989 /* determine the revision */
1990 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
1991 if (val < 3)
1992 ac97->id = 0x414c4720; /* Old version */
1993 else if (val < 0x10)
1994 ac97->id = 0x414c4721; /* D version */
1995 else if (val < 0x20)
1996 ac97->id = 0x414c4722; /* E version */
1997 else if (val < 0x30)
1998 ac97->id = 0x414c4723; /* F version */
1999
2000 /* revision E or F */
2001 /* FIXME: what about revision D ? */
2002 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2003 ac97->id == 0x414c4723);
2004
2005 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2006 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2007 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2008
2009 /* Enable SPDIF-IN only on Rev.E and above */
2010 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2011 /* SPDIF IN with pin 47 */
2012 if (ac97->spec.dev_flags)
2013 val |= 0x03; /* enable */
2014 else
2015 val &= ~0x03; /* disable */
2016 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2017
2018 /* set default: slot 3,4,7,8,6,9
2019 spdif-in monitor off, analog-spdif off, spdif-in off
2020 center on mic off, surround on line-in off
2021 downmix off, duplicate front off
2022 */
2023 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2024
2025 /* set GPIO0 for mic bias */
2026 /* GPIO0 pin output, no interrupt, high */
2027 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2028 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2029 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2030 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2031
2032 /* full DAC volume */
2033 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2034 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2035 return 0;
2036}
2037
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002038static void alc655_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002040 int shared;
2041
2042 /* shared Line-In */
2043 shared = is_shared_linein(ac97);
2044 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2045 shared ? (1 << 9) : 0, 0);
2046 /* update shared mic */
2047 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* misc control; vrefout disable */
2049 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002050 shared ? (1 << 12) : 0);
2051 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2052 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053}
2054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
2056 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002057 AC97_SURROUND_JACK_MODE_CTL,
2058 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059};
2060
2061static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2062{
2063 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2064 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2065 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2066
2067 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2068 uinfo->count = 1;
2069 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2070 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2071 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2072 strcpy(uinfo->value.enumerated.name,
2073 ac97->spec.dev_flags ?
2074 texts_658[uinfo->value.enumerated.item] :
2075 texts_655[uinfo->value.enumerated.item]);
2076 return 0;
2077}
2078
2079static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2080{
2081 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2082 unsigned short val;
2083
2084 val = ac97->regs[AC97_ALC650_MULTICH];
2085 val = (val >> 12) & 3;
2086 if (ac97->spec.dev_flags && val == 3)
2087 val = 0;
2088 ucontrol->value.enumerated.item[0] = val;
2089 return 0;
2090}
2091
2092static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2093{
2094 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2095
2096 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2097 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2098 0);
2099}
2100
2101static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002102 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /* disable this controls since it doesn't work as expected */
2104 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2105 {
2106 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002107 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 .info = alc655_iec958_route_info,
2109 .get = alc655_iec958_route_get,
2110 .put = alc655_iec958_route_put,
2111 },
2112};
2113
2114static int patch_alc655_specific(ac97_t * ac97)
2115{
2116 int err;
2117
2118 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2119 return err;
2120 if (ac97->ext_id & AC97_EI_SPDIF) {
2121 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2122 return err;
2123 }
2124 return 0;
2125}
2126
2127static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002128 .build_specific = patch_alc655_specific,
2129 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130};
2131
2132int patch_alc655(ac97_t * ac97)
2133{
2134 unsigned int val;
2135
2136 ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
2137
2138 ac97->build_ops = &patch_alc655_ops;
2139
2140 /* assume only page 0 for writing cache */
2141 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2142
2143 /* adjust default values */
2144 val = snd_ac97_read(ac97, 0x7a); /* misc control */
2145 if (ac97->id == 0x414c4780) /* ALC658 */
2146 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2147 else /* ALC655 */
2148 val |= (1 << 1); /* Pin 47 is spdif input pin */
2149 val &= ~(1 << 12); /* vref enable */
2150 snd_ac97_write_cache(ac97, 0x7a, val);
2151 /* set default: spdif-in enabled,
2152 spdif-in monitor off, spdif-in PCM off
2153 center on mic off, surround on line-in off
2154 duplicate front off
2155 */
2156 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2157
2158 /* full DAC volume */
2159 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2160 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2161 return 0;
2162}
2163
2164
2165#define AC97_ALC850_JACK_SELECT 0x76
2166#define AC97_ALC850_MISC1 0x7a
2167
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002168static void alc850_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002170 int shared;
2171
2172 /* shared Line-In */
2173 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 /* SURR 1kOhm (bit4), Amp (bit5) */
2175 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002176 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002178 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2179 shared ? (2<<12) : (0<<12));
2180 /* update shared mic */
2181 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 /* Vref disable (bit12), 1kOhm (bit13) */
2183 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002184 shared ? (1<<12) : (1<<13));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 /* MIC-IN = 1, CENTER-LFE = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002186 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2187 shared ? (2<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = {
2191 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02002192 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002193 AC97_SURROUND_JACK_MODE_CTL,
2194 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195};
2196
2197static int patch_alc850_specific(ac97_t *ac97)
2198{
2199 int err;
2200
2201 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2202 return err;
2203 if (ac97->ext_id & AC97_EI_SPDIF) {
2204 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2205 return err;
2206 }
2207 return 0;
2208}
2209
2210static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002211 .build_specific = patch_alc850_specific,
2212 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213};
2214
2215int patch_alc850(ac97_t *ac97)
2216{
2217 ac97->build_ops = &patch_alc850_ops;
2218
2219 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2220
2221 /* assume only page 0 for writing cache */
2222 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2223
2224 /* adjust default values */
2225 /* set default: spdif-in enabled,
2226 spdif-in monitor off, spdif-in PCM off
2227 center on mic off, surround on line-in off
2228 duplicate front off
2229 */
2230 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2231 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2232 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2233 */
2234 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2235 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2236 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2237 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2238 */
2239 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2240 (1<<11)|(0<<12)|(1<<15));
2241
2242 /* full DAC volume */
2243 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2244 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2245 return 0;
2246}
2247
2248
2249/*
2250 * C-Media CM97xx codecs
2251 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002252static void cm9738_update_jacks(ac97_t *ac97)
2253{
2254 /* shared Line-In */
2255 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2256 is_shared_linein(ac97) ? (1 << 10) : 0);
2257}
2258
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002261 AC97_SURROUND_JACK_MODE_CTL,
2262 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263};
2264
2265static int patch_cm9738_specific(ac97_t * ac97)
2266{
2267 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2268}
2269
2270static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002271 .build_specific = patch_cm9738_specific,
2272 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273};
2274
2275int patch_cm9738(ac97_t * ac97)
2276{
2277 ac97->build_ops = &patch_cm9738_ops;
2278 /* FIXME: can anyone confirm below? */
2279 /* CM9738 has no PCM volume although the register reacts */
2280 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2281 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2282
2283 return 0;
2284}
2285
2286static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2287{
2288 static char *texts[] = { "Analog", "Digital" };
2289
2290 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2291 uinfo->count = 1;
2292 uinfo->value.enumerated.items = 2;
2293 if (uinfo->value.enumerated.item > 1)
2294 uinfo->value.enumerated.item = 1;
2295 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2296 return 0;
2297}
2298
2299static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2300{
2301 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2302 unsigned short val;
2303
2304 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2305 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2306 return 0;
2307}
2308
2309static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2310{
2311 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2312
2313 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2314 0x01 << 1,
2315 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2316}
2317
2318static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
2319 /* BIT 0: SPDI_EN - always true */
2320 { /* BIT 1: SPDIFS */
2321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2322 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2323 .info = snd_ac97_cmedia_spdif_playback_source_info,
2324 .get = snd_ac97_cmedia_spdif_playback_source_get,
2325 .put = snd_ac97_cmedia_spdif_playback_source_put,
2326 },
2327 /* BIT 2: IG_SPIV */
2328 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2329 /* BIT 3: SPI2F */
2330 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2331 /* BIT 4: SPI2SDI */
2332 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2333 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2334};
2335
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002336static void cm9739_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002338 /* shared Line-In */
2339 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2340 is_shared_linein(ac97) ? (1 << 10) : 0);
2341 /* shared Mic */
2342 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2343 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002347 AC97_SURROUND_JACK_MODE_CTL,
2348 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349};
2350
2351static int patch_cm9739_specific(ac97_t * ac97)
2352{
2353 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2354}
2355
2356static int patch_cm9739_post_spdif(ac97_t * ac97)
2357{
2358 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2359}
2360
2361static struct snd_ac97_build_ops patch_cm9739_ops = {
2362 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002363 .build_post_spdif = patch_cm9739_post_spdif,
2364 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365};
2366
2367int patch_cm9739(ac97_t * ac97)
2368{
2369 unsigned short val;
2370
2371 ac97->build_ops = &patch_cm9739_ops;
2372
2373 /* CM9739/A has no Master and PCM volume although the register reacts */
2374 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2375 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2376 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2377
2378 /* check spdif */
2379 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2380 if (val & AC97_EA_SPCV) {
2381 /* enable spdif in */
2382 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2383 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2384 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2385 } else {
2386 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2387 ac97->rates[AC97_RATES_SPDIF] = 0;
2388 }
2389
2390 /* set-up multi channel */
2391 /* bit 14: 0 = SPDIF, 1 = EAPD */
2392 /* bit 13: enable internal vref output for mic */
2393 /* bit 12: disable center/lfe (swithable) */
2394 /* bit 10: disable surround/line (switchable) */
2395 /* bit 9: mix 2 surround off */
2396 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2397 /* bit 3: undocumented; surround? */
2398 /* bit 0: dB */
2399 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2400 val |= (1 << 3);
2401 val |= (1 << 13);
2402 if (! (ac97->ext_id & AC97_EI_SPDIF))
2403 val |= (1 << 14);
2404 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2405
2406 /* FIXME: set up GPIO */
2407 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2408 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2409 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2410 if (ac97->pci &&
2411 ac97->subsystem_vendor == 0x1043 &&
2412 ac97->subsystem_device == 0x1843) {
2413 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2414 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2415 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2416 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2417 }
2418
2419 return 0;
2420}
2421
2422#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002423#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424#define AC97_CM9761_SPDIF_CTRL 0x6c
2425
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002426static void cm9761_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002428 unsigned short surr_vals[2][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 { 0x0008, 0x0400 }, /* off, on */
2430 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */
2431 };
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002432 unsigned short clfe_vals[2][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 { 0x2000, 0x1880 }, /* off, on */
2434 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */
2435 };
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002436
2437 /* shared Line-In */
2438 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408,
2439 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]);
2440 /* shared Mic */
2441 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880,
2442 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443}
2444
2445static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002446 AC97_SURROUND_JACK_MODE_CTL,
2447 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448};
2449
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002450static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2451{
2452 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2453
2454 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2455 uinfo->count = 1;
2456 uinfo->value.enumerated.items = 3;
2457 if (uinfo->value.enumerated.item > 2)
2458 uinfo->value.enumerated.item = 2;
2459 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2460 return 0;
2461}
2462
2463static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2464{
2465 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2466
2467 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2468 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2469 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2470 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2471 else
2472 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2473 return 0;
2474}
2475
2476static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2477{
2478 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2479
2480 if (ucontrol->value.enumerated.item[0] == 2)
2481 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2482 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2483 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2484 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2485}
2486
2487static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2488static const struct ac97_enum cm9761_dac_clock_enum =
2489 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2490
2491static const snd_kcontrol_new_t snd_ac97_cm9761_controls_spdif[] = {
2492 { /* BIT 1: SPDIFS */
2493 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2494 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2495 .info = cm9761_spdif_out_source_info,
2496 .get = cm9761_spdif_out_source_get,
2497 .put = cm9761_spdif_out_source_put,
2498 },
2499 /* BIT 2: IG_SPIV */
2500 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2501 /* BIT 3: SPI2F */
2502 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2503 /* BIT 4: SPI2SDI */
2504 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2505 /* BIT 9-10: DAC_CTL */
2506 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2507};
2508
2509static int patch_cm9761_post_spdif(ac97_t * ac97)
2510{
2511 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2512}
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514static int patch_cm9761_specific(ac97_t * ac97)
2515{
2516 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2517}
2518
2519static struct snd_ac97_build_ops patch_cm9761_ops = {
2520 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002521 .build_post_spdif = patch_cm9761_post_spdif,
2522 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523};
2524
2525int patch_cm9761(ac97_t *ac97)
2526{
2527 unsigned short val;
2528
2529 /* CM9761 has no PCM volume although the register reacts */
2530 /* Master volume seems to have _some_ influence on the analog
2531 * input sounds
2532 */
2533 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2534 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2535 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2536
2537 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */
2538 if (ac97->id == AC97_ID_CM9761_82) {
2539 unsigned short tmp;
2540 /* check page 1, reg 0x60 */
2541 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2542 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2543 tmp = snd_ac97_read(ac97, 0x60);
2544 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2545 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2546 }
2547
2548 ac97->build_ops = &patch_cm9761_ops;
2549
2550 /* enable spdif */
2551 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2552 ac97->ext_id |= AC97_EI_SPDIF;
2553 /* to be sure: we overwrite the ext status bits */
2554 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2555 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002556 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2558
2559 /* set-up multi channel */
2560 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002561 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002563 * bit 12: CLFE control (reverted on rev B)
2564 * bit 11: Mic/center share (reverted on rev B)
2565 * bit 10: suddound/line share
2566 * bit 9: Analog-in mix -> surround
2567 * bit 8: Analog-in mix -> CLFE
2568 * bit 7: Mic/LFE share (mic/center/lfe)
2569 * bit 5: vref select (9761A)
2570 * bit 4: front control
2571 * bit 3: surround control (revereted with rev B)
2572 * bit 2: front mic
2573 * bit 1: stereo mic
2574 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 */
2576
2577#if 0
2578 if (ac97->spec.dev_flags)
2579 val = 0x0214;
2580 else
2581 val = 0x321c;
2582#endif
2583 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2584 val |= (1 << 4); /* front on */
2585 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2586
2587 /* FIXME: set up GPIO */
2588 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2589 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2590
2591 return 0;
2592}
2593
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002594#define AC97_CM9780_SIDE 0x60
2595#define AC97_CM9780_JACK 0x62
2596#define AC97_CM9780_MIXER 0x64
2597#define AC97_CM9780_MULTI_CHAN 0x66
2598#define AC97_CM9780_SPDIF 0x6c
2599
2600static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2601static const struct ac97_enum cm9780_ch_select_enum =
2602 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2603static const snd_kcontrol_new_t cm9780_controls[] = {
2604 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2605 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2606 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2607};
2608
2609static int patch_cm9780_specific(ac97_t *ac97)
2610{
2611 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2612}
2613
2614static struct snd_ac97_build_ops patch_cm9780_ops = {
2615 .build_specific = patch_cm9780_specific,
2616 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2617};
2618
2619int patch_cm9780(ac97_t *ac97)
2620{
2621 unsigned short val;
2622
2623 ac97->build_ops = &patch_cm9780_ops;
2624
2625 /* enable spdif */
2626 if (ac97->ext_id & AC97_EI_SPDIF) {
2627 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2628 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2629 val |= 0x1; /* SPDI_EN */
2630 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2631 }
2632
2633 return 0;
2634}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636/*
2637 * VIA VT1616 codec
2638 */
2639static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
2640AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2641AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2642AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2643AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2644};
2645
2646static int patch_vt1616_specific(ac97_t * ac97)
2647{
2648 int err;
2649
2650 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2651 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2652 return err;
2653 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2654 return err;
2655 return 0;
2656}
2657
2658static struct snd_ac97_build_ops patch_vt1616_ops = {
2659 .build_specific = patch_vt1616_specific
2660};
2661
2662int patch_vt1616(ac97_t * ac97)
2663{
2664 ac97->build_ops = &patch_vt1616_ops;
2665 return 0;
2666}
2667
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002668/*
2669 */
2670static void it2646_update_jacks(ac97_t *ac97)
2671{
2672 /* shared Line-In */
2673 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2674 is_shared_linein(ac97) ? (1<<9) : 0);
2675 /* shared Mic */
2676 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2677 is_shared_micin(ac97) ? (1<<10) : 0);
2678}
2679
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002681 AC97_SURROUND_JACK_MODE_CTL,
2682 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683};
2684
2685static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
Clemens Ladisch10e8d782005-08-03 13:40:08 +02002686 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2688 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2689};
2690
2691static int patch_it2646_specific(ac97_t * ac97)
2692{
2693 int err;
2694 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2695 return err;
2696 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2697 return err;
2698 return 0;
2699}
2700
2701static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002702 .build_specific = patch_it2646_specific,
2703 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704};
2705
2706int patch_it2646(ac97_t * ac97)
2707{
2708 ac97->build_ops = &patch_it2646_ops;
2709 /* full DAC volume */
2710 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2711 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2712 return 0;
2713}
2714
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002715/*
2716 * Si3036 codec
2717 */
2718
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719#define AC97_SI3036_CHIP_ID 0x5a
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002720#define AC97_SI3036_LINE_CFG 0x5c
2721
2722static const snd_kcontrol_new_t snd_ac97_controls_si3036[] = {
2723AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2724};
2725
2726static int patch_si3036_specific(ac97_t * ac97)
2727{
2728 return patch_build_controls(ac97, snd_ac97_controls_si3036, ARRAY_SIZE(snd_ac97_controls_si3036));
2729}
2730
2731static struct snd_ac97_build_ops patch_si3036_ops = {
2732 .build_specific = patch_si3036_specific,
2733};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735int mpatch_si3036(ac97_t * ac97)
2736{
Sasha Khapyorsky87d61c22005-05-29 15:08:23 +02002737 ac97->build_ops = &patch_si3036_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2739 snd_ac97_write_cache(ac97, 0x68, 0);
2740 return 0;
2741}