blob: 26540972ee787d13b6c76f69a9229258777dd758 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002 * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
35
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
64 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
65
Ingo Molnar62932df2006-01-16 16:34:20 +010066 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020067 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010068
69 /* dynamic controls, init_verbs and input_mux */
70 struct auto_pin_cfg autocfg;
71 unsigned int num_kctl_alloc, num_kctl_used;
72 struct snd_kcontrol_new *kctl_alloc;
73 struct hda_input_mux private_imux;
74 hda_nid_t private_dac_nids[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020077/*
78 * input MUX handling (common part)
79 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010080static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020081{
82 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
83 struct ad198x_spec *spec = codec->spec;
84
85 return snd_hda_input_mux_info(spec->input_mux, uinfo);
86}
87
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010088static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020089{
90 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
91 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010092 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020093
Takashi Iwai985be542005-11-02 18:26:49 +010094 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020095 return 0;
96}
97
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010098static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
104 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100105 spec->capsrc_nids[adc_idx],
106 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200107}
108
109/*
110 * initialization (common callbacks)
111 */
112static int ad198x_init(struct hda_codec *codec)
113{
114 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100115 int i;
116
117 for (i = 0; i < spec->num_init_verbs; i++)
118 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200119 return 0;
120}
121
122static int ad198x_build_controls(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200126 int err;
127
Takashi Iwai985be542005-11-02 18:26:49 +0100128 for (i = 0; i < spec->num_mixers; i++) {
129 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
130 if (err < 0)
131 return err;
132 }
133 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200134 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100135 if (err < 0)
136 return err;
137 }
138 if (spec->dig_in_nid) {
139 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
140 if (err < 0)
141 return err;
142 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200143 return 0;
144}
145
146/*
147 * Analog playback callbacks
148 */
149static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100151 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200152{
153 struct ad198x_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
155}
156
157static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 unsigned int stream_tag,
160 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100161 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200162{
163 struct ad198x_spec *spec = codec->spec;
164 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
165 format, substream);
166}
167
168static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100170 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200171{
172 struct ad198x_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
174}
175
176/*
177 * Digital out
178 */
179static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100181 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200182{
183 struct ad198x_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
185}
186
187static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100189 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200190{
191 struct ad198x_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
193}
194
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200195static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
196 struct hda_codec *codec,
197 unsigned int stream_tag,
198 unsigned int format,
199 struct snd_pcm_substream *substream)
200{
201 struct ad198x_spec *spec = codec->spec;
202 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
203 format, substream);
204}
205
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200206/*
207 * Analog capture
208 */
209static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
210 struct hda_codec *codec,
211 unsigned int stream_tag,
212 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100213 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200214{
215 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100216 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
217 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200218 return 0;
219}
220
221static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100223 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200224{
225 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100226 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
227 0, 0, 0);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200228 return 0;
229}
230
231
232/*
233 */
234static struct hda_pcm_stream ad198x_pcm_analog_playback = {
235 .substreams = 1,
236 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100237 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200238 .nid = 0, /* fill later */
239 .ops = {
240 .open = ad198x_playback_pcm_open,
241 .prepare = ad198x_playback_pcm_prepare,
242 .cleanup = ad198x_playback_pcm_cleanup
243 },
244};
245
246static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100247 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200248 .channels_min = 2,
249 .channels_max = 2,
250 .nid = 0, /* fill later */
251 .ops = {
252 .prepare = ad198x_capture_pcm_prepare,
253 .cleanup = ad198x_capture_pcm_cleanup
254 },
255};
256
257static struct hda_pcm_stream ad198x_pcm_digital_playback = {
258 .substreams = 1,
259 .channels_min = 2,
260 .channels_max = 2,
261 .nid = 0, /* fill later */
262 .ops = {
263 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200264 .close = ad198x_dig_playback_pcm_close,
265 .prepare = ad198x_dig_playback_pcm_prepare
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200266 },
267};
268
Takashi Iwai985be542005-11-02 18:26:49 +0100269static struct hda_pcm_stream ad198x_pcm_digital_capture = {
270 .substreams = 1,
271 .channels_min = 2,
272 .channels_max = 2,
273 /* NID is set in alc_build_pcms */
274};
275
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200276static int ad198x_build_pcms(struct hda_codec *codec)
277{
278 struct ad198x_spec *spec = codec->spec;
279 struct hda_pcm *info = spec->pcm_rec;
280
281 codec->num_pcms = 1;
282 codec->pcm_info = info;
283
284 info->name = "AD198x Analog";
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
288 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100289 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
290 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200291
292 if (spec->multiout.dig_out_nid) {
293 info++;
294 codec->num_pcms++;
295 info->name = "AD198x Digital";
296 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
297 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100298 if (spec->dig_in_nid) {
299 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
300 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
301 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200302 }
303
304 return 0;
305}
306
307static void ad198x_free(struct hda_codec *codec)
308{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100309 struct ad198x_spec *spec = codec->spec;
310 unsigned int i;
311
312 if (spec->kctl_alloc) {
313 for (i = 0; i < spec->num_kctl_used; i++)
314 kfree(spec->kctl_alloc[i].name);
315 kfree(spec->kctl_alloc);
316 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200317 kfree(codec->spec);
318}
319
320#ifdef CONFIG_PM
321static int ad198x_resume(struct hda_codec *codec)
322{
323 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100324 int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200325
Takashi Iwai18a815d2006-03-01 19:54:39 +0100326 codec->patch_ops.init(codec);
Takashi Iwai985be542005-11-02 18:26:49 +0100327 for (i = 0; i < spec->num_mixers; i++)
328 snd_hda_resume_ctls(codec, spec->mixers[i]);
329 if (spec->multiout.dig_out_nid)
330 snd_hda_resume_spdif_out(codec);
331 if (spec->dig_in_nid)
332 snd_hda_resume_spdif_in(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200333 return 0;
334}
335#endif
336
337static struct hda_codec_ops ad198x_patch_ops = {
338 .build_controls = ad198x_build_controls,
339 .build_pcms = ad198x_build_pcms,
340 .init = ad198x_init,
341 .free = ad198x_free,
342#ifdef CONFIG_PM
343 .resume = ad198x_resume,
344#endif
345};
346
347
348/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100349 * EAPD control
350 * the private value = nid | (invert << 8)
351 */
352static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_info *uinfo)
354{
355 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
356 uinfo->count = 1;
357 uinfo->value.integer.min = 0;
358 uinfo->value.integer.max = 1;
359 return 0;
360}
361
362static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol)
364{
365 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366 struct ad198x_spec *spec = codec->spec;
367 int invert = (kcontrol->private_value >> 8) & 1;
368 if (invert)
369 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
370 else
371 ucontrol->value.integer.value[0] = spec->cur_eapd;
372 return 0;
373}
374
375static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
376 struct snd_ctl_elem_value *ucontrol)
377{
378 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
379 struct ad198x_spec *spec = codec->spec;
380 int invert = (kcontrol->private_value >> 8) & 1;
381 hda_nid_t nid = kcontrol->private_value & 0xff;
382 unsigned int eapd;
383 eapd = ucontrol->value.integer.value[0];
384 if (invert)
385 eapd = !eapd;
386 if (eapd == spec->cur_eapd && ! codec->in_resume)
387 return 0;
388 spec->cur_eapd = eapd;
389 snd_hda_codec_write(codec, nid,
390 0, AC_VERB_SET_EAPD_BTLENABLE,
391 eapd ? 0x02 : 0x00);
392 return 1;
393}
394
Takashi Iwai9230d212006-03-13 13:49:49 +0100395static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_info *uinfo);
397static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol);
399static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
400 struct snd_ctl_elem_value *ucontrol);
401
402
Takashi Iwai18a815d2006-03-01 19:54:39 +0100403/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200404 * AD1986A specific
405 */
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define AD1986A_SPDIF_OUT 0x02
408#define AD1986A_FRONT_DAC 0x03
409#define AD1986A_SURR_DAC 0x04
410#define AD1986A_CLFE_DAC 0x05
411#define AD1986A_ADC 0x06
412
413static hda_nid_t ad1986a_dac_nids[3] = {
414 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
415};
Takashi Iwai985be542005-11-02 18:26:49 +0100416static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100417static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419static struct hda_input_mux ad1986a_capture_source = {
420 .num_items = 7,
421 .items = {
422 { "Mic", 0x0 },
423 { "CD", 0x1 },
424 { "Aux", 0x3 },
425 { "Line", 0x4 },
426 { "Mix", 0x5 },
427 { "Mono", 0x6 },
428 { "Phone", 0x7 },
429 },
430};
431
432/*
433 * PCM control
434 *
435 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
436 */
437
438#define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
439
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100440static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200443 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Ingo Molnar62932df2006-01-16 16:34:20 +0100445 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100447 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return 0;
449}
450
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100451static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
453 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200454 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 int i, change = 0;
456
Ingo Molnar62932df2006-01-16 16:34:20 +0100457 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
459 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
460 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
461 }
462 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100463 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return change;
465}
466
Takashi Iwaiead9b7c2005-06-08 14:48:19 +0200467#define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100469static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200472 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Ingo Molnar62932df2006-01-16 16:34:20 +0100474 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100476 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return 0;
478}
479
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100480static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200483 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 int i, change = 0;
485
Ingo Molnar62932df2006-01-16 16:34:20 +0100486 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
488 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
489 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
490 }
491 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100492 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 return change;
494}
495
496/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * mixers
498 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100499static struct snd_kcontrol_new ad1986a_mixers[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 {
501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
502 .name = "PCM Playback Volume",
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200503 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
504 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
505 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .info = ad1986a_pcm_amp_vol_info,
507 .get = ad1986a_pcm_amp_vol_get,
508 .put = ad1986a_pcm_amp_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200509 .tlv = { .c = snd_hda_mixer_amp_tlv },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
511 },
512 {
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
514 .name = "PCM Playback Switch",
515 .info = ad1986a_pcm_amp_sw_info,
516 .get = ad1986a_pcm_amp_sw_get,
517 .put = ad1986a_pcm_amp_sw_put,
518 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
519 },
520 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
525 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
526 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
529 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
530 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
531 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
532 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
533 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
534 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
535 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
536 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
537 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100538 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
540 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
541 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
542 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
543 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
544 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
545 {
546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
547 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200548 .info = ad198x_mux_enum_info,
549 .get = ad198x_mux_enum_get,
550 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
553 { } /* end */
554};
555
Takashi Iwai9230d212006-03-13 13:49:49 +0100556/* additional mixers for 3stack mode */
557static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
558 {
559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560 .name = "Channel Mode",
561 .info = ad198x_ch_mode_info,
562 .get = ad198x_ch_mode_get,
563 .put = ad198x_ch_mode_put,
564 },
565 { } /* end */
566};
567
568/* laptop model - 2ch only */
569static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
570
571static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
572 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
574 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
575 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
576 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
578 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
580 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
581 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
582 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
583 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
584 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
585 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100586 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai9230d212006-03-13 13:49:49 +0100587 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
588 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
589 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
590 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
591 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
592 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
593 {
594 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
595 .name = "Capture Source",
596 .info = ad198x_mux_enum_info,
597 .get = ad198x_mux_enum_get,
598 .put = ad198x_mux_enum_put,
599 },
600 { } /* end */
601};
602
Takashi Iwai825aa972006-03-17 10:50:49 +0100603/* laptop-eapd model - 2ch only */
604
605/* master controls both pins 0x1a and 0x1b */
606static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 long *valp = ucontrol->value.integer.value;
611 int change;
612
613 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
614 0x7f, valp[0] & 0x7f);
615 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
616 0x7f, valp[1] & 0x7f);
617 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
618 0x7f, valp[0] & 0x7f);
619 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
620 0x7f, valp[1] & 0x7f);
621 return change;
622}
623
624static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_value *ucontrol)
626{
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 long *valp = ucontrol->value.integer.value;
629 int change;
630
631 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
632 0x80, valp[0] ? 0 : 0x80);
633 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
634 0x80, valp[1] ? 0 : 0x80);
635 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
636 0x80, valp[0] ? 0 : 0x80);
637 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
638 0x80, valp[1] ? 0 : 0x80);
639 return change;
640}
641
642static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
643 .num_items = 3,
644 .items = {
645 { "Mic", 0x0 },
646 { "Internal Mic", 0x4 },
647 { "Mix", 0x5 },
648 },
649};
650
651static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
652 {
653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
654 .name = "Master Playback Volume",
655 .info = snd_hda_mixer_amp_volume_info,
656 .get = snd_hda_mixer_amp_volume_get,
657 .put = ad1986a_laptop_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200658 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwai825aa972006-03-17 10:50:49 +0100659 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
660 },
661 {
662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
663 .name = "Master Playback Switch",
664 .info = snd_hda_mixer_amp_switch_info,
665 .get = snd_hda_mixer_amp_switch_get,
666 .put = ad1986a_laptop_master_sw_put,
667 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
668 },
669 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
670 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
671 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
672 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
673 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
674 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100675 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100676 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
677 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
678 {
679 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
680 .name = "Capture Source",
681 .info = ad198x_mux_enum_info,
682 .get = ad198x_mux_enum_get,
683 .put = ad198x_mux_enum_put,
684 },
685 {
686 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
687 .name = "External Amplifier",
688 .info = ad198x_eapd_info,
689 .get = ad198x_eapd_get,
690 .put = ad198x_eapd_put,
691 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
692 },
693 { } /* end */
694};
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696/*
697 * initialization verbs
698 */
699static struct hda_verb ad1986a_init_verbs[] = {
700 /* Front, Surround, CLFE DAC; mute as default */
701 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
702 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
703 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
704 /* Downmix - off */
705 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
706 /* HP, Line-Out, Surround, CLFE selectors */
707 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
708 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
709 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
710 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
711 /* Mono selector */
712 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
713 /* Mic selector: Mic 1/2 pin */
714 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
715 /* Line-in selector: Line-in */
716 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
717 /* Mic 1/2 swap */
718 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
719 /* Record selector: mic */
720 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
721 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
722 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
725 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
726 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
727 /* PC beep */
728 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
729 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
730 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
731 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
732 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
733 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
734 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200735 /* HP Pin */
736 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
737 /* Front, Surround, CLFE Pins */
738 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
739 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
740 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
741 /* Mono Pin */
742 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
743 /* Mic Pin */
744 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
745 /* Line, Aux, CD, Beep-In Pin */
746 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
747 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
748 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
749 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
750 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 { } /* end */
752};
753
Takashi Iwai9230d212006-03-13 13:49:49 +0100754static struct hda_verb ad1986a_ch2_init[] = {
755 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200756 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
757 /* Line-in selectors */
758 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100759 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200760 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
761 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
762 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100763 { } /* end */
764};
765
766static struct hda_verb ad1986a_ch4_init[] = {
767 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200768 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
769 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100770 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200771 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
772 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100773 { } /* end */
774};
775
776static struct hda_verb ad1986a_ch6_init[] = {
777 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200778 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
779 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100780 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200781 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
782 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100783 { } /* end */
784};
785
786static struct hda_channel_mode ad1986a_modes[3] = {
787 { 2, ad1986a_ch2_init },
788 { 4, ad1986a_ch4_init },
789 { 6, ad1986a_ch6_init },
790};
791
Takashi Iwai825aa972006-03-17 10:50:49 +0100792/* eapd initialization */
793static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100794 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +0100795 {}
796};
797
Tobin Davisf36090f2007-01-08 11:07:12 +0100798/* Ultra initialization */
799static struct hda_verb ad1986a_ultra_init[] = {
800 /* eapd initialization */
801 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
802 /* CLFE -> Mic in */
803 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
804 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
805 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
806 { } /* end */
807};
808
Takashi Iwai9230d212006-03-13 13:49:49 +0100809/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100810enum {
811 AD1986A_6STACK,
812 AD1986A_3STACK,
813 AD1986A_LAPTOP,
814 AD1986A_LAPTOP_EAPD,
Tobin Davisf36090f2007-01-08 11:07:12 +0100815 AD1986A_ULTRA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100816 AD1986A_MODELS
817};
Takashi Iwai9230d212006-03-13 13:49:49 +0100818
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100819static const char *ad1986a_models[AD1986A_MODELS] = {
820 [AD1986A_6STACK] = "6stack",
821 [AD1986A_3STACK] = "3stack",
822 [AD1986A_LAPTOP] = "laptop",
823 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisf36090f2007-01-08 11:07:12 +0100824 [AD1986A_ULTRA] = "ultra",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100825};
826
827static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
828 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
829 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
830 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
831 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
832 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
833 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
834 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
835 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
836 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
837 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
838 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
839 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
840 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
841 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +0100842 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100843 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
844 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
845 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
846 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
Tobin Davisf36090f2007-01-08 11:07:12 +0100847 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
848 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Tobin Davis18768992007-03-12 22:20:51 +0100849 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100850 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
851 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
852 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +0100853 {}
854};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856static int patch_ad1986a(struct hda_codec *codec)
857{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200858 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100859 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200861 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if (spec == NULL)
863 return -ENOMEM;
864
Ingo Molnar62932df2006-01-16 16:34:20 +0100865 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 codec->spec = spec;
867
868 spec->multiout.max_channels = 6;
869 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
870 spec->multiout.dac_nids = ad1986a_dac_nids;
871 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100872 spec->num_adc_nids = 1;
873 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100874 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200875 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100876 spec->num_mixers = 1;
877 spec->mixers[0] = ad1986a_mixers;
878 spec->num_init_verbs = 1;
879 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200881 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Takashi Iwai9230d212006-03-13 13:49:49 +0100883 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100884 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
885 ad1986a_models,
886 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +0100887 switch (board_config) {
888 case AD1986A_3STACK:
889 spec->num_mixers = 2;
890 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +0200891 spec->num_init_verbs = 2;
892 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100893 spec->channel_mode = ad1986a_modes;
894 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200895 spec->need_dac_fix = 1;
896 spec->multiout.max_channels = 2;
897 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100898 break;
899 case AD1986A_LAPTOP:
900 spec->mixers[0] = ad1986a_laptop_mixers;
901 spec->multiout.max_channels = 2;
902 spec->multiout.num_dacs = 1;
903 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
904 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100905 case AD1986A_LAPTOP_EAPD:
906 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
907 spec->num_init_verbs = 2;
908 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
909 spec->multiout.max_channels = 2;
910 spec->multiout.num_dacs = 1;
911 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
912 spec->multiout.dig_out_nid = 0;
913 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
914 break;
Tobin Davisf36090f2007-01-08 11:07:12 +0100915 case AD1986A_ULTRA:
916 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
917 spec->num_init_verbs = 2;
918 spec->init_verbs[1] = ad1986a_ultra_init;
919 spec->multiout.max_channels = 2;
920 spec->multiout.num_dacs = 1;
921 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
922 spec->multiout.dig_out_nid = 0;
923 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100924 }
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return 0;
927}
928
929/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200930 * AD1983 specific
931 */
932
933#define AD1983_SPDIF_OUT 0x02
934#define AD1983_DAC 0x03
935#define AD1983_ADC 0x04
936
937static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100938static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100939static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200940
941static struct hda_input_mux ad1983_capture_source = {
942 .num_items = 4,
943 .items = {
944 { "Mic", 0x0 },
945 { "Line", 0x1 },
946 { "Mix", 0x2 },
947 { "Mix Mono", 0x3 },
948 },
949};
950
951/*
952 * SPDIF playback route
953 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100954static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200955{
956 static char *texts[] = { "PCM", "ADC" };
957
958 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
959 uinfo->count = 1;
960 uinfo->value.enumerated.items = 2;
961 if (uinfo->value.enumerated.item > 1)
962 uinfo->value.enumerated.item = 1;
963 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
964 return 0;
965}
966
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100967static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200968{
969 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
970 struct ad198x_spec *spec = codec->spec;
971
972 ucontrol->value.enumerated.item[0] = spec->spdif_route;
973 return 0;
974}
975
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100976static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200977{
978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
979 struct ad198x_spec *spec = codec->spec;
980
981 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
982 spec->spdif_route = ucontrol->value.enumerated.item[0];
983 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
984 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
985 return 1;
986 }
987 return 0;
988}
989
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100990static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200991 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
992 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
993 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
995 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
996 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
997 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
998 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
999 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1000 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1001 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1002 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1003 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1004 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1005 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1006 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1007 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1008 {
1009 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1010 .name = "Capture Source",
1011 .info = ad198x_mux_enum_info,
1012 .get = ad198x_mux_enum_get,
1013 .put = ad198x_mux_enum_put,
1014 },
1015 {
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001017 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001018 .info = ad1983_spdif_route_info,
1019 .get = ad1983_spdif_route_get,
1020 .put = ad1983_spdif_route_put,
1021 },
1022 { } /* end */
1023};
1024
1025static struct hda_verb ad1983_init_verbs[] = {
1026 /* Front, HP, Mono; mute as default */
1027 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1028 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1029 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1030 /* Beep, PCM, Mic, Line-In: mute */
1031 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1032 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1033 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1034 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1035 /* Front, HP selectors; from Mix */
1036 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1037 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1038 /* Mono selector; from Mix */
1039 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1040 /* Mic selector; Mic */
1041 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1042 /* Line-in selector: Line-in */
1043 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1044 /* Mic boost: 0dB */
1045 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1046 /* Record selector: mic */
1047 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1048 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1049 /* SPDIF route: PCM */
1050 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1051 /* Front Pin */
1052 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1053 /* HP Pin */
1054 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1055 /* Mono Pin */
1056 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1057 /* Mic Pin */
1058 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1059 /* Line Pin */
1060 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1061 { } /* end */
1062};
1063
Takashi Iwai985be542005-11-02 18:26:49 +01001064
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001065static int patch_ad1983(struct hda_codec *codec)
1066{
1067 struct ad198x_spec *spec;
1068
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001069 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001070 if (spec == NULL)
1071 return -ENOMEM;
1072
Ingo Molnar62932df2006-01-16 16:34:20 +01001073 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001074 codec->spec = spec;
1075
1076 spec->multiout.max_channels = 2;
1077 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1078 spec->multiout.dac_nids = ad1983_dac_nids;
1079 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001080 spec->num_adc_nids = 1;
1081 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001082 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001083 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001084 spec->num_mixers = 1;
1085 spec->mixers[0] = ad1983_mixers;
1086 spec->num_init_verbs = 1;
1087 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001088 spec->spdif_route = 0;
1089
1090 codec->patch_ops = ad198x_patch_ops;
1091
1092 return 0;
1093}
1094
1095
1096/*
1097 * AD1981 HD specific
1098 */
1099
1100#define AD1981_SPDIF_OUT 0x02
1101#define AD1981_DAC 0x03
1102#define AD1981_ADC 0x04
1103
1104static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001105static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001106static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001107
1108/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1109static struct hda_input_mux ad1981_capture_source = {
1110 .num_items = 7,
1111 .items = {
1112 { "Front Mic", 0x0 },
1113 { "Line", 0x1 },
1114 { "Mix", 0x2 },
1115 { "Mix Mono", 0x3 },
1116 { "CD", 0x4 },
1117 { "Mic", 0x6 },
1118 { "Aux", 0x7 },
1119 },
1120};
1121
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001122static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001123 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1124 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1126 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1127 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1128 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1132 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1133 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1134 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1135 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1136 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1137 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1138 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1139 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1140 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1141 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1142 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1143 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1144 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1145 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1146 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1147 {
1148 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1149 .name = "Capture Source",
1150 .info = ad198x_mux_enum_info,
1151 .get = ad198x_mux_enum_get,
1152 .put = ad198x_mux_enum_put,
1153 },
1154 /* identical with AD1983 */
1155 {
1156 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001157 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001158 .info = ad1983_spdif_route_info,
1159 .get = ad1983_spdif_route_get,
1160 .put = ad1983_spdif_route_put,
1161 },
1162 { } /* end */
1163};
1164
1165static struct hda_verb ad1981_init_verbs[] = {
1166 /* Front, HP, Mono; mute as default */
1167 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1168 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1169 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1170 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1171 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1172 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1173 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1174 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1175 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1176 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1177 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1178 /* Front, HP selectors; from Mix */
1179 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1180 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1181 /* Mono selector; from Mix */
1182 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1183 /* Mic Mixer; select Front Mic */
1184 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1185 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1186 /* Mic boost: 0dB */
1187 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1188 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1189 /* Record selector: Front mic */
1190 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1191 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1192 /* SPDIF route: PCM */
1193 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1194 /* Front Pin */
1195 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1196 /* HP Pin */
1197 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1198 /* Mono Pin */
1199 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1200 /* Front & Rear Mic Pins */
1201 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1202 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1203 /* Line Pin */
1204 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1205 /* Digital Beep */
1206 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1207 /* Line-Out as Input: disabled */
1208 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1209 { } /* end */
1210};
1211
Takashi Iwai18a815d2006-03-01 19:54:39 +01001212/*
1213 * Patch for HP nx6320
1214 *
Tobin Davis18768992007-03-12 22:20:51 +01001215 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001216 * speaker output enabled _and_ mute-LED off.
1217 */
1218
1219#define AD1981_HP_EVENT 0x37
1220#define AD1981_MIC_EVENT 0x38
1221
1222static struct hda_verb ad1981_hp_init_verbs[] = {
1223 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1224 /* pin sensing on HP and Mic jacks */
1225 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1226 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1227 {}
1228};
1229
1230/* turn on/off EAPD (+ mute HP) as a master switch */
1231static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1232 struct snd_ctl_elem_value *ucontrol)
1233{
1234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1235 struct ad198x_spec *spec = codec->spec;
1236
1237 if (! ad198x_eapd_put(kcontrol, ucontrol))
1238 return 0;
1239
1240 /* toggle HP mute appropriately */
1241 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1242 0x80, spec->cur_eapd ? 0 : 0x80);
1243 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1244 0x80, spec->cur_eapd ? 0 : 0x80);
1245 return 1;
1246}
1247
1248/* bind volumes of both NID 0x05 and 0x06 */
1249static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1250 struct snd_ctl_elem_value *ucontrol)
1251{
1252 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1253 long *valp = ucontrol->value.integer.value;
1254 int change;
1255
1256 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1257 0x7f, valp[0] & 0x7f);
1258 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1259 0x7f, valp[1] & 0x7f);
1260 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1261 0x7f, valp[0] & 0x7f);
1262 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1263 0x7f, valp[1] & 0x7f);
1264 return change;
1265}
1266
1267/* mute internal speaker if HP is plugged */
1268static void ad1981_hp_automute(struct hda_codec *codec)
1269{
1270 unsigned int present;
1271
1272 present = snd_hda_codec_read(codec, 0x06, 0,
1273 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1274 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1275 0x80, present ? 0x80 : 0);
1276 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1277 0x80, present ? 0x80 : 0);
1278}
1279
1280/* toggle input of built-in and mic jack appropriately */
1281static void ad1981_hp_automic(struct hda_codec *codec)
1282{
1283 static struct hda_verb mic_jack_on[] = {
1284 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1285 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1286 {}
1287 };
1288 static struct hda_verb mic_jack_off[] = {
1289 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1290 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1291 {}
1292 };
1293 unsigned int present;
1294
1295 present = snd_hda_codec_read(codec, 0x08, 0,
1296 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1297 if (present)
1298 snd_hda_sequence_write(codec, mic_jack_on);
1299 else
1300 snd_hda_sequence_write(codec, mic_jack_off);
1301}
1302
1303/* unsolicited event for HP jack sensing */
1304static void ad1981_hp_unsol_event(struct hda_codec *codec,
1305 unsigned int res)
1306{
1307 res >>= 26;
1308 switch (res) {
1309 case AD1981_HP_EVENT:
1310 ad1981_hp_automute(codec);
1311 break;
1312 case AD1981_MIC_EVENT:
1313 ad1981_hp_automic(codec);
1314 break;
1315 }
1316}
1317
1318static struct hda_input_mux ad1981_hp_capture_source = {
1319 .num_items = 3,
1320 .items = {
1321 { "Mic", 0x0 },
1322 { "Docking-Station", 0x1 },
1323 { "Mix", 0x2 },
1324 },
1325};
1326
1327static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1328 {
1329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1330 .name = "Master Playback Volume",
1331 .info = snd_hda_mixer_amp_volume_info,
1332 .get = snd_hda_mixer_amp_volume_get,
1333 .put = ad1981_hp_master_vol_put,
1334 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1335 },
1336 {
1337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1338 .name = "Master Playback Switch",
1339 .info = ad198x_eapd_info,
1340 .get = ad198x_eapd_get,
1341 .put = ad1981_hp_master_sw_put,
1342 .private_value = 0x05,
1343 },
1344 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1345 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1346#if 0
1347 /* FIXME: analog mic/line loopback doesn't work with my tests...
1348 * (although recording is OK)
1349 */
1350 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1352 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1356 /* FIXME: does this laptop have analog CD connection? */
1357 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1359#endif
1360 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1361 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1362 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1364 {
1365 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1366 .name = "Capture Source",
1367 .info = ad198x_mux_enum_info,
1368 .get = ad198x_mux_enum_get,
1369 .put = ad198x_mux_enum_put,
1370 },
1371 { } /* end */
1372};
1373
1374/* initialize jack-sensing, too */
1375static int ad1981_hp_init(struct hda_codec *codec)
1376{
1377 ad198x_init(codec);
1378 ad1981_hp_automute(codec);
1379 ad1981_hp_automic(codec);
1380 return 0;
1381}
1382
Tobin Davis18768992007-03-12 22:20:51 +01001383/* configuration for Toshiba Laptops */
1384static struct hda_verb ad1981_toshiba_init_verbs[] = {
1385 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1386 /* pin sensing on HP and Mic jacks */
1387 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1388 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1389 {}
1390};
1391
1392static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1393 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1394 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1395 { }
1396};
1397
Takashi Iwai01686c52006-04-18 12:54:11 +02001398/* configuration for Lenovo Thinkpad T60 */
1399static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1400 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1406 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1409 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1411 {
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = "Capture Source",
1414 .info = ad198x_mux_enum_info,
1415 .get = ad198x_mux_enum_get,
1416 .put = ad198x_mux_enum_put,
1417 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001418 /* identical with AD1983 */
1419 {
1420 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1421 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1422 .info = ad1983_spdif_route_info,
1423 .get = ad1983_spdif_route_get,
1424 .put = ad1983_spdif_route_put,
1425 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001426 { } /* end */
1427};
1428
1429static struct hda_input_mux ad1981_thinkpad_capture_source = {
1430 .num_items = 3,
1431 .items = {
1432 { "Mic", 0x0 },
1433 { "Mix", 0x2 },
1434 { "CD", 0x4 },
1435 },
1436};
1437
Takashi Iwai18a815d2006-03-01 19:54:39 +01001438/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001439enum {
1440 AD1981_BASIC,
1441 AD1981_HP,
1442 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001443 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001444 AD1981_MODELS
1445};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001446
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001447static const char *ad1981_models[AD1981_MODELS] = {
1448 [AD1981_HP] = "hp",
1449 [AD1981_THINKPAD] = "thinkpad",
1450 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001451 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001452};
1453
1454static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001455 /* All HP models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001456 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1457 /* HP nx6320 (reversed SSID, H/W bug) */
1458 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai01686c52006-04-18 12:54:11 +02001459 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001460 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1461 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Tobin Davis18768992007-03-12 22:20:51 +01001462 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001463 {}
1464};
1465
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001466static int patch_ad1981(struct hda_codec *codec)
1467{
1468 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001469 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001470
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001471 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001472 if (spec == NULL)
1473 return -ENOMEM;
1474
Ingo Molnar62932df2006-01-16 16:34:20 +01001475 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001476 codec->spec = spec;
1477
1478 spec->multiout.max_channels = 2;
1479 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1480 spec->multiout.dac_nids = ad1981_dac_nids;
1481 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001482 spec->num_adc_nids = 1;
1483 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001484 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001485 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001486 spec->num_mixers = 1;
1487 spec->mixers[0] = ad1981_mixers;
1488 spec->num_init_verbs = 1;
1489 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001490 spec->spdif_route = 0;
1491
1492 codec->patch_ops = ad198x_patch_ops;
1493
Takashi Iwai18a815d2006-03-01 19:54:39 +01001494 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001495 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1496 ad1981_models,
1497 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001498 switch (board_config) {
1499 case AD1981_HP:
1500 spec->mixers[0] = ad1981_hp_mixers;
1501 spec->num_init_verbs = 2;
1502 spec->init_verbs[1] = ad1981_hp_init_verbs;
1503 spec->multiout.dig_out_nid = 0;
1504 spec->input_mux = &ad1981_hp_capture_source;
1505
1506 codec->patch_ops.init = ad1981_hp_init;
1507 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1508 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001509 case AD1981_THINKPAD:
1510 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001511 spec->input_mux = &ad1981_thinkpad_capture_source;
1512 break;
Tobin Davis18768992007-03-12 22:20:51 +01001513 case AD1981_TOSHIBA:
1514 spec->mixers[0] = ad1981_hp_mixers;
1515 spec->mixers[1] = ad1981_toshiba_mixers;
1516 spec->num_init_verbs = 2;
1517 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1518 spec->multiout.dig_out_nid = 0;
1519 spec->input_mux = &ad1981_hp_capture_source;
1520 codec->patch_ops.init = ad1981_hp_init;
1521 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1522 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001523 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001524 return 0;
1525}
1526
1527
1528/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001529 * AD1988
1530 *
1531 * Output pins and routes
1532 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001533 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001534 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1535 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1536 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1537 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1538 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1539 * port-F 0x16 (mute) <- 0x2a <- 06
1540 * port-G 0x24 (mute) <- 0x27 <- 05
1541 * port-H 0x25 (mute) <- 0x28 <- 0a
1542 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1543 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001544 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1545 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001546 *
1547 * Input pins and routes
1548 *
1549 * pin boost mix input # / adc input #
1550 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1551 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1552 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1553 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1554 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1555 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1556 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1557 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1558 *
1559 *
1560 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001561 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001562 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001563 *
1564 * Inputs of Analog Mix (0x20)
1565 * 0:Port-B (front mic)
1566 * 1:Port-C/G/H (line-in)
1567 * 2:Port-A
1568 * 3:Port-D (line-in/2)
1569 * 4:Port-E/G/H (mic-in)
1570 * 5:Port-F (mic2-in)
1571 * 6:CD
1572 * 7:Beep
1573 *
1574 * ADC selection
1575 * 0:Port-A
1576 * 1:Port-B (front mic-in)
1577 * 2:Port-C (line-in)
1578 * 3:Port-F (mic2-in)
1579 * 4:Port-E (mic-in)
1580 * 5:CD
1581 * 6:Port-G
1582 * 7:Port-H
1583 * 8:Port-D (line-in/2)
1584 * 9:Mix
1585 *
1586 * Proposed pin assignments by the datasheet
1587 *
1588 * 6-stack
1589 * Port-A front headphone
1590 * B front mic-in
1591 * C rear line-in
1592 * D rear front-out
1593 * E rear mic-in
1594 * F rear surround
1595 * G rear CLFE
1596 * H rear side
1597 *
1598 * 3-stack
1599 * Port-A front headphone
1600 * B front mic
1601 * C rear line-in/surround
1602 * D rear front-out
1603 * E rear mic-in/CLFE
1604 *
1605 * laptop
1606 * Port-A headphone
1607 * B mic-in
1608 * C docking station
1609 * D internal speaker (with EAPD)
1610 * E/F quad mic array
1611 */
1612
1613
1614/* models */
1615enum {
1616 AD1988_6STACK,
1617 AD1988_6STACK_DIG,
1618 AD1988_3STACK,
1619 AD1988_3STACK_DIG,
1620 AD1988_LAPTOP,
1621 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001622 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001623 AD1988_MODEL_LAST,
1624};
1625
Takashi Iwaid32410b12005-11-24 16:06:23 +01001626/* reivision id to check workarounds */
1627#define AD1988A_REV2 0x100200
1628
Takashi Iwai1a806f42006-07-03 15:58:16 +02001629#define is_rev2(codec) \
1630 ((codec)->vendor_id == 0x11d41988 && \
1631 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001632
1633/*
1634 * mixers
1635 */
1636
Takashi Iwaid32410b12005-11-24 16:06:23 +01001637static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001638 0x04, 0x06, 0x05, 0x0a
1639};
1640
Takashi Iwaid32410b12005-11-24 16:06:23 +01001641static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001642 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001643};
1644
1645/* for AD1988A revision-2, DAC2-4 are swapped */
1646static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1647 0x04, 0x05, 0x0a, 0x06
1648};
1649
1650static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001651 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001652};
1653
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001654static hda_nid_t ad1988_adc_nids[3] = {
1655 0x08, 0x09, 0x0f
1656};
1657
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001658static hda_nid_t ad1988_capsrc_nids[3] = {
1659 0x0c, 0x0d, 0x0e
1660};
1661
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001662#define AD1988_SPDIF_OUT 0x02
1663#define AD1988_SPDIF_IN 0x07
1664
1665static struct hda_input_mux ad1988_6stack_capture_source = {
1666 .num_items = 5,
1667 .items = {
1668 { "Front Mic", 0x0 },
1669 { "Line", 0x1 },
1670 { "Mic", 0x4 },
1671 { "CD", 0x5 },
1672 { "Mix", 0x9 },
1673 },
1674};
1675
1676static struct hda_input_mux ad1988_laptop_capture_source = {
1677 .num_items = 3,
1678 .items = {
1679 { "Mic/Line", 0x0 },
1680 { "CD", 0x5 },
1681 { "Mix", 0x9 },
1682 },
1683};
1684
1685/*
1686 */
1687static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_info *uinfo)
1689{
1690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1691 struct ad198x_spec *spec = codec->spec;
1692 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1693 spec->num_channel_mode);
1694}
1695
1696static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1697 struct snd_ctl_elem_value *ucontrol)
1698{
1699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1700 struct ad198x_spec *spec = codec->spec;
1701 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1702 spec->num_channel_mode, spec->multiout.max_channels);
1703}
1704
1705static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol)
1707{
1708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1709 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001710 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1711 spec->num_channel_mode,
1712 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001713 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001714 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001715 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001716}
1717
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001718/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001719static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001720 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1721 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1722 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1723 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1724 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001725 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001726};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001727
Takashi Iwaid32410b12005-11-24 16:06:23 +01001728static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1729 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1730 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1731 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1732 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1733 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001734 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001735};
1736
1737static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001738 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1739 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1740 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1741 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1742 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1743 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1744 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1745
1746 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1747 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1748 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1749 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1750 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1751 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1752 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1753 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1754
1755 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1756 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1757
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001758 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001759 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1760
1761 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1762 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1763
1764 { } /* end */
1765};
1766
1767/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001768static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001769 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001770 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001771 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1772 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001773 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001774};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001775
Takashi Iwaid32410b12005-11-24 16:06:23 +01001776static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1777 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001778 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1779 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1780 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001781 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001782};
1783
1784static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001785 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001786 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1787 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1788 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001789 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1790 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1791
1792 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1793 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1794 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1795 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1796 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1797 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1798 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1799 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1800
1801 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1802 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1803
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001804 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001805 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1806
1807 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1808 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1809 {
1810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1811 .name = "Channel Mode",
1812 .info = ad198x_ch_mode_info,
1813 .get = ad198x_ch_mode_get,
1814 .put = ad198x_ch_mode_put,
1815 },
1816
1817 { } /* end */
1818};
1819
1820/* laptop mode */
1821static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1822 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1823 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1824 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1825
1826 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1827 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1828 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1829 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1830 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1831 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1832
1833 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1834 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1835
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001836 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001837 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1838
1839 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1840
1841 {
1842 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1843 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001844 .info = ad198x_eapd_info,
1845 .get = ad198x_eapd_get,
1846 .put = ad198x_eapd_put,
1847 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001848 },
1849
1850 { } /* end */
1851};
1852
1853/* capture */
1854static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1855 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1856 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1857 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1858 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1859 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1860 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1861 {
1862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1863 /* The multiple "Capture Source" controls confuse alsamixer
1864 * So call somewhat different..
1865 * FIXME: the controls appear in the "playback" view!
1866 */
1867 /* .name = "Capture Source", */
1868 .name = "Input Source",
1869 .count = 3,
1870 .info = ad198x_mux_enum_info,
1871 .get = ad198x_mux_enum_get,
1872 .put = ad198x_mux_enum_put,
1873 },
1874 { } /* end */
1875};
1876
1877static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1878 struct snd_ctl_elem_info *uinfo)
1879{
1880 static char *texts[] = {
1881 "PCM", "ADC1", "ADC2", "ADC3"
1882 };
1883 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1884 uinfo->count = 1;
1885 uinfo->value.enumerated.items = 4;
1886 if (uinfo->value.enumerated.item >= 4)
1887 uinfo->value.enumerated.item = 3;
1888 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1889 return 0;
1890}
1891
1892static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1893 struct snd_ctl_elem_value *ucontrol)
1894{
1895 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1896 unsigned int sel;
1897
1898 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1899 if (sel > 0) {
1900 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1901 if (sel <= 3)
1902 sel++;
1903 else
1904 sel = 0;
1905 }
1906 ucontrol->value.enumerated.item[0] = sel;
1907 return 0;
1908}
1909
1910static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1911 struct snd_ctl_elem_value *ucontrol)
1912{
1913 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1914 unsigned int sel;
1915 int change;
1916
1917 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1918 if (! ucontrol->value.enumerated.item[0]) {
1919 change = sel != 0;
1920 if (change)
1921 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1922 } else {
1923 change = sel == 0;
1924 if (change)
1925 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1926 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1927 change |= sel == ucontrol->value.enumerated.item[0];
1928 if (change)
1929 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1930 ucontrol->value.enumerated.item[0] - 1);
1931 }
1932 return change;
1933}
1934
1935static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1936 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1937 {
1938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1939 .name = "IEC958 Playback Source",
1940 .info = ad1988_spdif_playback_source_info,
1941 .get = ad1988_spdif_playback_source_get,
1942 .put = ad1988_spdif_playback_source_put,
1943 },
1944 { } /* end */
1945};
1946
1947static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1948 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1949 { } /* end */
1950};
1951
1952
1953/*
1954 * initialization verbs
1955 */
1956
1957/*
1958 * for 6-stack (+dig)
1959 */
1960static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001961 /* Front, Surround, CLFE, side DAC; unmute as default */
1962 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1963 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1964 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1965 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001966 /* Port-A front headphon path */
1967 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1968 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1969 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1970 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1971 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1972 /* Port-D line-out path */
1973 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1974 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1975 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1976 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1977 /* Port-F surround path */
1978 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1979 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1980 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1981 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1982 /* Port-G CLFE path */
1983 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1984 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1985 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1986 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1987 /* Port-H side path */
1988 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1989 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1990 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1991 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1992 /* Mono out path */
1993 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1994 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1995 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1996 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1997 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1998 /* Port-B front mic-in path */
1999 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2000 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2001 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2002 /* Port-C line-in path */
2003 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2004 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2005 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2006 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2007 /* Port-E mic-in path */
2008 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2009 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2010 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2011 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2012
2013 { }
2014};
2015
2016static struct hda_verb ad1988_capture_init_verbs[] = {
2017 /* mute analog mix */
2018 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2019 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2020 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2021 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2022 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2023 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2024 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2025 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2026 /* select ADCs - front-mic */
2027 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2028 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2029 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2030 /* ADCs; muted */
2031 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2032 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2033 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2034
2035 { }
2036};
2037
2038static struct hda_verb ad1988_spdif_init_verbs[] = {
2039 /* SPDIF out sel */
2040 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2041 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2042 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2043 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2044 /* SPDIF out pin */
2045 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2046 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
2047
2048 { }
2049};
2050
2051/*
2052 * verbs for 3stack (+dig)
2053 */
2054static struct hda_verb ad1988_3stack_ch2_init[] = {
2055 /* set port-C to line-in */
2056 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2057 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2058 /* set port-E to mic-in */
2059 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2060 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2061 { } /* end */
2062};
2063
2064static struct hda_verb ad1988_3stack_ch6_init[] = {
2065 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002066 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002067 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002068 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002069 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002070 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002071 { } /* end */
2072};
2073
2074static struct hda_channel_mode ad1988_3stack_modes[2] = {
2075 { 2, ad1988_3stack_ch2_init },
2076 { 6, ad1988_3stack_ch6_init },
2077};
2078
2079static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002080 /* Front, Surround, CLFE, side DAC; unmute as default */
2081 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2082 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2083 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2084 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002085 /* Port-A front headphon path */
2086 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2087 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2088 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2089 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2090 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2091 /* Port-D line-out path */
2092 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2093 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2094 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2095 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2096 /* Mono out path */
2097 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2098 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2099 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2100 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2101 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2102 /* Port-B front mic-in path */
2103 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2104 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2105 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002106 /* Port-C line-in/surround path - 6ch mode as default */
2107 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2108 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002109 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002110 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002111 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002112 /* Port-E mic-in/CLFE path - 6ch mode as default */
2113 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2114 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002115 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002116 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002117 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2118 /* mute analog mix */
2119 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2120 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2121 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2122 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2123 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2124 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2125 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2126 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2127 /* select ADCs - front-mic */
2128 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2129 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2130 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2131 /* ADCs; muted */
2132 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2133 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2134 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2135 { }
2136};
2137
2138/*
2139 * verbs for laptop mode (+dig)
2140 */
2141static struct hda_verb ad1988_laptop_hp_on[] = {
2142 /* unmute port-A and mute port-D */
2143 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2144 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2145 { } /* end */
2146};
2147static struct hda_verb ad1988_laptop_hp_off[] = {
2148 /* mute port-A and unmute port-D */
2149 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2150 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2151 { } /* end */
2152};
2153
2154#define AD1988_HP_EVENT 0x01
2155
2156static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002157 /* Front, Surround, CLFE, side DAC; unmute as default */
2158 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2159 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2160 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2161 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002162 /* Port-A front headphon path */
2163 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2164 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2165 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2166 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2167 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2168 /* unsolicited event for pin-sense */
2169 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2170 /* Port-D line-out path + EAPD */
2171 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2172 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2173 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2174 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2176 /* Mono out path */
2177 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2178 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2179 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2180 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2181 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2182 /* Port-B mic-in path */
2183 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2184 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2185 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2186 /* Port-C docking station - try to output */
2187 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2188 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2189 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2190 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2191 /* mute analog mix */
2192 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2193 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2194 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2195 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2196 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2197 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2198 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2199 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2200 /* select ADCs - mic */
2201 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2202 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2203 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2204 /* ADCs; muted */
2205 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2206 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2207 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2208 { }
2209};
2210
2211static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2212{
2213 if ((res >> 26) != AD1988_HP_EVENT)
2214 return;
2215 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2216 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2217 else
2218 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2219}
2220
2221
2222/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002223 * Automatic parse of I/O pins from the BIOS configuration
2224 */
2225
2226#define NUM_CONTROL_ALLOC 32
2227#define NUM_VERB_ALLOC 32
2228
2229enum {
2230 AD_CTL_WIDGET_VOL,
2231 AD_CTL_WIDGET_MUTE,
2232 AD_CTL_BIND_MUTE,
2233};
2234static struct snd_kcontrol_new ad1988_control_templates[] = {
2235 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2236 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2237 HDA_BIND_MUTE(NULL, 0, 0, 0),
2238};
2239
2240/* add dynamic controls */
2241static int add_control(struct ad198x_spec *spec, int type, const char *name,
2242 unsigned long val)
2243{
2244 struct snd_kcontrol_new *knew;
2245
2246 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2247 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2248
2249 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2250 if (! knew)
2251 return -ENOMEM;
2252 if (spec->kctl_alloc) {
2253 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2254 kfree(spec->kctl_alloc);
2255 }
2256 spec->kctl_alloc = knew;
2257 spec->num_kctl_alloc = num;
2258 }
2259
2260 knew = &spec->kctl_alloc[spec->num_kctl_used];
2261 *knew = ad1988_control_templates[type];
2262 knew->name = kstrdup(name, GFP_KERNEL);
2263 if (! knew->name)
2264 return -ENOMEM;
2265 knew->private_value = val;
2266 spec->num_kctl_used++;
2267 return 0;
2268}
2269
2270#define AD1988_PIN_CD_NID 0x18
2271#define AD1988_PIN_BEEP_NID 0x10
2272
2273static hda_nid_t ad1988_mixer_nids[8] = {
2274 /* A B C D E F G H */
2275 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2276};
2277
2278static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2279{
2280 static hda_nid_t idx_to_dac[8] = {
2281 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002282 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002283 };
2284 static hda_nid_t idx_to_dac_rev2[8] = {
2285 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002286 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002287 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002288 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002289 return idx_to_dac_rev2[idx];
2290 else
2291 return idx_to_dac[idx];
2292}
2293
2294static hda_nid_t ad1988_boost_nids[8] = {
2295 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2296};
2297
2298static int ad1988_pin_idx(hda_nid_t nid)
2299{
2300 static hda_nid_t ad1988_io_pins[8] = {
2301 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2302 };
2303 int i;
2304 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2305 if (ad1988_io_pins[i] == nid)
2306 return i;
2307 return 0; /* should be -1 */
2308}
2309
2310static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2311{
2312 static int loopback_idx[8] = {
2313 2, 0, 1, 3, 4, 5, 1, 4
2314 };
2315 switch (nid) {
2316 case AD1988_PIN_CD_NID:
2317 return 6;
2318 default:
2319 return loopback_idx[ad1988_pin_idx(nid)];
2320 }
2321}
2322
2323static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2324{
2325 static int adc_idx[8] = {
2326 0, 1, 2, 8, 4, 3, 6, 7
2327 };
2328 switch (nid) {
2329 case AD1988_PIN_CD_NID:
2330 return 5;
2331 default:
2332 return adc_idx[ad1988_pin_idx(nid)];
2333 }
2334}
2335
2336/* fill in the dac_nids table from the parsed pin configuration */
2337static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2338 const struct auto_pin_cfg *cfg)
2339{
2340 struct ad198x_spec *spec = codec->spec;
2341 int i, idx;
2342
2343 spec->multiout.dac_nids = spec->private_dac_nids;
2344
2345 /* check the pins hardwired to audio widget */
2346 for (i = 0; i < cfg->line_outs; i++) {
2347 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2348 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2349 }
2350 spec->multiout.num_dacs = cfg->line_outs;
2351 return 0;
2352}
2353
2354/* add playback controls from the parsed DAC table */
2355static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2356 const struct auto_pin_cfg *cfg)
2357{
2358 char name[32];
2359 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2360 hda_nid_t nid;
2361 int i, err;
2362
2363 for (i = 0; i < cfg->line_outs; i++) {
2364 hda_nid_t dac = spec->multiout.dac_nids[i];
2365 if (! dac)
2366 continue;
2367 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2368 if (i == 2) {
2369 /* Center/LFE */
2370 err = add_control(spec, AD_CTL_WIDGET_VOL,
2371 "Center Playback Volume",
2372 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2373 if (err < 0)
2374 return err;
2375 err = add_control(spec, AD_CTL_WIDGET_VOL,
2376 "LFE Playback Volume",
2377 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2378 if (err < 0)
2379 return err;
2380 err = add_control(spec, AD_CTL_BIND_MUTE,
2381 "Center Playback Switch",
2382 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2383 if (err < 0)
2384 return err;
2385 err = add_control(spec, AD_CTL_BIND_MUTE,
2386 "LFE Playback Switch",
2387 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2388 if (err < 0)
2389 return err;
2390 } else {
2391 sprintf(name, "%s Playback Volume", chname[i]);
2392 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2393 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2394 if (err < 0)
2395 return err;
2396 sprintf(name, "%s Playback Switch", chname[i]);
2397 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2398 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2399 if (err < 0)
2400 return err;
2401 }
2402 }
2403 return 0;
2404}
2405
2406/* add playback controls for speaker and HP outputs */
2407static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2408 const char *pfx)
2409{
2410 struct ad198x_spec *spec = codec->spec;
2411 hda_nid_t nid;
2412 int idx, err;
2413 char name[32];
2414
2415 if (! pin)
2416 return 0;
2417
2418 idx = ad1988_pin_idx(pin);
2419 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002420 /* specify the DAC as the extra output */
2421 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002422 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002423 else
2424 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002425 /* control HP volume/switch on the output mixer amp */
2426 sprintf(name, "%s Playback Volume", pfx);
2427 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2428 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2429 return err;
2430 nid = ad1988_mixer_nids[idx];
2431 sprintf(name, "%s Playback Switch", pfx);
2432 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2433 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2434 return err;
2435 return 0;
2436}
2437
2438/* create input playback/capture controls for the given pin */
2439static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2440 const char *ctlname, int boost)
2441{
2442 char name[32];
2443 int err, idx;
2444
2445 sprintf(name, "%s Playback Volume", ctlname);
2446 idx = ad1988_pin_to_loopback_idx(pin);
2447 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2448 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2449 return err;
2450 sprintf(name, "%s Playback Switch", ctlname);
2451 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2452 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2453 return err;
2454 if (boost) {
2455 hda_nid_t bnid;
2456 idx = ad1988_pin_idx(pin);
2457 bnid = ad1988_boost_nids[idx];
2458 if (bnid) {
2459 sprintf(name, "%s Boost", ctlname);
2460 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2461 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2462
2463 }
2464 }
2465 return 0;
2466}
2467
2468/* create playback/capture controls for input pins */
2469static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2470 const struct auto_pin_cfg *cfg)
2471{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002472 struct hda_input_mux *imux = &spec->private_imux;
2473 int i, err;
2474
2475 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002476 err = new_analog_input(spec, cfg->input_pins[i],
2477 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002478 i <= AUTO_PIN_FRONT_MIC);
2479 if (err < 0)
2480 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002481 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002482 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2483 imux->num_items++;
2484 }
2485 imux->items[imux->num_items].label = "Mix";
2486 imux->items[imux->num_items].index = 9;
2487 imux->num_items++;
2488
2489 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2490 "Analog Mix Playback Volume",
2491 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2492 return err;
2493 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2494 "Analog Mix Playback Switch",
2495 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2496 return err;
2497
2498 return 0;
2499}
2500
2501static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2502 hda_nid_t nid, int pin_type,
2503 int dac_idx)
2504{
2505 /* set as output */
2506 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2507 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2508 switch (nid) {
2509 case 0x11: /* port-A - DAC 04 */
2510 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2511 break;
2512 case 0x14: /* port-B - DAC 06 */
2513 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2514 break;
2515 case 0x15: /* port-C - DAC 05 */
2516 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2517 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002518 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002519 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2520 break;
2521 case 0x13: /* mono - DAC 04 */
2522 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2523 break;
2524 }
2525}
2526
2527static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2528{
2529 struct ad198x_spec *spec = codec->spec;
2530 int i;
2531
2532 for (i = 0; i < spec->autocfg.line_outs; i++) {
2533 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2534 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2535 }
2536}
2537
2538static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2539{
2540 struct ad198x_spec *spec = codec->spec;
2541 hda_nid_t pin;
2542
Takashi Iwai82bc9552006-03-21 11:24:42 +01002543 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002544 if (pin) /* connect to front */
2545 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002546 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002547 if (pin) /* connect to front */
2548 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2549}
2550
2551static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2552{
2553 struct ad198x_spec *spec = codec->spec;
2554 int i, idx;
2555
2556 for (i = 0; i < AUTO_PIN_LAST; i++) {
2557 hda_nid_t nid = spec->autocfg.input_pins[i];
2558 if (! nid)
2559 continue;
2560 switch (nid) {
2561 case 0x15: /* port-C */
2562 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2563 break;
2564 case 0x17: /* port-E */
2565 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2566 break;
2567 }
2568 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2569 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2570 if (nid != AD1988_PIN_CD_NID)
2571 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2572 AMP_OUT_MUTE);
2573 idx = ad1988_pin_idx(nid);
2574 if (ad1988_boost_nids[idx])
2575 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2576 AC_VERB_SET_AMP_GAIN_MUTE,
2577 AMP_OUT_ZERO);
2578 }
2579}
2580
2581/* parse the BIOS configuration and set up the alc_spec */
2582/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2583static int ad1988_parse_auto_config(struct hda_codec *codec)
2584{
2585 struct ad198x_spec *spec = codec->spec;
2586 int err;
2587
Kailang Yangdf694da2005-12-05 19:42:22 +01002588 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002589 return err;
2590 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2591 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002592 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002593 return 0; /* can't find valid BIOS pin config */
2594 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002595 (err = ad1988_auto_create_extra_out(codec,
2596 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002597 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002598 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002599 "Headphone")) < 0 ||
2600 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2601 return err;
2602
2603 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2604
2605 if (spec->autocfg.dig_out_pin)
2606 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2607 if (spec->autocfg.dig_in_pin)
2608 spec->dig_in_nid = AD1988_SPDIF_IN;
2609
2610 if (spec->kctl_alloc)
2611 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2612
2613 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2614
2615 spec->input_mux = &spec->private_imux;
2616
2617 return 1;
2618}
2619
2620/* init callback for auto-configuration model -- overriding the default init */
2621static int ad1988_auto_init(struct hda_codec *codec)
2622{
2623 ad198x_init(codec);
2624 ad1988_auto_init_multi_out(codec);
2625 ad1988_auto_init_extra_out(codec);
2626 ad1988_auto_init_analog_input(codec);
2627 return 0;
2628}
2629
2630
2631/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002632 */
2633
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002634static const char *ad1988_models[AD1988_MODEL_LAST] = {
2635 [AD1988_6STACK] = "6stack",
2636 [AD1988_6STACK_DIG] = "6stack-dig",
2637 [AD1988_3STACK] = "3stack",
2638 [AD1988_3STACK_DIG] = "3stack-dig",
2639 [AD1988_LAPTOP] = "laptop",
2640 [AD1988_LAPTOP_DIG] = "laptop-dig",
2641 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002642};
2643
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002644static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2645 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Tobin Davis18768992007-03-12 22:20:51 +01002646 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002647 {}
2648};
2649
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002650static int patch_ad1988(struct hda_codec *codec)
2651{
2652 struct ad198x_spec *spec;
2653 int board_config;
2654
2655 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2656 if (spec == NULL)
2657 return -ENOMEM;
2658
Ingo Molnar62932df2006-01-16 16:34:20 +01002659 mutex_init(&spec->amp_mutex);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002660 codec->spec = spec;
2661
Takashi Iwai1a806f42006-07-03 15:58:16 +02002662 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002663 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2664
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002665 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002666 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002667 if (board_config < 0) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002668 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2669 board_config = AD1988_AUTO;
2670 }
2671
2672 if (board_config == AD1988_AUTO) {
2673 /* automatic parse from the BIOS config */
2674 int err = ad1988_parse_auto_config(codec);
2675 if (err < 0) {
2676 ad198x_free(codec);
2677 return err;
2678 } else if (! err) {
2679 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2680 board_config = AD1988_6STACK;
2681 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002682 }
2683
2684 switch (board_config) {
2685 case AD1988_6STACK:
2686 case AD1988_6STACK_DIG:
2687 spec->multiout.max_channels = 8;
2688 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002689 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002690 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2691 else
2692 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002693 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002694 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002695 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002696 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2697 else
2698 spec->mixers[0] = ad1988_6stack_mixers1;
2699 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002700 spec->num_init_verbs = 1;
2701 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2702 if (board_config == AD1988_6STACK_DIG) {
2703 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2704 spec->dig_in_nid = AD1988_SPDIF_IN;
2705 }
2706 break;
2707 case AD1988_3STACK:
2708 case AD1988_3STACK_DIG:
2709 spec->multiout.max_channels = 6;
2710 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002711 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002712 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2713 else
2714 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002715 spec->input_mux = &ad1988_6stack_capture_source;
2716 spec->channel_mode = ad1988_3stack_modes;
2717 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002718 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002719 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002720 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2721 else
2722 spec->mixers[0] = ad1988_3stack_mixers1;
2723 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002724 spec->num_init_verbs = 1;
2725 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2726 if (board_config == AD1988_3STACK_DIG)
2727 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2728 break;
2729 case AD1988_LAPTOP:
2730 case AD1988_LAPTOP_DIG:
2731 spec->multiout.max_channels = 2;
2732 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002733 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002734 spec->input_mux = &ad1988_laptop_capture_source;
2735 spec->num_mixers = 1;
2736 spec->mixers[0] = ad1988_laptop_mixers;
2737 spec->num_init_verbs = 1;
2738 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2739 if (board_config == AD1988_LAPTOP_DIG)
2740 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2741 break;
2742 }
2743
Takashi Iwaid32410b12005-11-24 16:06:23 +01002744 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2745 spec->adc_nids = ad1988_adc_nids;
2746 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002747 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2748 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2749 if (spec->multiout.dig_out_nid) {
2750 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2751 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2752 }
2753 if (spec->dig_in_nid)
2754 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2755
2756 codec->patch_ops = ad198x_patch_ops;
2757 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002758 case AD1988_AUTO:
2759 codec->patch_ops.init = ad1988_auto_init;
2760 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002761 case AD1988_LAPTOP:
2762 case AD1988_LAPTOP_DIG:
2763 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2764 break;
2765 }
2766
2767 return 0;
2768}
2769
2770
2771/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 * patch entries
2773 */
2774struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002775 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2776 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002778 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02002779 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 {} /* terminator */
2781};