blob: ce02e7091fcb555ba7c94b56cd38b47bd2fe897a [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
373int patch_wolfson03(ac97_t * ac97)
374{
375 /* This is known to work for the ViewSonic ViewPad 1000
376 Randolph Bentson <bentson@holmsjoen.com> */
377
378 // WM9703/9707/9708/9717
379 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
380 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000);
381 return 0;
382}
383
384int patch_wolfson04(ac97_t * ac97)
385{
386 // WM9704M/9704Q
387 // set front and rear mixer volume
388 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
389 snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808);
390
391 // patch for DVD noise
392 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
393
394 // init vol
395 snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808);
396
397 // set rear surround volume
398 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
399 return 0;
400}
401
402int patch_wolfson05(ac97_t * ac97)
403{
404 // WM9705, WM9710
405 // set front mixer volume
406 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
407 return 0;
408}
409
410int patch_wolfson11(ac97_t * ac97)
411{
412 // WM9711, WM9712
413 // set out3 volume
414 snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808);
415 return 0;
416}
417
418static const char* wm9713_mic_mixer[] = {"Stereo", "Mic1", "Mic2", "Mute"};
419static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
420static const char* wm9713_rec_src_l[] = {"Mic1", "Mic2", "Line L", "Mono In", "HP Mix L", "Spk Mix", "Mono Mix", "Zh"};
421static const char* wm9713_rec_src_r[] = {"Mic1", "Mic2", "Line R", "Mono In", "HP Mix R", "Spk Mix", "Mono Mix", "Zh"};
422
423static const struct ac97_enum wm9713_enum[] = {
424AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
425AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
426AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
427AC97_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src_l),
428AC97_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src_r),
429};
430
431static const snd_kcontrol_new_t wm13_snd_ac97_controls_line_in[] = {
432AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
433AC97_SINGLE("Line In to Headphone Mute", AC97_PC_BEEP, 15, 1, 1),
434AC97_SINGLE("Line In to Speaker Mute", AC97_PC_BEEP, 14, 1, 1),
435AC97_SINGLE("Line In to Mono Mute", AC97_PC_BEEP, 13, 1, 1),
436};
437
438static const snd_kcontrol_new_t wm13_snd_ac97_controls_dac[] = {
439AC97_DOUBLE("DAC Volume", AC97_PHONE, 8, 0, 31, 1),
440AC97_SINGLE("DAC to Headphone Mute", AC97_PHONE, 15, 1, 1),
441AC97_SINGLE("DAC to Speaker Mute", AC97_PHONE, 14, 1, 1),
442AC97_SINGLE("DAC to Mono Mute", AC97_PHONE, 13, 1, 1),
443};
444
445static const snd_kcontrol_new_t wm13_snd_ac97_controls_mic[] = {
446AC97_SINGLE("MICA Volume", AC97_MIC, 8, 31, 1),
447AC97_SINGLE("MICB Volume", AC97_MIC, 0, 31, 1),
448AC97_SINGLE("MICA to Mono Mute", AC97_LINE, 7, 1, 1),
449AC97_SINGLE("MICB to Mono Mute", AC97_LINE, 6, 1, 1),
450AC97_SINGLE("MIC Boost (+20dB)", AC97_LINE, 5, 1, 1),
451AC97_ENUM("MIC Headphone Routing", wm9713_enum[0]),
452AC97_SINGLE("MIC Headphone Mixer Volume", AC97_LINE, 0, 7, 1)
453};
454
455static const snd_kcontrol_new_t wm13_snd_ac97_controls_adc[] = {
456AC97_SINGLE("ADC Mute", AC97_CD, 15, 1, 1),
457AC97_DOUBLE("Gain Step Size (1.5dB/0.75dB)", AC97_CD, 14, 6, 1, 1),
458AC97_DOUBLE("ADC Volume",AC97_CD, 8, 0, 15, 0),
459AC97_SINGLE("ADC Zero Cross", AC97_CD, 7, 1, 1),
460};
461
462static const snd_kcontrol_new_t wm13_snd_ac97_controls_recsel[] = {
463AC97_ENUM("Record to Headphone Path", wm9713_enum[1]),
464AC97_SINGLE("Record to Headphone Volume", AC97_VIDEO, 11, 7, 0),
465AC97_ENUM("Record to Mono Path", wm9713_enum[2]),
466AC97_SINGLE("Record to Mono Boost (+20dB)", AC97_VIDEO, 8, 1, 0),
467AC97_SINGLE("Record ADC Boost (+20dB)", AC97_VIDEO, 6, 1, 0),
468AC97_ENUM("Record Select Left", wm9713_enum[3]),
469AC97_ENUM("Record Select Right", wm9713_enum[4]),
470};
471
472static int patch_wolfson_wm9713_specific(ac97_t * ac97)
473{
474 int err, i;
475
476 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_line_in); i++) {
477 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_line_in[i], ac97))) < 0)
478 return err;
479 }
480 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
481
482 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_dac); i++) {
483 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_dac[i], ac97))) < 0)
484 return err;
485 }
486 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
487
488 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_mic); i++) {
489 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_mic[i], ac97))) < 0)
490 return err;
491 }
492 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
493 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
494
495 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_adc); i++) {
496 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_adc[i], ac97))) < 0)
497 return err;
498 }
499 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
500
501 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_recsel); i++) {
502 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_recsel[i], ac97))) < 0)
503 return err;
504 }
505 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
506 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
507
508 return 0;
509}
510
511#ifdef CONFIG_PM
512static void patch_wolfson_wm9713_suspend (ac97_t * ac97)
513{
514 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
515 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
516}
517
518static void patch_wolfson_wm9713_resume (ac97_t * ac97)
519{
520 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
521 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
522 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
523}
524#endif
525
526static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
527 .build_specific = patch_wolfson_wm9713_specific,
528#ifdef CONFIG_PM
529 .suspend = patch_wolfson_wm9713_suspend,
530 .resume = patch_wolfson_wm9713_resume
531#endif
532};
533
534int patch_wolfson13(ac97_t * ac97)
535{
536 ac97->build_ops = &patch_wolfson_wm9713_ops;
537
538 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
539 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
540
541 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
542 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
543 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
544
545 return 0;
546}
547
548/*
549 * Tritech codec
550 */
551int patch_tritech_tr28028(ac97_t * ac97)
552{
553 snd_ac97_write_cache(ac97, 0x26, 0x0300);
554 snd_ac97_write_cache(ac97, 0x26, 0x0000);
555 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
556 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
557 return 0;
558}
559
560/*
561 * Sigmatel STAC97xx codecs
562 */
563static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
564{
565 snd_kcontrol_t *kctl;
566 int err;
567
568 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
569 return err;
570 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
571 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
572 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
573 return 0;
574}
575
576static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
577{
578 snd_kcontrol_t *kctl;
579 int err;
580
581 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
582 return err;
583 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
584 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
585 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
586 return err;
587 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
588 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
589 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
590 return 0;
591}
592
593static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
594AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
595
596static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
597AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
598
599static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
600AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
601AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
602};
603
604static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
605{
606 int err;
607
608 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
609 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
610 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
611 return err;
612 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
613 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
614 return err;
615 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
616 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
617 return err;
618 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
619 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
620 return err;
621 return 0;
622}
623
624static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
625 .build_3d = patch_sigmatel_stac9700_3d,
626 .build_specific = patch_sigmatel_stac97xx_specific
627};
628
629int patch_sigmatel_stac9700(ac97_t * ac97)
630{
631 ac97->build_ops = &patch_sigmatel_stac9700_ops;
632 return 0;
633}
634
635static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
636{
637 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
638 int err;
639
640 down(&ac97->page_mutex);
641 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
642 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
643 (ucontrol->value.integer.value[0] & 1) << 4);
644 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
645 up(&ac97->page_mutex);
646 return err;
647}
648
649static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = {
650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
651 .name = "Sigmatel Output Bias Switch",
652 .info = snd_ac97_info_volsw,
653 .get = snd_ac97_get_volsw,
654 .put = snd_ac97_stac9708_put_bias,
655 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
656};
657
658static int patch_sigmatel_stac9708_specific(ac97_t *ac97)
659{
660 int err;
661
662 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
663 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
664 return err;
665 return patch_sigmatel_stac97xx_specific(ac97);
666}
667
668static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
669 .build_3d = patch_sigmatel_stac9708_3d,
670 .build_specific = patch_sigmatel_stac9708_specific
671};
672
673int patch_sigmatel_stac9708(ac97_t * ac97)
674{
675 unsigned int codec72, codec6c;
676
677 ac97->build_ops = &patch_sigmatel_stac9708_ops;
678 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
679
680 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
681 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
682
683 if ((codec72==0) && (codec6c==0)) {
684 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
685 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
686 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
687 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
688 } else if ((codec72==0x8000) && (codec6c==0)) {
689 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
690 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
691 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
692 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
693 /* nothing */
694 }
695 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
696 return 0;
697}
698
699int patch_sigmatel_stac9721(ac97_t * ac97)
700{
701 ac97->build_ops = &patch_sigmatel_stac9700_ops;
702 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
703 // patch for SigmaTel
704 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
705 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
706 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
707 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
708 }
709 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
710 return 0;
711}
712
713int patch_sigmatel_stac9744(ac97_t * ac97)
714{
715 // patch for SigmaTel
716 ac97->build_ops = &patch_sigmatel_stac9700_ops;
717 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
718 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
719 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
720 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
721 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
722 return 0;
723}
724
725int patch_sigmatel_stac9756(ac97_t * ac97)
726{
727 // patch for SigmaTel
728 ac97->build_ops = &patch_sigmatel_stac9700_ops;
729 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
730 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
731 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
732 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
733 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
734 return 0;
735}
736
737static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
738{
739 static char *texts[5] = { "Input/Disabled", "Front Output",
740 "Rear Output", "Center/LFE Output", "Mixer Output" };
741
742 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
743 uinfo->count = 1;
744 uinfo->value.enumerated.items = 5;
745 if (uinfo->value.enumerated.item > 4)
746 uinfo->value.enumerated.item = 4;
747 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
748 return 0;
749}
750
751static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
752{
753 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
754 int shift = kcontrol->private_value;
755 unsigned short val;
756
757 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
758 if (!(val & 4))
759 ucontrol->value.enumerated.item[0] = 0;
760 else
761 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
762 return 0;
763}
764
765static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
766{
767 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
768 int shift = kcontrol->private_value;
769 unsigned short val;
770
771 if (ucontrol->value.enumerated.item[0] > 4)
772 return -EINVAL;
773 if (ucontrol->value.enumerated.item[0] == 0)
774 val = 0;
775 else
776 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
777 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
778 7 << shift, val << shift, 0);
779}
780
781static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
782{
783 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
784 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
785
786 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
787 uinfo->count = 1;
788 uinfo->value.enumerated.items = 7;
789 if (uinfo->value.enumerated.item > 6)
790 uinfo->value.enumerated.item = 6;
791 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
792 return 0;
793}
794
795static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
796{
797 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
798 int shift = kcontrol->private_value;
799 unsigned short val;
800
801 val = ac97->regs[AC97_SIGMATEL_INSEL];
802 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
803 return 0;
804}
805
806static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
807{
808 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
809 int shift = kcontrol->private_value;
810
811 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
812 ucontrol->value.enumerated.item[0] << shift, 0);
813}
814
815static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
816{
817 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
818
819 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
820 uinfo->count = 1;
821 uinfo->value.enumerated.items = 3;
822 if (uinfo->value.enumerated.item > 2)
823 uinfo->value.enumerated.item = 2;
824 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
825 return 0;
826}
827
828static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
829{
830 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
831
832 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
833 return 0;
834}
835
836static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
837{
838 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
839
840 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
841 ucontrol->value.enumerated.item[0], 0);
842}
843
844#define STAC9758_OUTPUT_JACK(xname, shift) \
845{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
846 .info = snd_ac97_stac9758_output_jack_info, \
847 .get = snd_ac97_stac9758_output_jack_get, \
848 .put = snd_ac97_stac9758_output_jack_put, \
849 .private_value = shift }
850#define STAC9758_INPUT_JACK(xname, shift) \
851{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
852 .info = snd_ac97_stac9758_input_jack_info, \
853 .get = snd_ac97_stac9758_input_jack_get, \
854 .put = snd_ac97_stac9758_input_jack_put, \
855 .private_value = shift }
856static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = {
857 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
858 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
859 STAC9758_OUTPUT_JACK("Front Jack", 7),
860 STAC9758_OUTPUT_JACK("Rear Jack", 10),
861 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
862 STAC9758_INPUT_JACK("Mic Input Source", 0),
863 STAC9758_INPUT_JACK("Line Input Source", 8),
864 {
865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
866 .name = "Headphone Amp",
867 .info = snd_ac97_stac9758_phonesel_info,
868 .get = snd_ac97_stac9758_phonesel_get,
869 .put = snd_ac97_stac9758_phonesel_put
870 },
871 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
872 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
873};
874
875static int patch_sigmatel_stac9758_specific(ac97_t *ac97)
876{
877 int err;
878
879 err = patch_sigmatel_stac97xx_specific(ac97);
880 if (err < 0)
881 return err;
882 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
883 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
884 if (err < 0)
885 return err;
886 /* DAC-A direct */
887 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
888 /* DAC-A to Mix = PCM */
889 /* DAC-B direct = Surround */
890 /* DAC-B to Mix */
891 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
892 /* DAC-C direct = Center/LFE */
893
894 return 0;
895}
896
897static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
898 .build_3d = patch_sigmatel_stac9700_3d,
899 .build_specific = patch_sigmatel_stac9758_specific
900};
901
902int patch_sigmatel_stac9758(ac97_t * ac97)
903{
904 static unsigned short regs[4] = {
905 AC97_SIGMATEL_OUTSEL,
906 AC97_SIGMATEL_IOMISC,
907 AC97_SIGMATEL_INSEL,
908 AC97_SIGMATEL_VARIOUS
909 };
910 static unsigned short def_regs[4] = {
911 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
912 /* IOMISC */ 0x2001,
913 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
914 /* VARIOUS */ 0x0040
915 };
916 static unsigned short m675_regs[4] = {
917 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
918 /* IOMISC */ 0x2102, /* HP amp on */
919 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
920 /* VARIOUS */ 0x0041 /* stereo mic */
921 };
922 unsigned short *pregs = def_regs;
923 int i;
924
925 /* Gateway M675 notebook */
926 if (ac97->pci &&
927 ac97->subsystem_vendor == 0x107b &&
928 ac97->subsystem_device == 0x0601)
929 pregs = m675_regs;
930
931 // patch for SigmaTel
932 ac97->build_ops = &patch_sigmatel_stac9758_ops;
933 /* FIXME: assume only page 0 for writing cache */
934 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
935 for (i = 0; i < 4; i++)
936 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
937
938 ac97->flags |= AC97_STEREO_MUTES;
939 return 0;
940}
941
942/*
943 * Cirrus Logic CS42xx codecs
944 */
945static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
946 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
947 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
948};
949
950static int patch_cirrus_build_spdif(ac97_t * ac97)
951{
952 int err;
953
954 /* con mask, pro mask, default */
955 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
956 return err;
957 /* switch, spsa */
958 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
959 return err;
960 switch (ac97->id & AC97_ID_CS_MASK) {
961 case AC97_ID_CS4205:
962 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
963 return err;
964 break;
965 }
966 /* set default PCM S/PDIF params */
967 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
968 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
969 return 0;
970}
971
972static struct snd_ac97_build_ops patch_cirrus_ops = {
973 .build_spdif = patch_cirrus_build_spdif
974};
975
976int patch_cirrus_spdif(ac97_t * ac97)
977{
978 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
979 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
980 - sp/dif EA ID is not set, but sp/dif is always present.
981 - enable/disable is spdif register bit 15.
982 - sp/dif control register is 0x68. differs from AC97:
983 - valid is bit 14 (vs 15)
984 - no DRS
985 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
986 - sp/dif ssource select is in 0x5e bits 0,1.
987 */
988
989 ac97->build_ops = &patch_cirrus_ops;
990 ac97->flags |= AC97_CS_SPDIF;
991 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
992 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
993 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
994 return 0;
995}
996
997int patch_cirrus_cs4299(ac97_t * ac97)
998{
999 /* force the detection of PC Beep */
1000 ac97->flags |= AC97_HAS_PC_BEEP;
1001
1002 return patch_cirrus_spdif(ac97);
1003}
1004
1005/*
1006 * Conexant codecs
1007 */
1008static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
1009 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1010};
1011
1012static int patch_conexant_build_spdif(ac97_t * ac97)
1013{
1014 int err;
1015
1016 /* con mask, pro mask, default */
1017 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1018 return err;
1019 /* switch */
1020 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1021 return err;
1022 /* set default PCM S/PDIF params */
1023 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1024 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1025 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1026 return 0;
1027}
1028
1029static struct snd_ac97_build_ops patch_conexant_ops = {
1030 .build_spdif = patch_conexant_build_spdif
1031};
1032
1033int patch_conexant(ac97_t * ac97)
1034{
1035 ac97->build_ops = &patch_conexant_ops;
1036 ac97->flags |= AC97_CX_SPDIF;
1037 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1038 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1039 return 0;
1040}
1041
1042/*
1043 * Analog Device AD18xx, AD19xx codecs
1044 */
1045#ifdef CONFIG_PM
1046static void ad18xx_resume(ac97_t *ac97)
1047{
1048 static unsigned short setup_regs[] = {
1049 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1050 };
1051 int i, codec;
1052
1053 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1054 unsigned short reg = setup_regs[i];
1055 if (test_bit(reg, ac97->reg_accessed)) {
1056 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1057 snd_ac97_read(ac97, reg);
1058 }
1059 }
1060
1061 if (! (ac97->flags & AC97_AD_MULTI))
1062 /* normal restore */
1063 snd_ac97_restore_status(ac97);
1064 else {
1065 /* restore the AD18xx codec configurations */
1066 for (codec = 0; codec < 3; codec++) {
1067 if (! ac97->spec.ad18xx.id[codec])
1068 continue;
1069 /* select single codec */
1070 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1071 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1072 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1073 }
1074 /* select all codecs */
1075 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1076
1077 /* restore status */
1078 for (i = 2; i < 0x7c ; i += 2) {
1079 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1080 continue;
1081 if (test_bit(i, ac97->reg_accessed)) {
1082 /* handle multi codecs for AD18xx */
1083 if (i == AC97_PCM) {
1084 for (codec = 0; codec < 3; codec++) {
1085 if (! ac97->spec.ad18xx.id[codec])
1086 continue;
1087 /* select single codec */
1088 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1089 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1090 /* update PCM bits */
1091 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1092 }
1093 /* select all codecs */
1094 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1095 continue;
1096 } else if (i == AC97_AD_TEST ||
1097 i == AC97_AD_CODEC_CFG ||
1098 i == AC97_AD_SERIAL_CFG)
1099 continue; /* ignore */
1100 }
1101 snd_ac97_write(ac97, i, ac97->regs[i]);
1102 snd_ac97_read(ac97, i);
1103 }
1104 }
1105
1106 snd_ac97_restore_iec958(ac97);
1107}
1108#endif
1109
1110int patch_ad1819(ac97_t * ac97)
1111{
1112 unsigned short scfg;
1113
1114 // patch for Analog Devices
1115 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1116 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1117 return 0;
1118}
1119
1120static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
1121{
1122 unsigned short val;
1123
1124 // test for unchained codec
1125 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1126 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1127 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1128 if ((val & 0xff40) != 0x5340)
1129 return 0;
1130 ac97->spec.ad18xx.unchained[idx] = mask;
1131 ac97->spec.ad18xx.id[idx] = val;
1132 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1133 return mask;
1134}
1135
1136static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
1137{
1138 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1139 unsigned short val;
1140
1141 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1142 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1143 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1144 if ((val & 0xff40) != 0x5340)
1145 return 0;
1146 if (codec_bits)
1147 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1148 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1149 ac97->spec.ad18xx.id[idx] = val;
1150 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1151 return 1;
1152}
1153
1154static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
1155{
1156 // already detected?
1157 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1158 cidx1 = -1;
1159 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1160 cidx2 = -1;
1161 if (cidx1 < 0 && cidx2 < 0)
1162 return;
1163 // test for chained codecs
1164 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1165 ac97->spec.ad18xx.unchained[unchained_idx]);
1166 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1167 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1168 if (cidx1 >= 0) {
1169 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1170 patch_ad1881_chained1(ac97, cidx2, 0);
1171 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1172 patch_ad1881_chained1(ac97, cidx1, 0);
1173 } else if (cidx2 >= 0) {
1174 patch_ad1881_chained1(ac97, cidx2, 0);
1175 }
1176}
1177
1178static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1179#ifdef CONFIG_PM
1180 .resume = ad18xx_resume
1181#endif
1182};
1183
1184int patch_ad1881(ac97_t * ac97)
1185{
1186 static const char cfg_idxs[3][2] = {
1187 {2, 1},
1188 {0, 2},
1189 {0, 1}
1190 };
1191
1192 // patch for Analog Devices
1193 unsigned short codecs[3];
1194 unsigned short val;
1195 int idx, num;
1196
1197 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1198 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1199 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1200 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1201 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1202
1203 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
1204
1205 for (idx = 0; idx < 3; idx++)
1206 if (ac97->spec.ad18xx.unchained[idx])
1207 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1208
1209 if (ac97->spec.ad18xx.id[1]) {
1210 ac97->flags |= AC97_AD_MULTI;
1211 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1212 }
1213 if (ac97->spec.ad18xx.id[2]) {
1214 ac97->flags |= AC97_AD_MULTI;
1215 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1216 }
1217
1218 __end:
1219 /* select all codecs */
1220 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1221 /* check if only one codec is present */
1222 for (idx = num = 0; idx < 3; idx++)
1223 if (ac97->spec.ad18xx.id[idx])
1224 num++;
1225 if (num == 1) {
1226 /* ok, deselect all ID bits */
1227 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1228 ac97->spec.ad18xx.codec_cfg[0] =
1229 ac97->spec.ad18xx.codec_cfg[1] =
1230 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1231 }
1232 /* required for AD1886/AD1885 combination */
1233 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1234 if (ac97->spec.ad18xx.id[0]) {
1235 ac97->id &= 0xffff0000;
1236 ac97->id |= ac97->spec.ad18xx.id[0];
1237 }
1238 ac97->build_ops = &patch_ad1881_build_ops;
1239 return 0;
1240}
1241
1242static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
1243 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1244 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1245 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1246 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1247 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1248 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1249};
1250
1251static int patch_ad1885_specific(ac97_t * ac97)
1252{
1253 int err;
1254
1255 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1256 return err;
1257 return 0;
1258}
1259
1260static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1261 .build_specific = &patch_ad1885_specific,
1262#ifdef CONFIG_PM
1263 .resume = ad18xx_resume
1264#endif
1265};
1266
1267int patch_ad1885(ac97_t * ac97)
1268{
1269 patch_ad1881(ac97);
1270 /* This is required to deal with the Intel D815EEAL2 */
1271 /* i.e. Line out is actually headphone out from codec */
1272
1273 /* set default */
1274 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1275
1276 ac97->build_ops = &patch_ad1885_build_ops;
1277 return 0;
1278}
1279
1280int patch_ad1886(ac97_t * ac97)
1281{
1282 patch_ad1881(ac97);
1283 /* Presario700 workaround */
1284 /* for Jack Sense/SPDIF Register misetting causing */
1285 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1286 return 0;
1287}
1288
1289/* MISC bits */
1290#define AC97_AD198X_MBC 0x0003 /* mic boost */
1291#define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1292#define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1293#define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1294#define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1295#define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1296#define AC97_AD198X_VREF_0 0x000c /* 0V */
1297#define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1298#define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1299#define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1300#define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1301#define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1302#define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1303#define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1304#define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1305#define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1306#define AC97_AD198X_MSPLT 0x2000 /* mute split */
1307#define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1308#define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1309
1310
1311static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1312{
1313 static char *texts[2] = { "AC-Link", "A/D Converter" };
1314
1315 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1316 uinfo->count = 1;
1317 uinfo->value.enumerated.items = 2;
1318 if (uinfo->value.enumerated.item > 1)
1319 uinfo->value.enumerated.item = 1;
1320 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1321 return 0;
1322}
1323
1324static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1325{
1326 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1327 unsigned short val;
1328
1329 val = ac97->regs[AC97_AD_SERIAL_CFG];
1330 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1331 return 0;
1332}
1333
1334static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1335{
1336 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1337 unsigned short val;
1338
1339 if (ucontrol->value.enumerated.item[0] > 1)
1340 return -EINVAL;
1341 val = ucontrol->value.enumerated.item[0] << 2;
1342 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1343}
1344
1345static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
1346 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1347 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1348 .info = snd_ac97_ad198x_spdif_source_info,
1349 .get = snd_ac97_ad198x_spdif_source_get,
1350 .put = snd_ac97_ad198x_spdif_source_put,
1351};
1352
1353static int patch_ad198x_post_spdif(ac97_t * ac97)
1354{
1355 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1356}
1357
1358static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = {
1359 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1360 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1361};
1362
1363static int patch_ad1981a_specific(ac97_t * ac97)
1364{
1365 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1366 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1367}
1368
1369static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1370 .build_post_spdif = patch_ad198x_post_spdif,
1371 .build_specific = patch_ad1981a_specific,
1372#ifdef CONFIG_PM
1373 .resume = ad18xx_resume
1374#endif
1375};
1376
1377static void check_ad1981_hp_jack_sense(ac97_t *ac97)
1378{
1379 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1380 switch (subid) {
1381 case 0x103c0890: /* HP nc6000 */
1382 case 0x103c006d: /* HP nx9105 */
1383 case 0x17340088: /* FSC Scenic-W */
1384 /* enable headphone jack sense */
1385 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1386 break;
1387 }
1388}
1389
1390int patch_ad1981a(ac97_t *ac97)
1391{
1392 patch_ad1881(ac97);
1393 ac97->build_ops = &patch_ad1981a_build_ops;
1394 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1395 ac97->flags |= AC97_STEREO_MUTES;
1396 check_ad1981_hp_jack_sense(ac97);
1397 return 0;
1398}
1399
1400static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
1401AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1402
1403static int patch_ad1981b_specific(ac97_t *ac97)
1404{
1405 int err;
1406
1407 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1408 return err;
1409 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1410 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1411}
1412
1413static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1414 .build_post_spdif = patch_ad198x_post_spdif,
1415 .build_specific = patch_ad1981b_specific,
1416#ifdef CONFIG_PM
1417 .resume = ad18xx_resume
1418#endif
1419};
1420
1421int patch_ad1981b(ac97_t *ac97)
1422{
1423 patch_ad1881(ac97);
1424 ac97->build_ops = &patch_ad1981b_build_ops;
1425 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1426 ac97->flags |= AC97_STEREO_MUTES;
1427 check_ad1981_hp_jack_sense(ac97);
1428 return 0;
1429}
1430
1431static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1432{
1433 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1434 uinfo->count = 1;
1435 uinfo->value.integer.min = 0;
1436 uinfo->value.integer.max = 1;
1437 return 0;
1438}
1439
1440static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1441{
1442 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1443 unsigned short val;
1444
1445 val = ac97->regs[AC97_AD_MISC];
1446 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1447 return 0;
1448}
1449
1450static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1451{
1452 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1453 unsigned short val;
1454
1455 val = !ucontrol->value.integer.value[0]
1456 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1457 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1458 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1459}
1460
1461static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1462{
1463 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1464
1465 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1466 uinfo->count = 1;
1467 uinfo->value.enumerated.items = 3;
1468 if (uinfo->value.enumerated.item > 2)
1469 uinfo->value.enumerated.item = 2;
1470 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1471 return 0;
1472}
1473
1474static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1475{
1476 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1477 unsigned short val;
1478
1479 val = ac97->regs[AC97_AD_MISC];
1480 if (!(val & AC97_AD198X_DMIX1))
1481 ucontrol->value.enumerated.item[0] = 0;
1482 else
1483 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1484 return 0;
1485}
1486
1487static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1488{
1489 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1490 unsigned short val;
1491
1492 if (ucontrol->value.enumerated.item[0] > 2)
1493 return -EINVAL;
1494 if (ucontrol->value.enumerated.item[0] == 0)
1495 val = 0;
1496 else
1497 val = AC97_AD198X_DMIX1 |
1498 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1499 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1500 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1501}
1502
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001503static void ad1888_update_jacks(ac97_t *ac97)
1504{
1505 /* shared Line-In */
1506 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1507 is_shared_linein(ac97) ? 0 : 1 << 12);
1508 /* shared Mic */
1509 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
Clemens Ladisch32964802005-05-10 14:48:37 +02001510 is_shared_micin(ac97) ? 0 : 1 << 11);
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001511}
1512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
1514 {
1515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1516 .name = "Exchange Front/Surround",
1517 .info = snd_ac97_ad1888_lohpsel_info,
1518 .get = snd_ac97_ad1888_lohpsel_get,
1519 .put = snd_ac97_ad1888_lohpsel_put
1520 },
1521 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1522 {
1523 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1524 .name = "Downmix",
1525 .info = snd_ac97_ad1888_downmix_info,
1526 .get = snd_ac97_ad1888_downmix_get,
1527 .put = snd_ac97_ad1888_downmix_put
1528 },
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001529#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC, 12, 1, 0),
1531 AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC, 11, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001532#else
1533 AC97_SURROUND_JACK_MODE_CTL,
1534 AC97_CHANNEL_MODE_CTL,
1535#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536};
1537
1538static int patch_ad1888_specific(ac97_t *ac97)
1539{
1540 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1541 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1542 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1543 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1544}
1545
1546static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1547 .build_post_spdif = patch_ad198x_post_spdif,
1548 .build_specific = patch_ad1888_specific,
1549#ifdef CONFIG_PM
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001550 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001552 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553};
1554
1555int patch_ad1888(ac97_t * ac97)
1556{
1557 unsigned short misc;
1558
1559 patch_ad1881(ac97);
1560 ac97->build_ops = &patch_ad1888_build_ops;
1561 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1562 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1563 /* AD-compatible mode */
1564 /* Stereo mutes enabled */
1565 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1566 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1567 AC97_AD198X_LOSEL |
1568 AC97_AD198X_HPSEL |
1569 AC97_AD198X_MSPLT |
1570 AC97_AD198X_AC97NC);
1571 ac97->flags |= AC97_STEREO_MUTES;
1572 return 0;
1573}
1574
1575static int patch_ad1980_specific(ac97_t *ac97)
1576{
1577 int err;
1578
1579 if ((err = patch_ad1888_specific(ac97)) < 0)
1580 return err;
1581 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1582}
1583
1584static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1585 .build_post_spdif = patch_ad198x_post_spdif,
1586 .build_specific = patch_ad1980_specific,
1587#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001588 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001590 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591};
1592
1593int patch_ad1980(ac97_t * ac97)
1594{
1595 patch_ad1888(ac97);
1596 ac97->build_ops = &patch_ad1980_build_ops;
1597 return 0;
1598}
1599
1600static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1601 AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG, 9, 1, 0),
1602 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1603};
1604
1605static int patch_ad1985_specific(ac97_t *ac97)
1606{
1607 int err;
1608
1609 if ((err = patch_ad1980_specific(ac97)) < 0)
1610 return err;
1611 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1612}
1613
1614static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1615 .build_post_spdif = patch_ad198x_post_spdif,
1616 .build_specific = patch_ad1985_specific,
1617#ifdef CONFIG_PM
Clemens Ladisch462c4172005-05-10 14:50:31 +02001618 .resume = ad18xx_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619#endif
Clemens Ladisch462c4172005-05-10 14:50:31 +02001620 .update_jacks = ad1888_update_jacks,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621};
1622
1623int patch_ad1985(ac97_t * ac97)
1624{
1625 unsigned short misc;
1626
1627 patch_ad1881(ac97);
1628 ac97->build_ops = &patch_ad1985_build_ops;
1629 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1630 /* switch front/surround line-out/hp-out */
1631 /* center/LFE, mic in 3.75V mode */
1632 /* AD-compatible mode */
1633 /* Stereo mutes enabled */
1634 /* in accordance with ADI driver: misc | 0x5c28 */
1635 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1636 AC97_AD198X_VREFH |
1637 AC97_AD198X_LOSEL |
1638 AC97_AD198X_HPSEL |
1639 AC97_AD198X_CLDIS |
1640 AC97_AD198X_LODIS |
1641 AC97_AD198X_MSPLT |
1642 AC97_AD198X_AC97NC);
1643 ac97->flags |= AC97_STEREO_MUTES;
1644 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1645 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1646 return 0;
1647}
1648
1649/*
1650 * realtek ALC65x/850 codecs
1651 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001652static void alc650_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001654 int shared;
1655
1656 /* shared Line-In */
1657 shared = is_shared_linein(ac97);
1658 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1659 shared ? (1 << 9) : 0);
1660 /* update shared Mic */
1661 shared = is_shared_micin(ac97);
1662 /* disable/enable vref */
1663 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1664 shared ? (1 << 12) : 0);
1665 /* turn on/off center-on-mic */
1666 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1667 shared ? (1 << 10) : 0);
1668 /* GPIO0 high for mic */
1669 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1670 shared ? 0 : 0x100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
1672
1673static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1674 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1675 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1676 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1677 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1678 /* 4: Analog Input To Surround */
1679 /* 5: Analog Input To Center/LFE */
1680 /* 6: Independent Master Volume Right */
1681 /* 7: Independent Master Volume Left */
1682 /* 8: reserved */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001683 /* 9: Line-In/Surround share */
1684 /* 10: Mic/CLFE share */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 /* 11-13: in IEC958 controls */
1686 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1687#if 0 /* always set in patch_alc650 */
1688 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1689 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1690 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1691 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1692 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1693 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1694#endif
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001695 AC97_SURROUND_JACK_MODE_CTL,
1696 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697};
1698
1699static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1700 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1701 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1702 /* disable this controls since it doesn't work as expected */
1703 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
1704};
1705
1706static int patch_alc650_specific(ac97_t * ac97)
1707{
1708 int err;
1709
1710 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1711 return err;
1712 if (ac97->ext_id & AC97_EI_SPDIF) {
1713 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1714 return err;
1715 }
1716 return 0;
1717}
1718
1719static struct snd_ac97_build_ops patch_alc650_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001720 .build_specific = patch_alc650_specific,
1721 .update_jacks = alc650_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722};
1723
1724int patch_alc650(ac97_t * ac97)
1725{
1726 unsigned short val;
1727
1728 ac97->build_ops = &patch_alc650_ops;
1729
1730 /* determine the revision */
1731 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
1732 if (val < 3)
1733 ac97->id = 0x414c4720; /* Old version */
1734 else if (val < 0x10)
1735 ac97->id = 0x414c4721; /* D version */
1736 else if (val < 0x20)
1737 ac97->id = 0x414c4722; /* E version */
1738 else if (val < 0x30)
1739 ac97->id = 0x414c4723; /* F version */
1740
1741 /* revision E or F */
1742 /* FIXME: what about revision D ? */
1743 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
1744 ac97->id == 0x414c4723);
1745
1746 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1747 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1748 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
1749
1750 /* Enable SPDIF-IN only on Rev.E and above */
1751 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
1752 /* SPDIF IN with pin 47 */
1753 if (ac97->spec.dev_flags)
1754 val |= 0x03; /* enable */
1755 else
1756 val &= ~0x03; /* disable */
1757 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
1758
1759 /* set default: slot 3,4,7,8,6,9
1760 spdif-in monitor off, analog-spdif off, spdif-in off
1761 center on mic off, surround on line-in off
1762 downmix off, duplicate front off
1763 */
1764 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
1765
1766 /* set GPIO0 for mic bias */
1767 /* GPIO0 pin output, no interrupt, high */
1768 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
1769 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
1770 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1771 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
1772
1773 /* full DAC volume */
1774 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1775 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1776 return 0;
1777}
1778
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001779static void alc655_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001781 int shared;
1782
1783 /* shared Line-In */
1784 shared = is_shared_linein(ac97);
1785 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
1786 shared ? (1 << 9) : 0, 0);
1787 /* update shared mic */
1788 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 /* misc control; vrefout disable */
1790 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001791 shared ? (1 << 12) : 0);
1792 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
1793 shared ? (1 << 10) : 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794}
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
1797 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001798 AC97_SURROUND_JACK_MODE_CTL,
1799 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800};
1801
1802static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1803{
1804 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
1805 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1806 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1807
1808 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1809 uinfo->count = 1;
1810 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
1811 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1812 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1813 strcpy(uinfo->value.enumerated.name,
1814 ac97->spec.dev_flags ?
1815 texts_658[uinfo->value.enumerated.item] :
1816 texts_655[uinfo->value.enumerated.item]);
1817 return 0;
1818}
1819
1820static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1821{
1822 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1823 unsigned short val;
1824
1825 val = ac97->regs[AC97_ALC650_MULTICH];
1826 val = (val >> 12) & 3;
1827 if (ac97->spec.dev_flags && val == 3)
1828 val = 0;
1829 ucontrol->value.enumerated.item[0] = val;
1830 return 0;
1831}
1832
1833static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1834{
1835 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1836
1837 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
1838 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
1839 0);
1840}
1841
1842static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
1843 AC97_PAGE_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0, 0),
1844 /* disable this controls since it doesn't work as expected */
1845 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
1846 {
1847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1848 .name = "IEC958 Playback Route",
1849 .info = alc655_iec958_route_info,
1850 .get = alc655_iec958_route_get,
1851 .put = alc655_iec958_route_put,
1852 },
1853};
1854
1855static int patch_alc655_specific(ac97_t * ac97)
1856{
1857 int err;
1858
1859 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
1860 return err;
1861 if (ac97->ext_id & AC97_EI_SPDIF) {
1862 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1863 return err;
1864 }
1865 return 0;
1866}
1867
1868static struct snd_ac97_build_ops patch_alc655_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001869 .build_specific = patch_alc655_specific,
1870 .update_jacks = alc655_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871};
1872
1873int patch_alc655(ac97_t * ac97)
1874{
1875 unsigned int val;
1876
1877 ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
1878
1879 ac97->build_ops = &patch_alc655_ops;
1880
1881 /* assume only page 0 for writing cache */
1882 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1883
1884 /* adjust default values */
1885 val = snd_ac97_read(ac97, 0x7a); /* misc control */
1886 if (ac97->id == 0x414c4780) /* ALC658 */
1887 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
1888 else /* ALC655 */
1889 val |= (1 << 1); /* Pin 47 is spdif input pin */
1890 val &= ~(1 << 12); /* vref enable */
1891 snd_ac97_write_cache(ac97, 0x7a, val);
1892 /* set default: spdif-in enabled,
1893 spdif-in monitor off, spdif-in PCM off
1894 center on mic off, surround on line-in off
1895 duplicate front off
1896 */
1897 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1898
1899 /* full DAC volume */
1900 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1901 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1902 return 0;
1903}
1904
1905
1906#define AC97_ALC850_JACK_SELECT 0x76
1907#define AC97_ALC850_MISC1 0x7a
1908
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001909static void alc850_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001911 int shared;
1912
1913 /* shared Line-In */
1914 shared = is_shared_linein(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 /* SURR 1kOhm (bit4), Amp (bit5) */
1916 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001917 shared ? (1<<5) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 /* LINE-IN = 0, SURROUND = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001919 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
1920 shared ? (2<<12) : (0<<12));
1921 /* update shared mic */
1922 shared = is_shared_micin(ac97);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 /* Vref disable (bit12), 1kOhm (bit13) */
1924 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001925 shared ? (1<<12) : (1<<13));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 /* MIC-IN = 1, CENTER-LFE = 2 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001927 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
1928 shared ? (2<<4) : (1<<4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
1931static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = {
1932 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
Sergey Vlasov67e1b512005-04-25 11:34:33 +02001933 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001934 AC97_SURROUND_JACK_MODE_CTL,
1935 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936};
1937
1938static int patch_alc850_specific(ac97_t *ac97)
1939{
1940 int err;
1941
1942 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
1943 return err;
1944 if (ac97->ext_id & AC97_EI_SPDIF) {
1945 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1946 return err;
1947 }
1948 return 0;
1949}
1950
1951static struct snd_ac97_build_ops patch_alc850_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001952 .build_specific = patch_alc850_specific,
1953 .update_jacks = alc850_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954};
1955
1956int patch_alc850(ac97_t *ac97)
1957{
1958 ac97->build_ops = &patch_alc850_ops;
1959
1960 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
1961
1962 /* assume only page 0 for writing cache */
1963 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1964
1965 /* adjust default values */
1966 /* set default: spdif-in enabled,
1967 spdif-in monitor off, spdif-in PCM off
1968 center on mic off, surround on line-in off
1969 duplicate front off
1970 */
1971 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1972 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
1973 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
1974 */
1975 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
1976 (1<<7)|(0<<12)|(1<<13)|(0<<14));
1977 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
1978 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
1979 */
1980 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
1981 (1<<11)|(0<<12)|(1<<15));
1982
1983 /* full DAC volume */
1984 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1985 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1986 return 0;
1987}
1988
1989
1990/*
1991 * C-Media CM97xx codecs
1992 */
Takashi Iwaieb8caf32005-04-13 14:32:57 +02001993static void cm9738_update_jacks(ac97_t *ac97)
1994{
1995 /* shared Line-In */
1996 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
1997 is_shared_linein(ac97) ? (1 << 10) : 0);
1998}
1999
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002002 AC97_SURROUND_JACK_MODE_CTL,
2003 AC97_CHANNEL_MODE_4CH_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004};
2005
2006static int patch_cm9738_specific(ac97_t * ac97)
2007{
2008 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2009}
2010
2011static struct snd_ac97_build_ops patch_cm9738_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002012 .build_specific = patch_cm9738_specific,
2013 .update_jacks = cm9738_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014};
2015
2016int patch_cm9738(ac97_t * ac97)
2017{
2018 ac97->build_ops = &patch_cm9738_ops;
2019 /* FIXME: can anyone confirm below? */
2020 /* CM9738 has no PCM volume although the register reacts */
2021 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2022 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2023
2024 return 0;
2025}
2026
2027static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2028{
2029 static char *texts[] = { "Analog", "Digital" };
2030
2031 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2032 uinfo->count = 1;
2033 uinfo->value.enumerated.items = 2;
2034 if (uinfo->value.enumerated.item > 1)
2035 uinfo->value.enumerated.item = 1;
2036 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2037 return 0;
2038}
2039
2040static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2041{
2042 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2043 unsigned short val;
2044
2045 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2046 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2047 return 0;
2048}
2049
2050static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2051{
2052 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2053
2054 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2055 0x01 << 1,
2056 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2057}
2058
2059static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
2060 /* BIT 0: SPDI_EN - always true */
2061 { /* BIT 1: SPDIFS */
2062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2063 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2064 .info = snd_ac97_cmedia_spdif_playback_source_info,
2065 .get = snd_ac97_cmedia_spdif_playback_source_get,
2066 .put = snd_ac97_cmedia_spdif_playback_source_put,
2067 },
2068 /* BIT 2: IG_SPIV */
2069 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2070 /* BIT 3: SPI2F */
2071 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2072 /* BIT 4: SPI2SDI */
2073 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2074 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2075};
2076
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002077static void cm9739_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002079 /* shared Line-In */
2080 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2081 is_shared_linein(ac97) ? (1 << 10) : 0);
2082 /* shared Mic */
2083 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2084 is_shared_micin(ac97) ? 0x1000 : 0x2000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
2086
2087static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002088 AC97_SURROUND_JACK_MODE_CTL,
2089 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090};
2091
2092static int patch_cm9739_specific(ac97_t * ac97)
2093{
2094 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2095}
2096
2097static int patch_cm9739_post_spdif(ac97_t * ac97)
2098{
2099 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2100}
2101
2102static struct snd_ac97_build_ops patch_cm9739_ops = {
2103 .build_specific = patch_cm9739_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002104 .build_post_spdif = patch_cm9739_post_spdif,
2105 .update_jacks = cm9739_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106};
2107
2108int patch_cm9739(ac97_t * ac97)
2109{
2110 unsigned short val;
2111
2112 ac97->build_ops = &patch_cm9739_ops;
2113
2114 /* CM9739/A has no Master and PCM volume although the register reacts */
2115 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2116 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2117 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2118
2119 /* check spdif */
2120 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2121 if (val & AC97_EA_SPCV) {
2122 /* enable spdif in */
2123 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2124 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2125 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2126 } else {
2127 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2128 ac97->rates[AC97_RATES_SPDIF] = 0;
2129 }
2130
2131 /* set-up multi channel */
2132 /* bit 14: 0 = SPDIF, 1 = EAPD */
2133 /* bit 13: enable internal vref output for mic */
2134 /* bit 12: disable center/lfe (swithable) */
2135 /* bit 10: disable surround/line (switchable) */
2136 /* bit 9: mix 2 surround off */
2137 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2138 /* bit 3: undocumented; surround? */
2139 /* bit 0: dB */
2140 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2141 val |= (1 << 3);
2142 val |= (1 << 13);
2143 if (! (ac97->ext_id & AC97_EI_SPDIF))
2144 val |= (1 << 14);
2145 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2146
2147 /* FIXME: set up GPIO */
2148 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2149 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2150 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2151 if (ac97->pci &&
2152 ac97->subsystem_vendor == 0x1043 &&
2153 ac97->subsystem_device == 0x1843) {
2154 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2155 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2156 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2157 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2158 }
2159
2160 return 0;
2161}
2162
2163#define AC97_CM9761_MULTI_CHAN 0x64
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002164#define AC97_CM9761_FUNC 0x66
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165#define AC97_CM9761_SPDIF_CTRL 0x6c
2166
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002167static void cm9761_update_jacks(ac97_t *ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002169 unsigned short surr_vals[2][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 { 0x0008, 0x0400 }, /* off, on */
2171 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */
2172 };
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002173 unsigned short clfe_vals[2][2] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 { 0x2000, 0x1880 }, /* off, on */
2175 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */
2176 };
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002177
2178 /* shared Line-In */
2179 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408,
2180 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]);
2181 /* shared Mic */
2182 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880,
2183 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
2186static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002187 AC97_SURROUND_JACK_MODE_CTL,
2188 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189};
2190
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002191static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2192{
2193 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2194
2195 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2196 uinfo->count = 1;
2197 uinfo->value.enumerated.items = 3;
2198 if (uinfo->value.enumerated.item > 2)
2199 uinfo->value.enumerated.item = 2;
2200 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2201 return 0;
2202}
2203
2204static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2205{
2206 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2207
2208 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2209 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2210 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2211 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2212 else
2213 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2214 return 0;
2215}
2216
2217static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2218{
2219 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2220
2221 if (ucontrol->value.enumerated.item[0] == 2)
2222 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2223 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2224 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2225 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2226}
2227
2228static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2229static const struct ac97_enum cm9761_dac_clock_enum =
2230 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2231
2232static const snd_kcontrol_new_t snd_ac97_cm9761_controls_spdif[] = {
2233 { /* BIT 1: SPDIFS */
2234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2235 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2236 .info = cm9761_spdif_out_source_info,
2237 .get = cm9761_spdif_out_source_get,
2238 .put = cm9761_spdif_out_source_put,
2239 },
2240 /* BIT 2: IG_SPIV */
2241 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2242 /* BIT 3: SPI2F */
2243 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2244 /* BIT 4: SPI2SDI */
2245 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2246 /* BIT 9-10: DAC_CTL */
2247 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2248};
2249
2250static int patch_cm9761_post_spdif(ac97_t * ac97)
2251{
2252 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2253}
2254
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255static int patch_cm9761_specific(ac97_t * ac97)
2256{
2257 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2258}
2259
2260static struct snd_ac97_build_ops patch_cm9761_ops = {
2261 .build_specific = patch_cm9761_specific,
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002262 .build_post_spdif = patch_cm9761_post_spdif,
2263 .update_jacks = cm9761_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264};
2265
2266int patch_cm9761(ac97_t *ac97)
2267{
2268 unsigned short val;
2269
2270 /* CM9761 has no PCM volume although the register reacts */
2271 /* Master volume seems to have _some_ influence on the analog
2272 * input sounds
2273 */
2274 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2275 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2276 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2277
2278 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */
2279 if (ac97->id == AC97_ID_CM9761_82) {
2280 unsigned short tmp;
2281 /* check page 1, reg 0x60 */
2282 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2283 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2284 tmp = snd_ac97_read(ac97, 0x60);
2285 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2286 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2287 }
2288
2289 ac97->build_ops = &patch_cm9761_ops;
2290
2291 /* enable spdif */
2292 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2293 ac97->ext_id |= AC97_EI_SPDIF;
2294 /* to be sure: we overwrite the ext status bits */
2295 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2296 /* Don't set 0x0200 here. This results in the silent analog output */
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002297 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2299
2300 /* set-up multi channel */
2301 /* bit 15: pc master beep off
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002302 * bit 14: pin47 = EAPD/SPDIF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 * bit 13: vref ctl [= cm9739]
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002304 * bit 12: CLFE control (reverted on rev B)
2305 * bit 11: Mic/center share (reverted on rev B)
2306 * bit 10: suddound/line share
2307 * bit 9: Analog-in mix -> surround
2308 * bit 8: Analog-in mix -> CLFE
2309 * bit 7: Mic/LFE share (mic/center/lfe)
2310 * bit 5: vref select (9761A)
2311 * bit 4: front control
2312 * bit 3: surround control (revereted with rev B)
2313 * bit 2: front mic
2314 * bit 1: stereo mic
2315 * bit 0: mic boost level (0=20dB, 1=30dB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 */
2317
2318#if 0
2319 if (ac97->spec.dev_flags)
2320 val = 0x0214;
2321 else
2322 val = 0x321c;
2323#endif
2324 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2325 val |= (1 << 4); /* front on */
2326 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2327
2328 /* FIXME: set up GPIO */
2329 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2330 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2331
2332 return 0;
2333}
2334
Takashi Iwai5f0dccf2005-04-07 15:53:20 +02002335#define AC97_CM9780_SIDE 0x60
2336#define AC97_CM9780_JACK 0x62
2337#define AC97_CM9780_MIXER 0x64
2338#define AC97_CM9780_MULTI_CHAN 0x66
2339#define AC97_CM9780_SPDIF 0x6c
2340
2341static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2342static const struct ac97_enum cm9780_ch_select_enum =
2343 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2344static const snd_kcontrol_new_t cm9780_controls[] = {
2345 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2346 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2347 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2348};
2349
2350static int patch_cm9780_specific(ac97_t *ac97)
2351{
2352 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2353}
2354
2355static struct snd_ac97_build_ops patch_cm9780_ops = {
2356 .build_specific = patch_cm9780_specific,
2357 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2358};
2359
2360int patch_cm9780(ac97_t *ac97)
2361{
2362 unsigned short val;
2363
2364 ac97->build_ops = &patch_cm9780_ops;
2365
2366 /* enable spdif */
2367 if (ac97->ext_id & AC97_EI_SPDIF) {
2368 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2369 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2370 val |= 0x1; /* SPDI_EN */
2371 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2372 }
2373
2374 return 0;
2375}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377/*
2378 * VIA VT1616 codec
2379 */
2380static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
2381AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2382AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2383AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2384AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2385};
2386
2387static int patch_vt1616_specific(ac97_t * ac97)
2388{
2389 int err;
2390
2391 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2392 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2393 return err;
2394 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2395 return err;
2396 return 0;
2397}
2398
2399static struct snd_ac97_build_ops patch_vt1616_ops = {
2400 .build_specific = patch_vt1616_specific
2401};
2402
2403int patch_vt1616(ac97_t * ac97)
2404{
2405 ac97->build_ops = &patch_vt1616_ops;
2406 return 0;
2407}
2408
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002409/*
2410 */
2411static void it2646_update_jacks(ac97_t *ac97)
2412{
2413 /* shared Line-In */
2414 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2415 is_shared_linein(ac97) ? (1<<9) : 0);
2416 /* shared Mic */
2417 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2418 is_shared_micin(ac97) ? (1<<10) : 0);
2419}
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002422 AC97_SURROUND_JACK_MODE_CTL,
2423 AC97_CHANNEL_MODE_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424};
2425
2426static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
2427 AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
2428 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2429 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2430};
2431
2432static int patch_it2646_specific(ac97_t * ac97)
2433{
2434 int err;
2435 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2436 return err;
2437 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2438 return err;
2439 return 0;
2440}
2441
2442static struct snd_ac97_build_ops patch_it2646_ops = {
Takashi Iwaieb8caf32005-04-13 14:32:57 +02002443 .build_specific = patch_it2646_specific,
2444 .update_jacks = it2646_update_jacks
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445};
2446
2447int patch_it2646(ac97_t * ac97)
2448{
2449 ac97->build_ops = &patch_it2646_ops;
2450 /* full DAC volume */
2451 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2452 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2453 return 0;
2454}
2455
2456/* Si3036/8 specific registers */
2457#define AC97_SI3036_CHIP_ID 0x5a
2458
2459int mpatch_si3036(ac97_t * ac97)
2460{
2461 //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
2462 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2463 snd_ac97_write_cache(ac97, 0x68, 0);
2464 return 0;
2465}