blob: cc2e944cc59f17c48f949004ce94ffeb2ba67d38 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02002 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Takashi Iwai2bac6472007-05-18 18:21:41 +02005 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <sound/driver.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010027#include <linux/mutex.h>
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <sound/core.h>
30#include "hda_codec.h"
31#include "hda_local.h"
32
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020033struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010034 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010035 int num_mixers;
36
Takashi Iwaid32410b12005-11-24 16:06:23 +010037 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010038 * don't forget NULL termination!
39 */
40 unsigned int num_init_verbs;
41
42 /* playback */
43 struct hda_multi_out multiout; /* playback set-up
44 * max_channels, dacs must be set
45 * dig_out_nid and hp_nid are optional
46 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010047 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020048 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010049
50 /* capture */
51 unsigned int num_adc_nids;
52 hda_nid_t *adc_nids;
53 hda_nid_t dig_in_nid; /* digital-in NID; optional */
54
55 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020056 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010057 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010058 unsigned int cur_mux[3];
59
60 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010061 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010062 int num_channel_mode;
63
64 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020065 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010066
Ingo Molnar62932df2006-01-16 16:34:20 +010067 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020068 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010069
70 /* dynamic controls, init_verbs and input_mux */
71 struct auto_pin_cfg autocfg;
72 unsigned int num_kctl_alloc, num_kctl_used;
73 struct snd_kcontrol_new *kctl_alloc;
74 struct hda_input_mux private_imux;
75 hda_nid_t private_dac_nids[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020078/*
79 * input MUX handling (common part)
80 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010081static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020082{
83 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
84 struct ad198x_spec *spec = codec->spec;
85
86 return snd_hda_input_mux_info(spec->input_mux, uinfo);
87}
88
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010089static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020090{
91 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
92 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020094
Takashi Iwai985be542005-11-02 18:26:49 +010095 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020096 return 0;
97}
98
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010099static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200100{
101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
102 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100103 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200104
105 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100106 spec->capsrc_nids[adc_idx],
107 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200108}
109
110/*
111 * initialization (common callbacks)
112 */
113static int ad198x_init(struct hda_codec *codec)
114{
115 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100116 int i;
117
118 for (i = 0; i < spec->num_init_verbs; i++)
119 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200120 return 0;
121}
122
123static int ad198x_build_controls(struct hda_codec *codec)
124{
125 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100126 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200127 int err;
128
Takashi Iwai985be542005-11-02 18:26:49 +0100129 for (i = 0; i < spec->num_mixers; i++) {
130 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
131 if (err < 0)
132 return err;
133 }
134 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200135 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100136 if (err < 0)
137 return err;
138 }
139 if (spec->dig_in_nid) {
140 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
141 if (err < 0)
142 return err;
143 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200144 return 0;
145}
146
147/*
148 * Analog playback callbacks
149 */
150static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
151 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100152 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200153{
154 struct ad198x_spec *spec = codec->spec;
155 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
156}
157
158static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100162 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200163{
164 struct ad198x_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
166 format, substream);
167}
168
169static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
170 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100171 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200172{
173 struct ad198x_spec *spec = codec->spec;
174 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
175}
176
177/*
178 * Digital out
179 */
180static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
181 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100182 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200183{
184 struct ad198x_spec *spec = codec->spec;
185 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
186}
187
188static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100190 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200191{
192 struct ad198x_spec *spec = codec->spec;
193 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
194}
195
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200196static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
197 struct hda_codec *codec,
198 unsigned int stream_tag,
199 unsigned int format,
200 struct snd_pcm_substream *substream)
201{
202 struct ad198x_spec *spec = codec->spec;
203 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
204 format, substream);
205}
206
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200207/*
208 * Analog capture
209 */
210static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 unsigned int stream_tag,
213 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100214 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200215{
216 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100217 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
218 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200219 return 0;
220}
221
222static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
223 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100224 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200225{
226 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100227 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
228 0, 0, 0);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200229 return 0;
230}
231
232
233/*
234 */
235static struct hda_pcm_stream ad198x_pcm_analog_playback = {
236 .substreams = 1,
237 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100238 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200239 .nid = 0, /* fill later */
240 .ops = {
241 .open = ad198x_playback_pcm_open,
242 .prepare = ad198x_playback_pcm_prepare,
243 .cleanup = ad198x_playback_pcm_cleanup
244 },
245};
246
247static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100248 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200249 .channels_min = 2,
250 .channels_max = 2,
251 .nid = 0, /* fill later */
252 .ops = {
253 .prepare = ad198x_capture_pcm_prepare,
254 .cleanup = ad198x_capture_pcm_cleanup
255 },
256};
257
258static struct hda_pcm_stream ad198x_pcm_digital_playback = {
259 .substreams = 1,
260 .channels_min = 2,
261 .channels_max = 2,
262 .nid = 0, /* fill later */
263 .ops = {
264 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200265 .close = ad198x_dig_playback_pcm_close,
266 .prepare = ad198x_dig_playback_pcm_prepare
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200267 },
268};
269
Takashi Iwai985be542005-11-02 18:26:49 +0100270static struct hda_pcm_stream ad198x_pcm_digital_capture = {
271 .substreams = 1,
272 .channels_min = 2,
273 .channels_max = 2,
274 /* NID is set in alc_build_pcms */
275};
276
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200277static int ad198x_build_pcms(struct hda_codec *codec)
278{
279 struct ad198x_spec *spec = codec->spec;
280 struct hda_pcm *info = spec->pcm_rec;
281
282 codec->num_pcms = 1;
283 codec->pcm_info = info;
284
285 info->name = "AD198x Analog";
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
289 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100290 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
291 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200292
293 if (spec->multiout.dig_out_nid) {
294 info++;
295 codec->num_pcms++;
296 info->name = "AD198x Digital";
297 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
298 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100299 if (spec->dig_in_nid) {
300 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
302 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200303 }
304
305 return 0;
306}
307
308static void ad198x_free(struct hda_codec *codec)
309{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100310 struct ad198x_spec *spec = codec->spec;
311 unsigned int i;
312
313 if (spec->kctl_alloc) {
314 for (i = 0; i < spec->num_kctl_used; i++)
315 kfree(spec->kctl_alloc[i].name);
316 kfree(spec->kctl_alloc);
317 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200318 kfree(codec->spec);
319}
320
321#ifdef CONFIG_PM
322static int ad198x_resume(struct hda_codec *codec)
323{
324 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100325 int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200326
Takashi Iwai18a815d2006-03-01 19:54:39 +0100327 codec->patch_ops.init(codec);
Takashi Iwai985be542005-11-02 18:26:49 +0100328 for (i = 0; i < spec->num_mixers; i++)
329 snd_hda_resume_ctls(codec, spec->mixers[i]);
330 if (spec->multiout.dig_out_nid)
331 snd_hda_resume_spdif_out(codec);
332 if (spec->dig_in_nid)
333 snd_hda_resume_spdif_in(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200334 return 0;
335}
336#endif
337
338static struct hda_codec_ops ad198x_patch_ops = {
339 .build_controls = ad198x_build_controls,
340 .build_pcms = ad198x_build_pcms,
341 .init = ad198x_init,
342 .free = ad198x_free,
343#ifdef CONFIG_PM
344 .resume = ad198x_resume,
345#endif
346};
347
348
349/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100350 * EAPD control
351 * the private value = nid | (invert << 8)
352 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200353#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100354
355static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
357{
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359 struct ad198x_spec *spec = codec->spec;
360 int invert = (kcontrol->private_value >> 8) & 1;
361 if (invert)
362 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
363 else
364 ucontrol->value.integer.value[0] = spec->cur_eapd;
365 return 0;
366}
367
368static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_value *ucontrol)
370{
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct ad198x_spec *spec = codec->spec;
373 int invert = (kcontrol->private_value >> 8) & 1;
374 hda_nid_t nid = kcontrol->private_value & 0xff;
375 unsigned int eapd;
376 eapd = ucontrol->value.integer.value[0];
377 if (invert)
378 eapd = !eapd;
379 if (eapd == spec->cur_eapd && ! codec->in_resume)
380 return 0;
381 spec->cur_eapd = eapd;
382 snd_hda_codec_write(codec, nid,
383 0, AC_VERB_SET_EAPD_BTLENABLE,
384 eapd ? 0x02 : 0x00);
385 return 1;
386}
387
Takashi Iwai9230d212006-03-13 13:49:49 +0100388static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_info *uinfo);
390static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
391 struct snd_ctl_elem_value *ucontrol);
392static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
393 struct snd_ctl_elem_value *ucontrol);
394
395
Takashi Iwai18a815d2006-03-01 19:54:39 +0100396/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200397 * AD1986A specific
398 */
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define AD1986A_SPDIF_OUT 0x02
401#define AD1986A_FRONT_DAC 0x03
402#define AD1986A_SURR_DAC 0x04
403#define AD1986A_CLFE_DAC 0x05
404#define AD1986A_ADC 0x06
405
406static hda_nid_t ad1986a_dac_nids[3] = {
407 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
408};
Takashi Iwai985be542005-11-02 18:26:49 +0100409static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100410static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412static struct hda_input_mux ad1986a_capture_source = {
413 .num_items = 7,
414 .items = {
415 { "Mic", 0x0 },
416 { "CD", 0x1 },
417 { "Aux", 0x3 },
418 { "Line", 0x4 },
419 { "Mix", 0x5 },
420 { "Mono", 0x6 },
421 { "Phone", 0x7 },
422 },
423};
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Takashi Iwai532d5382007-07-27 19:02:40 +0200426static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
427 .ops = &snd_hda_bind_vol,
428 .values = {
429 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
432 0
433 },
434};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Takashi Iwai532d5382007-07-27 19:02:40 +0200436static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
437 .ops = &snd_hda_bind_sw,
438 .values = {
439 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
440 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
441 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
442 0
443 },
444};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 * mixers
448 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100449static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200450 /*
451 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
452 */
453 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
454 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
456 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
457 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
458 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
459 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
460 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
461 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
462 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
463 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
464 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
465 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
466 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
467 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
468 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
469 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
470 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
471 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
472 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100473 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
475 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
476 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
477 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
478 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
479 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
480 {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200483 .info = ad198x_mux_enum_info,
484 .get = ad198x_mux_enum_get,
485 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
487 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
488 { } /* end */
489};
490
Takashi Iwai9230d212006-03-13 13:49:49 +0100491/* additional mixers for 3stack mode */
492static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
493 {
494 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
495 .name = "Channel Mode",
496 .info = ad198x_ch_mode_info,
497 .get = ad198x_ch_mode_get,
498 .put = ad198x_ch_mode_put,
499 },
500 { } /* end */
501};
502
503/* laptop model - 2ch only */
504static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
505
506static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
507 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
508 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
509 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
510 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
511 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
512 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
513 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
517 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
518 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
519 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
520 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100521 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai9230d212006-03-13 13:49:49 +0100522 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
526 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
528 {
529 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
530 .name = "Capture Source",
531 .info = ad198x_mux_enum_info,
532 .get = ad198x_mux_enum_get,
533 .put = ad198x_mux_enum_put,
534 },
535 { } /* end */
536};
537
Takashi Iwai825aa972006-03-17 10:50:49 +0100538/* laptop-eapd model - 2ch only */
539
540/* master controls both pins 0x1a and 0x1b */
Takashi Iwai532d5382007-07-27 19:02:40 +0200541static struct hda_bind_ctls ad1986a_laptop_master_vol = {
542 .ops = &snd_hda_bind_vol,
543 .values = {
544 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
545 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
546 0,
547 },
548};
Takashi Iwai825aa972006-03-17 10:50:49 +0100549
Takashi Iwai532d5382007-07-27 19:02:40 +0200550static struct hda_bind_ctls ad1986a_laptop_master_sw = {
551 .ops = &snd_hda_bind_sw,
552 .values = {
553 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
554 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
555 0,
556 },
557};
Takashi Iwai825aa972006-03-17 10:50:49 +0100558
559static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
560 .num_items = 3,
561 .items = {
562 { "Mic", 0x0 },
563 { "Internal Mic", 0x4 },
564 { "Mix", 0x5 },
565 },
566};
567
568static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200569 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
570 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai825aa972006-03-17 10:50:49 +0100571 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
572 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
575 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
576 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100577 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100578 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
580 {
581 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
582 .name = "Capture Source",
583 .info = ad198x_mux_enum_info,
584 .get = ad198x_mux_enum_get,
585 .put = ad198x_mux_enum_put,
586 },
587 {
588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
589 .name = "External Amplifier",
590 .info = ad198x_eapd_info,
591 .get = ad198x_eapd_get,
592 .put = ad198x_eapd_put,
593 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
594 },
595 { } /* end */
596};
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598/*
599 * initialization verbs
600 */
601static struct hda_verb ad1986a_init_verbs[] = {
602 /* Front, Surround, CLFE DAC; mute as default */
603 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
604 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
605 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
606 /* Downmix - off */
607 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
608 /* HP, Line-Out, Surround, CLFE selectors */
609 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
610 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
611 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
612 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
613 /* Mono selector */
614 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
615 /* Mic selector: Mic 1/2 pin */
616 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
617 /* Line-in selector: Line-in */
618 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
619 /* Mic 1/2 swap */
620 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
621 /* Record selector: mic */
622 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
623 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
624 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
625 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
626 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
627 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
628 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
629 /* PC beep */
630 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
631 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
632 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
633 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
634 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
635 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
636 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200637 /* HP Pin */
638 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
639 /* Front, Surround, CLFE Pins */
640 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
641 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
642 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
643 /* Mono Pin */
644 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
645 /* Mic Pin */
646 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
647 /* Line, Aux, CD, Beep-In Pin */
648 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
649 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
650 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
651 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
652 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 { } /* end */
654};
655
Takashi Iwai9230d212006-03-13 13:49:49 +0100656static struct hda_verb ad1986a_ch2_init[] = {
657 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200658 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
659 /* Line-in selectors */
660 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100661 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200662 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
663 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
664 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100665 { } /* end */
666};
667
668static struct hda_verb ad1986a_ch4_init[] = {
669 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200670 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
671 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100672 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200673 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
674 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100675 { } /* end */
676};
677
678static struct hda_verb ad1986a_ch6_init[] = {
679 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200680 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
681 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100682 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200683 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
684 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100685 { } /* end */
686};
687
688static struct hda_channel_mode ad1986a_modes[3] = {
689 { 2, ad1986a_ch2_init },
690 { 4, ad1986a_ch4_init },
691 { 6, ad1986a_ch6_init },
692};
693
Takashi Iwai825aa972006-03-17 10:50:49 +0100694/* eapd initialization */
695static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100696 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +0100697 {}
698};
699
Tobin Davisf36090f2007-01-08 11:07:12 +0100700/* Ultra initialization */
701static struct hda_verb ad1986a_ultra_init[] = {
702 /* eapd initialization */
703 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
704 /* CLFE -> Mic in */
705 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
706 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
707 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
708 { } /* end */
709};
710
Takashi Iwai9230d212006-03-13 13:49:49 +0100711/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100712enum {
713 AD1986A_6STACK,
714 AD1986A_3STACK,
715 AD1986A_LAPTOP,
716 AD1986A_LAPTOP_EAPD,
Tobin Davisf36090f2007-01-08 11:07:12 +0100717 AD1986A_ULTRA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100718 AD1986A_MODELS
719};
Takashi Iwai9230d212006-03-13 13:49:49 +0100720
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100721static const char *ad1986a_models[AD1986A_MODELS] = {
722 [AD1986A_6STACK] = "6stack",
723 [AD1986A_3STACK] = "3stack",
724 [AD1986A_LAPTOP] = "laptop",
725 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisf36090f2007-01-08 11:07:12 +0100726 [AD1986A_ULTRA] = "ultra",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100727};
728
729static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
730 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
731 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
732 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
733 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
734 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
735 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
736 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
737 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
738 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davis658fba02007-04-23 16:41:12 +0200739 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100740 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
741 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
742 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
743 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
744 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +0100745 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100746 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
747 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
748 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
749 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
Tobin Davisf36090f2007-01-08 11:07:12 +0100750 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
751 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Tobin Davis18768992007-03-12 22:20:51 +0100752 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100753 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
754 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
755 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +0100756 {}
757};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759static int patch_ad1986a(struct hda_codec *codec)
760{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200761 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100762 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200764 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 if (spec == NULL)
766 return -ENOMEM;
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 codec->spec = spec;
769
770 spec->multiout.max_channels = 6;
771 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
772 spec->multiout.dac_nids = ad1986a_dac_nids;
773 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100774 spec->num_adc_nids = 1;
775 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100776 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200777 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100778 spec->num_mixers = 1;
779 spec->mixers[0] = ad1986a_mixers;
780 spec->num_init_verbs = 1;
781 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200783 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Takashi Iwai9230d212006-03-13 13:49:49 +0100785 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100786 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
787 ad1986a_models,
788 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +0100789 switch (board_config) {
790 case AD1986A_3STACK:
791 spec->num_mixers = 2;
792 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +0200793 spec->num_init_verbs = 2;
794 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100795 spec->channel_mode = ad1986a_modes;
796 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200797 spec->need_dac_fix = 1;
798 spec->multiout.max_channels = 2;
799 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100800 break;
801 case AD1986A_LAPTOP:
802 spec->mixers[0] = ad1986a_laptop_mixers;
803 spec->multiout.max_channels = 2;
804 spec->multiout.num_dacs = 1;
805 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
806 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100807 case AD1986A_LAPTOP_EAPD:
808 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
809 spec->num_init_verbs = 2;
810 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
811 spec->multiout.max_channels = 2;
812 spec->multiout.num_dacs = 1;
813 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
814 spec->multiout.dig_out_nid = 0;
815 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
816 break;
Tobin Davisf36090f2007-01-08 11:07:12 +0100817 case AD1986A_ULTRA:
818 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
819 spec->num_init_verbs = 2;
820 spec->init_verbs[1] = ad1986a_ultra_init;
821 spec->multiout.max_channels = 2;
822 spec->multiout.num_dacs = 1;
823 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
824 spec->multiout.dig_out_nid = 0;
825 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100826 }
827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return 0;
829}
830
831/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200832 * AD1983 specific
833 */
834
835#define AD1983_SPDIF_OUT 0x02
836#define AD1983_DAC 0x03
837#define AD1983_ADC 0x04
838
839static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100840static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100841static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200842
843static struct hda_input_mux ad1983_capture_source = {
844 .num_items = 4,
845 .items = {
846 { "Mic", 0x0 },
847 { "Line", 0x1 },
848 { "Mix", 0x2 },
849 { "Mix Mono", 0x3 },
850 },
851};
852
853/*
854 * SPDIF playback route
855 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100856static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200857{
858 static char *texts[] = { "PCM", "ADC" };
859
860 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
861 uinfo->count = 1;
862 uinfo->value.enumerated.items = 2;
863 if (uinfo->value.enumerated.item > 1)
864 uinfo->value.enumerated.item = 1;
865 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
866 return 0;
867}
868
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100869static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200870{
871 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
872 struct ad198x_spec *spec = codec->spec;
873
874 ucontrol->value.enumerated.item[0] = spec->spdif_route;
875 return 0;
876}
877
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100878static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200879{
880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
881 struct ad198x_spec *spec = codec->spec;
882
883 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
884 spec->spdif_route = ucontrol->value.enumerated.item[0];
885 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
886 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
887 return 1;
888 }
889 return 0;
890}
891
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100892static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200893 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
894 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
895 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
896 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
897 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
898 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
899 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
900 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
901 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
902 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
903 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
904 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
905 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
906 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
907 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
908 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
909 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
910 {
911 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
912 .name = "Capture Source",
913 .info = ad198x_mux_enum_info,
914 .get = ad198x_mux_enum_get,
915 .put = ad198x_mux_enum_put,
916 },
917 {
918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +0200919 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200920 .info = ad1983_spdif_route_info,
921 .get = ad1983_spdif_route_get,
922 .put = ad1983_spdif_route_put,
923 },
924 { } /* end */
925};
926
927static struct hda_verb ad1983_init_verbs[] = {
928 /* Front, HP, Mono; mute as default */
929 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
930 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
931 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
932 /* Beep, PCM, Mic, Line-In: mute */
933 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
934 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
935 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
936 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
937 /* Front, HP selectors; from Mix */
938 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
939 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
940 /* Mono selector; from Mix */
941 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
942 /* Mic selector; Mic */
943 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
944 /* Line-in selector: Line-in */
945 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
946 /* Mic boost: 0dB */
947 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
948 /* Record selector: mic */
949 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
950 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
951 /* SPDIF route: PCM */
952 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
953 /* Front Pin */
954 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
955 /* HP Pin */
956 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
957 /* Mono Pin */
958 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
959 /* Mic Pin */
960 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
961 /* Line Pin */
962 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
963 { } /* end */
964};
965
Takashi Iwai985be542005-11-02 18:26:49 +0100966
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200967static int patch_ad1983(struct hda_codec *codec)
968{
969 struct ad198x_spec *spec;
970
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200971 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200972 if (spec == NULL)
973 return -ENOMEM;
974
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200975 codec->spec = spec;
976
977 spec->multiout.max_channels = 2;
978 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
979 spec->multiout.dac_nids = ad1983_dac_nids;
980 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100981 spec->num_adc_nids = 1;
982 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100983 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200984 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100985 spec->num_mixers = 1;
986 spec->mixers[0] = ad1983_mixers;
987 spec->num_init_verbs = 1;
988 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200989 spec->spdif_route = 0;
990
991 codec->patch_ops = ad198x_patch_ops;
992
993 return 0;
994}
995
996
997/*
998 * AD1981 HD specific
999 */
1000
1001#define AD1981_SPDIF_OUT 0x02
1002#define AD1981_DAC 0x03
1003#define AD1981_ADC 0x04
1004
1005static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001006static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001007static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001008
1009/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1010static struct hda_input_mux ad1981_capture_source = {
1011 .num_items = 7,
1012 .items = {
1013 { "Front Mic", 0x0 },
1014 { "Line", 0x1 },
1015 { "Mix", 0x2 },
1016 { "Mix Mono", 0x3 },
1017 { "CD", 0x4 },
1018 { "Mic", 0x6 },
1019 { "Aux", 0x7 },
1020 },
1021};
1022
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001023static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001024 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1026 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1027 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1028 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1029 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1030 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1031 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1032 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1033 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1034 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1035 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1036 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1038 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1039 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1041 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1042 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1043 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1044 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1045 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1046 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1048 {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = "Capture Source",
1051 .info = ad198x_mux_enum_info,
1052 .get = ad198x_mux_enum_get,
1053 .put = ad198x_mux_enum_put,
1054 },
1055 /* identical with AD1983 */
1056 {
1057 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001058 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001059 .info = ad1983_spdif_route_info,
1060 .get = ad1983_spdif_route_get,
1061 .put = ad1983_spdif_route_put,
1062 },
1063 { } /* end */
1064};
1065
1066static struct hda_verb ad1981_init_verbs[] = {
1067 /* Front, HP, Mono; mute as default */
1068 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1069 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1070 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1071 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1072 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1073 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1074 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1075 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1076 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1077 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1078 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1079 /* Front, HP selectors; from Mix */
1080 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1081 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1082 /* Mono selector; from Mix */
1083 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1084 /* Mic Mixer; select Front Mic */
1085 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1086 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1087 /* Mic boost: 0dB */
1088 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1089 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1090 /* Record selector: Front mic */
1091 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1092 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1093 /* SPDIF route: PCM */
1094 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1095 /* Front Pin */
1096 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1097 /* HP Pin */
1098 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1099 /* Mono Pin */
1100 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1101 /* Front & Rear Mic Pins */
1102 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1103 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1104 /* Line Pin */
1105 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1106 /* Digital Beep */
1107 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1108 /* Line-Out as Input: disabled */
1109 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1110 { } /* end */
1111};
1112
Takashi Iwai18a815d2006-03-01 19:54:39 +01001113/*
1114 * Patch for HP nx6320
1115 *
Tobin Davis18768992007-03-12 22:20:51 +01001116 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001117 * speaker output enabled _and_ mute-LED off.
1118 */
1119
1120#define AD1981_HP_EVENT 0x37
1121#define AD1981_MIC_EVENT 0x38
1122
1123static struct hda_verb ad1981_hp_init_verbs[] = {
1124 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1125 /* pin sensing on HP and Mic jacks */
1126 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1127 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1128 {}
1129};
1130
1131/* turn on/off EAPD (+ mute HP) as a master switch */
1132static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1133 struct snd_ctl_elem_value *ucontrol)
1134{
1135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1136 struct ad198x_spec *spec = codec->spec;
1137
1138 if (! ad198x_eapd_put(kcontrol, ucontrol))
1139 return 0;
1140
1141 /* toggle HP mute appropriately */
1142 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1143 0x80, spec->cur_eapd ? 0 : 0x80);
1144 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1145 0x80, spec->cur_eapd ? 0 : 0x80);
1146 return 1;
1147}
1148
1149/* bind volumes of both NID 0x05 and 0x06 */
1150static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1151 struct snd_ctl_elem_value *ucontrol)
1152{
1153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1154 long *valp = ucontrol->value.integer.value;
1155 int change;
1156
1157 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1158 0x7f, valp[0] & 0x7f);
1159 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1160 0x7f, valp[1] & 0x7f);
1161 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1162 0x7f, valp[0] & 0x7f);
1163 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1164 0x7f, valp[1] & 0x7f);
1165 return change;
1166}
1167
1168/* mute internal speaker if HP is plugged */
1169static void ad1981_hp_automute(struct hda_codec *codec)
1170{
1171 unsigned int present;
1172
1173 present = snd_hda_codec_read(codec, 0x06, 0,
1174 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1175 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1176 0x80, present ? 0x80 : 0);
1177 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1178 0x80, present ? 0x80 : 0);
1179}
1180
1181/* toggle input of built-in and mic jack appropriately */
1182static void ad1981_hp_automic(struct hda_codec *codec)
1183{
1184 static struct hda_verb mic_jack_on[] = {
1185 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1186 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1187 {}
1188 };
1189 static struct hda_verb mic_jack_off[] = {
1190 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1191 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1192 {}
1193 };
1194 unsigned int present;
1195
1196 present = snd_hda_codec_read(codec, 0x08, 0,
1197 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1198 if (present)
1199 snd_hda_sequence_write(codec, mic_jack_on);
1200 else
1201 snd_hda_sequence_write(codec, mic_jack_off);
1202}
1203
1204/* unsolicited event for HP jack sensing */
1205static void ad1981_hp_unsol_event(struct hda_codec *codec,
1206 unsigned int res)
1207{
1208 res >>= 26;
1209 switch (res) {
1210 case AD1981_HP_EVENT:
1211 ad1981_hp_automute(codec);
1212 break;
1213 case AD1981_MIC_EVENT:
1214 ad1981_hp_automic(codec);
1215 break;
1216 }
1217}
1218
1219static struct hda_input_mux ad1981_hp_capture_source = {
1220 .num_items = 3,
1221 .items = {
1222 { "Mic", 0x0 },
1223 { "Docking-Station", 0x1 },
1224 { "Mix", 0x2 },
1225 },
1226};
1227
1228static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1229 {
1230 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1231 .name = "Master Playback Volume",
1232 .info = snd_hda_mixer_amp_volume_info,
1233 .get = snd_hda_mixer_amp_volume_get,
1234 .put = ad1981_hp_master_vol_put,
1235 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1236 },
1237 {
1238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1239 .name = "Master Playback Switch",
1240 .info = ad198x_eapd_info,
1241 .get = ad198x_eapd_get,
1242 .put = ad1981_hp_master_sw_put,
1243 .private_value = 0x05,
1244 },
1245 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1246 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1247#if 0
1248 /* FIXME: analog mic/line loopback doesn't work with my tests...
1249 * (although recording is OK)
1250 */
1251 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1252 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1253 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1254 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1255 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1256 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1257 /* FIXME: does this laptop have analog CD connection? */
1258 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1259 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1260#endif
1261 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1262 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1263 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1265 {
1266 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1267 .name = "Capture Source",
1268 .info = ad198x_mux_enum_info,
1269 .get = ad198x_mux_enum_get,
1270 .put = ad198x_mux_enum_put,
1271 },
1272 { } /* end */
1273};
1274
1275/* initialize jack-sensing, too */
1276static int ad1981_hp_init(struct hda_codec *codec)
1277{
1278 ad198x_init(codec);
1279 ad1981_hp_automute(codec);
1280 ad1981_hp_automic(codec);
1281 return 0;
1282}
1283
Tobin Davis18768992007-03-12 22:20:51 +01001284/* configuration for Toshiba Laptops */
1285static struct hda_verb ad1981_toshiba_init_verbs[] = {
1286 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1287 /* pin sensing on HP and Mic jacks */
1288 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1289 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1290 {}
1291};
1292
1293static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1294 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1295 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1296 { }
1297};
1298
Takashi Iwai01686c52006-04-18 12:54:11 +02001299/* configuration for Lenovo Thinkpad T60 */
1300static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1301 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1302 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1303 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1304 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1305 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1306 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1307 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1308 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1309 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1310 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1311 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1312 {
1313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1314 .name = "Capture Source",
1315 .info = ad198x_mux_enum_info,
1316 .get = ad198x_mux_enum_get,
1317 .put = ad198x_mux_enum_put,
1318 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001319 /* identical with AD1983 */
1320 {
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1323 .info = ad1983_spdif_route_info,
1324 .get = ad1983_spdif_route_get,
1325 .put = ad1983_spdif_route_put,
1326 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001327 { } /* end */
1328};
1329
1330static struct hda_input_mux ad1981_thinkpad_capture_source = {
1331 .num_items = 3,
1332 .items = {
1333 { "Mic", 0x0 },
1334 { "Mix", 0x2 },
1335 { "CD", 0x4 },
1336 },
1337};
1338
Takashi Iwai18a815d2006-03-01 19:54:39 +01001339/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001340enum {
1341 AD1981_BASIC,
1342 AD1981_HP,
1343 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001344 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001345 AD1981_MODELS
1346};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001347
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001348static const char *ad1981_models[AD1981_MODELS] = {
1349 [AD1981_HP] = "hp",
1350 [AD1981_THINKPAD] = "thinkpad",
1351 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001352 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001353};
1354
1355static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001356 /* All HP models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001357 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1358 /* HP nx6320 (reversed SSID, H/W bug) */
1359 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai01686c52006-04-18 12:54:11 +02001360 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001361 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1362 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Tobin Davis18768992007-03-12 22:20:51 +01001363 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001364 {}
1365};
1366
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001367static int patch_ad1981(struct hda_codec *codec)
1368{
1369 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001370 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001371
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001372 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001373 if (spec == NULL)
1374 return -ENOMEM;
1375
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001376 codec->spec = spec;
1377
1378 spec->multiout.max_channels = 2;
1379 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1380 spec->multiout.dac_nids = ad1981_dac_nids;
1381 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001382 spec->num_adc_nids = 1;
1383 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001384 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001385 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001386 spec->num_mixers = 1;
1387 spec->mixers[0] = ad1981_mixers;
1388 spec->num_init_verbs = 1;
1389 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001390 spec->spdif_route = 0;
1391
1392 codec->patch_ops = ad198x_patch_ops;
1393
Takashi Iwai18a815d2006-03-01 19:54:39 +01001394 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001395 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1396 ad1981_models,
1397 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001398 switch (board_config) {
1399 case AD1981_HP:
1400 spec->mixers[0] = ad1981_hp_mixers;
1401 spec->num_init_verbs = 2;
1402 spec->init_verbs[1] = ad1981_hp_init_verbs;
1403 spec->multiout.dig_out_nid = 0;
1404 spec->input_mux = &ad1981_hp_capture_source;
1405
1406 codec->patch_ops.init = ad1981_hp_init;
1407 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1408 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001409 case AD1981_THINKPAD:
1410 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001411 spec->input_mux = &ad1981_thinkpad_capture_source;
1412 break;
Tobin Davis18768992007-03-12 22:20:51 +01001413 case AD1981_TOSHIBA:
1414 spec->mixers[0] = ad1981_hp_mixers;
1415 spec->mixers[1] = ad1981_toshiba_mixers;
1416 spec->num_init_verbs = 2;
1417 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1418 spec->multiout.dig_out_nid = 0;
1419 spec->input_mux = &ad1981_hp_capture_source;
1420 codec->patch_ops.init = ad1981_hp_init;
1421 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1422 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001423 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001424 return 0;
1425}
1426
1427
1428/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001429 * AD1988
1430 *
1431 * Output pins and routes
1432 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001433 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001434 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1435 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1436 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1437 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1438 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1439 * port-F 0x16 (mute) <- 0x2a <- 06
1440 * port-G 0x24 (mute) <- 0x27 <- 05
1441 * port-H 0x25 (mute) <- 0x28 <- 0a
1442 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1443 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001444 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1445 * (*) 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 +01001446 *
1447 * Input pins and routes
1448 *
1449 * pin boost mix input # / adc input #
1450 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1451 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1452 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1453 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1454 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1455 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1456 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1457 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1458 *
1459 *
1460 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001461 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001462 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001463 *
1464 * Inputs of Analog Mix (0x20)
1465 * 0:Port-B (front mic)
1466 * 1:Port-C/G/H (line-in)
1467 * 2:Port-A
1468 * 3:Port-D (line-in/2)
1469 * 4:Port-E/G/H (mic-in)
1470 * 5:Port-F (mic2-in)
1471 * 6:CD
1472 * 7:Beep
1473 *
1474 * ADC selection
1475 * 0:Port-A
1476 * 1:Port-B (front mic-in)
1477 * 2:Port-C (line-in)
1478 * 3:Port-F (mic2-in)
1479 * 4:Port-E (mic-in)
1480 * 5:CD
1481 * 6:Port-G
1482 * 7:Port-H
1483 * 8:Port-D (line-in/2)
1484 * 9:Mix
1485 *
1486 * Proposed pin assignments by the datasheet
1487 *
1488 * 6-stack
1489 * Port-A front headphone
1490 * B front mic-in
1491 * C rear line-in
1492 * D rear front-out
1493 * E rear mic-in
1494 * F rear surround
1495 * G rear CLFE
1496 * H rear side
1497 *
1498 * 3-stack
1499 * Port-A front headphone
1500 * B front mic
1501 * C rear line-in/surround
1502 * D rear front-out
1503 * E rear mic-in/CLFE
1504 *
1505 * laptop
1506 * Port-A headphone
1507 * B mic-in
1508 * C docking station
1509 * D internal speaker (with EAPD)
1510 * E/F quad mic array
1511 */
1512
1513
1514/* models */
1515enum {
1516 AD1988_6STACK,
1517 AD1988_6STACK_DIG,
1518 AD1988_3STACK,
1519 AD1988_3STACK_DIG,
1520 AD1988_LAPTOP,
1521 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001522 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001523 AD1988_MODEL_LAST,
1524};
1525
Takashi Iwaid32410b12005-11-24 16:06:23 +01001526/* reivision id to check workarounds */
1527#define AD1988A_REV2 0x100200
1528
Takashi Iwai1a806f42006-07-03 15:58:16 +02001529#define is_rev2(codec) \
1530 ((codec)->vendor_id == 0x11d41988 && \
1531 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001532
1533/*
1534 * mixers
1535 */
1536
Takashi Iwaid32410b12005-11-24 16:06:23 +01001537static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001538 0x04, 0x06, 0x05, 0x0a
1539};
1540
Takashi Iwaid32410b12005-11-24 16:06:23 +01001541static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001542 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001543};
1544
1545/* for AD1988A revision-2, DAC2-4 are swapped */
1546static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1547 0x04, 0x05, 0x0a, 0x06
1548};
1549
1550static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001551 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001552};
1553
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001554static hda_nid_t ad1988_adc_nids[3] = {
1555 0x08, 0x09, 0x0f
1556};
1557
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001558static hda_nid_t ad1988_capsrc_nids[3] = {
1559 0x0c, 0x0d, 0x0e
1560};
1561
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001562#define AD1988_SPDIF_OUT 0x02
1563#define AD1988_SPDIF_IN 0x07
1564
1565static struct hda_input_mux ad1988_6stack_capture_source = {
1566 .num_items = 5,
1567 .items = {
1568 { "Front Mic", 0x0 },
1569 { "Line", 0x1 },
1570 { "Mic", 0x4 },
1571 { "CD", 0x5 },
1572 { "Mix", 0x9 },
1573 },
1574};
1575
1576static struct hda_input_mux ad1988_laptop_capture_source = {
1577 .num_items = 3,
1578 .items = {
1579 { "Mic/Line", 0x0 },
1580 { "CD", 0x5 },
1581 { "Mix", 0x9 },
1582 },
1583};
1584
1585/*
1586 */
1587static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1588 struct snd_ctl_elem_info *uinfo)
1589{
1590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1591 struct ad198x_spec *spec = codec->spec;
1592 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1593 spec->num_channel_mode);
1594}
1595
1596static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1597 struct snd_ctl_elem_value *ucontrol)
1598{
1599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1600 struct ad198x_spec *spec = codec->spec;
1601 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1602 spec->num_channel_mode, spec->multiout.max_channels);
1603}
1604
1605static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1606 struct snd_ctl_elem_value *ucontrol)
1607{
1608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1609 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001610 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1611 spec->num_channel_mode,
1612 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001613 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001614 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001615 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001616}
1617
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001618/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001619static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001620 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1621 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1623 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1624 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001625 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001626};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001627
Takashi Iwaid32410b12005-11-24 16:06:23 +01001628static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1629 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1630 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1633 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001634 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001635};
1636
1637static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001638 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1639 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1640 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1641 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1642 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1643 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1644 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1645
1646 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1647 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1648 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1649 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1650 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1651 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1652 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1653 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1654
1655 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1656 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1657
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001658 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001659 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1660
1661 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1662 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1663
1664 { } /* end */
1665};
1666
1667/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001668static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001669 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001670 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001671 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1672 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001673 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001674};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001675
Takashi Iwaid32410b12005-11-24 16:06:23 +01001676static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1677 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001678 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001681 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001682};
1683
1684static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001685 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001686 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1687 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1688 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001689 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1690 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1691
1692 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1693 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1694 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1695 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1696 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1697 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1698 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1699 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1700
1701 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1702 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1703
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001704 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001705 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1706
1707 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1708 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1709 {
1710 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1711 .name = "Channel Mode",
1712 .info = ad198x_ch_mode_info,
1713 .get = ad198x_ch_mode_get,
1714 .put = ad198x_ch_mode_put,
1715 },
1716
1717 { } /* end */
1718};
1719
1720/* laptop mode */
1721static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1722 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1723 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1724 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1725
1726 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1727 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1728 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1729 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1730 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1731 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1732
1733 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1734 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1735
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001736 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001737 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1738
1739 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1740
1741 {
1742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1743 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001744 .info = ad198x_eapd_info,
1745 .get = ad198x_eapd_get,
1746 .put = ad198x_eapd_put,
1747 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001748 },
1749
1750 { } /* end */
1751};
1752
1753/* capture */
1754static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1755 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1756 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1757 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1758 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1759 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1760 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1761 {
1762 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1763 /* The multiple "Capture Source" controls confuse alsamixer
1764 * So call somewhat different..
1765 * FIXME: the controls appear in the "playback" view!
1766 */
1767 /* .name = "Capture Source", */
1768 .name = "Input Source",
1769 .count = 3,
1770 .info = ad198x_mux_enum_info,
1771 .get = ad198x_mux_enum_get,
1772 .put = ad198x_mux_enum_put,
1773 },
1774 { } /* end */
1775};
1776
1777static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1778 struct snd_ctl_elem_info *uinfo)
1779{
1780 static char *texts[] = {
1781 "PCM", "ADC1", "ADC2", "ADC3"
1782 };
1783 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1784 uinfo->count = 1;
1785 uinfo->value.enumerated.items = 4;
1786 if (uinfo->value.enumerated.item >= 4)
1787 uinfo->value.enumerated.item = 3;
1788 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1789 return 0;
1790}
1791
1792static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1793 struct snd_ctl_elem_value *ucontrol)
1794{
1795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1796 unsigned int sel;
1797
Takashi Iwaibddcf542007-07-24 18:04:05 +02001798 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
1799 AC_AMP_GET_INPUT);
1800 if (!(sel & 0x80))
1801 ucontrol->value.enumerated.item[0] = 0;
1802 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02001803 sel = snd_hda_codec_read(codec, 0x0b, 0,
1804 AC_VERB_GET_CONNECT_SEL, 0);
1805 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001806 sel++;
1807 else
1808 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02001809 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001810 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001811 return 0;
1812}
1813
1814static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1815 struct snd_ctl_elem_value *ucontrol)
1816{
1817 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02001818 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001819 int change;
1820
Takashi Iwai35b26722007-05-05 12:17:17 +02001821 val = ucontrol->value.enumerated.item[0];
Takashi Iwai35b26722007-05-05 12:17:17 +02001822 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02001823 sel = snd_hda_codec_read(codec, 0x1d, 0,
1824 AC_VERB_GET_AMP_GAIN_MUTE,
1825 AC_AMP_GET_INPUT);
1826 change = sel & 0x80;
1827 if (change || codec->in_resume) {
1828 snd_hda_codec_write(codec, 0x1d, 0,
1829 AC_VERB_SET_AMP_GAIN_MUTE,
1830 AMP_IN_UNMUTE(0));
1831 snd_hda_codec_write(codec, 0x1d, 0,
1832 AC_VERB_SET_AMP_GAIN_MUTE,
1833 AMP_IN_MUTE(1));
1834 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001835 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02001836 sel = snd_hda_codec_read(codec, 0x1d, 0,
1837 AC_VERB_GET_AMP_GAIN_MUTE,
1838 AC_AMP_GET_INPUT | 0x01);
1839 change = sel & 0x80;
1840 if (change || codec->in_resume) {
1841 snd_hda_codec_write(codec, 0x1d, 0,
1842 AC_VERB_SET_AMP_GAIN_MUTE,
1843 AMP_IN_MUTE(0));
1844 snd_hda_codec_write(codec, 0x1d, 0,
1845 AC_VERB_SET_AMP_GAIN_MUTE,
1846 AMP_IN_UNMUTE(1));
1847 }
Takashi Iwai35b26722007-05-05 12:17:17 +02001848 sel = snd_hda_codec_read(codec, 0x0b, 0,
1849 AC_VERB_GET_CONNECT_SEL, 0) + 1;
1850 change |= sel != val;
1851 if (change || codec->in_resume)
1852 snd_hda_codec_write(codec, 0x0b, 0,
1853 AC_VERB_SET_CONNECT_SEL, val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001854 }
1855 return change;
1856}
1857
1858static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1859 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1860 {
1861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1862 .name = "IEC958 Playback Source",
1863 .info = ad1988_spdif_playback_source_info,
1864 .get = ad1988_spdif_playback_source_get,
1865 .put = ad1988_spdif_playback_source_put,
1866 },
1867 { } /* end */
1868};
1869
1870static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1871 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1872 { } /* end */
1873};
1874
1875
1876/*
1877 * initialization verbs
1878 */
1879
1880/*
1881 * for 6-stack (+dig)
1882 */
1883static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001884 /* Front, Surround, CLFE, side DAC; unmute as default */
1885 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1886 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1887 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1888 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001889 /* Port-A front headphon path */
1890 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1891 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1892 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1893 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1894 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1895 /* Port-D line-out path */
1896 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1897 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1898 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1899 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1900 /* Port-F surround path */
1901 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1902 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1903 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1904 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1905 /* Port-G CLFE path */
1906 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1907 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1908 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1909 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1910 /* Port-H side path */
1911 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1912 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1913 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1914 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1915 /* Mono out path */
1916 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1917 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1918 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1919 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1920 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1921 /* Port-B front mic-in path */
1922 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1923 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1924 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1925 /* Port-C line-in path */
1926 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1927 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1928 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1929 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1930 /* Port-E mic-in path */
1931 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1932 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1933 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1934 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1935
1936 { }
1937};
1938
1939static struct hda_verb ad1988_capture_init_verbs[] = {
1940 /* mute analog mix */
1941 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1942 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1943 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1944 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1945 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1946 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1947 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1948 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1949 /* select ADCs - front-mic */
1950 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1951 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1952 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1953 /* ADCs; muted */
1954 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1955 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1956 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1957
1958 { }
1959};
1960
1961static struct hda_verb ad1988_spdif_init_verbs[] = {
1962 /* SPDIF out sel */
1963 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1964 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1965 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02001966 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001967 /* SPDIF out pin */
1968 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001969
1970 { }
1971};
1972
1973/*
1974 * verbs for 3stack (+dig)
1975 */
1976static struct hda_verb ad1988_3stack_ch2_init[] = {
1977 /* set port-C to line-in */
1978 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1979 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1980 /* set port-E to mic-in */
1981 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1982 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1983 { } /* end */
1984};
1985
1986static struct hda_verb ad1988_3stack_ch6_init[] = {
1987 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001988 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001989 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001990 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001991 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001992 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001993 { } /* end */
1994};
1995
1996static struct hda_channel_mode ad1988_3stack_modes[2] = {
1997 { 2, ad1988_3stack_ch2_init },
1998 { 6, ad1988_3stack_ch6_init },
1999};
2000
2001static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002002 /* Front, Surround, CLFE, side DAC; unmute as default */
2003 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2004 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2005 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2006 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002007 /* Port-A front headphon path */
2008 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2009 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2010 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2011 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2012 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2013 /* Port-D line-out path */
2014 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2015 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2016 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2017 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2018 /* Mono out path */
2019 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2020 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2021 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2022 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2023 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2024 /* Port-B front mic-in path */
2025 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2026 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2027 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002028 /* Port-C line-in/surround path - 6ch mode as default */
2029 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2030 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002031 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002032 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002033 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002034 /* Port-E mic-in/CLFE path - 6ch mode as default */
2035 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2036 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002037 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002038 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002039 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2040 /* mute analog mix */
2041 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2042 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2043 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2044 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2045 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2046 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2047 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2048 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2049 /* select ADCs - front-mic */
2050 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2051 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2052 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2053 /* ADCs; muted */
2054 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2055 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2056 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2057 { }
2058};
2059
2060/*
2061 * verbs for laptop mode (+dig)
2062 */
2063static struct hda_verb ad1988_laptop_hp_on[] = {
2064 /* unmute port-A and mute port-D */
2065 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2066 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2067 { } /* end */
2068};
2069static struct hda_verb ad1988_laptop_hp_off[] = {
2070 /* mute port-A and unmute port-D */
2071 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2072 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2073 { } /* end */
2074};
2075
2076#define AD1988_HP_EVENT 0x01
2077
2078static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002079 /* Front, Surround, CLFE, side DAC; unmute as default */
2080 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2081 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2082 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2083 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002084 /* Port-A front headphon path */
2085 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2086 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2087 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2088 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2089 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2090 /* unsolicited event for pin-sense */
2091 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2092 /* Port-D line-out path + EAPD */
2093 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2094 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2095 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2096 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2097 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2098 /* Mono out path */
2099 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2100 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2101 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2102 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2103 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2104 /* Port-B mic-in path */
2105 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2106 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2107 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2108 /* Port-C docking station - try to output */
2109 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2110 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2111 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2112 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2113 /* mute analog mix */
2114 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2115 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2116 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2117 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2118 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2119 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2120 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2121 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2122 /* select ADCs - mic */
2123 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2124 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2125 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2126 /* ADCs; muted */
2127 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2128 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2129 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2130 { }
2131};
2132
2133static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2134{
2135 if ((res >> 26) != AD1988_HP_EVENT)
2136 return;
2137 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2138 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2139 else
2140 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2141}
2142
2143
2144/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002145 * Automatic parse of I/O pins from the BIOS configuration
2146 */
2147
2148#define NUM_CONTROL_ALLOC 32
2149#define NUM_VERB_ALLOC 32
2150
2151enum {
2152 AD_CTL_WIDGET_VOL,
2153 AD_CTL_WIDGET_MUTE,
2154 AD_CTL_BIND_MUTE,
2155};
2156static struct snd_kcontrol_new ad1988_control_templates[] = {
2157 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2158 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2159 HDA_BIND_MUTE(NULL, 0, 0, 0),
2160};
2161
2162/* add dynamic controls */
2163static int add_control(struct ad198x_spec *spec, int type, const char *name,
2164 unsigned long val)
2165{
2166 struct snd_kcontrol_new *knew;
2167
2168 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2169 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2170
2171 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2172 if (! knew)
2173 return -ENOMEM;
2174 if (spec->kctl_alloc) {
2175 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2176 kfree(spec->kctl_alloc);
2177 }
2178 spec->kctl_alloc = knew;
2179 spec->num_kctl_alloc = num;
2180 }
2181
2182 knew = &spec->kctl_alloc[spec->num_kctl_used];
2183 *knew = ad1988_control_templates[type];
2184 knew->name = kstrdup(name, GFP_KERNEL);
2185 if (! knew->name)
2186 return -ENOMEM;
2187 knew->private_value = val;
2188 spec->num_kctl_used++;
2189 return 0;
2190}
2191
2192#define AD1988_PIN_CD_NID 0x18
2193#define AD1988_PIN_BEEP_NID 0x10
2194
2195static hda_nid_t ad1988_mixer_nids[8] = {
2196 /* A B C D E F G H */
2197 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2198};
2199
2200static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2201{
2202 static hda_nid_t idx_to_dac[8] = {
2203 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002204 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002205 };
2206 static hda_nid_t idx_to_dac_rev2[8] = {
2207 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002208 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002209 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002210 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002211 return idx_to_dac_rev2[idx];
2212 else
2213 return idx_to_dac[idx];
2214}
2215
2216static hda_nid_t ad1988_boost_nids[8] = {
2217 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2218};
2219
2220static int ad1988_pin_idx(hda_nid_t nid)
2221{
2222 static hda_nid_t ad1988_io_pins[8] = {
2223 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2224 };
2225 int i;
2226 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2227 if (ad1988_io_pins[i] == nid)
2228 return i;
2229 return 0; /* should be -1 */
2230}
2231
2232static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2233{
2234 static int loopback_idx[8] = {
2235 2, 0, 1, 3, 4, 5, 1, 4
2236 };
2237 switch (nid) {
2238 case AD1988_PIN_CD_NID:
2239 return 6;
2240 default:
2241 return loopback_idx[ad1988_pin_idx(nid)];
2242 }
2243}
2244
2245static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2246{
2247 static int adc_idx[8] = {
2248 0, 1, 2, 8, 4, 3, 6, 7
2249 };
2250 switch (nid) {
2251 case AD1988_PIN_CD_NID:
2252 return 5;
2253 default:
2254 return adc_idx[ad1988_pin_idx(nid)];
2255 }
2256}
2257
2258/* fill in the dac_nids table from the parsed pin configuration */
2259static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2260 const struct auto_pin_cfg *cfg)
2261{
2262 struct ad198x_spec *spec = codec->spec;
2263 int i, idx;
2264
2265 spec->multiout.dac_nids = spec->private_dac_nids;
2266
2267 /* check the pins hardwired to audio widget */
2268 for (i = 0; i < cfg->line_outs; i++) {
2269 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2270 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2271 }
2272 spec->multiout.num_dacs = cfg->line_outs;
2273 return 0;
2274}
2275
2276/* add playback controls from the parsed DAC table */
2277static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2278 const struct auto_pin_cfg *cfg)
2279{
2280 char name[32];
2281 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2282 hda_nid_t nid;
2283 int i, err;
2284
2285 for (i = 0; i < cfg->line_outs; i++) {
2286 hda_nid_t dac = spec->multiout.dac_nids[i];
2287 if (! dac)
2288 continue;
2289 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2290 if (i == 2) {
2291 /* Center/LFE */
2292 err = add_control(spec, AD_CTL_WIDGET_VOL,
2293 "Center Playback Volume",
2294 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2295 if (err < 0)
2296 return err;
2297 err = add_control(spec, AD_CTL_WIDGET_VOL,
2298 "LFE Playback Volume",
2299 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2300 if (err < 0)
2301 return err;
2302 err = add_control(spec, AD_CTL_BIND_MUTE,
2303 "Center Playback Switch",
2304 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2305 if (err < 0)
2306 return err;
2307 err = add_control(spec, AD_CTL_BIND_MUTE,
2308 "LFE Playback Switch",
2309 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2310 if (err < 0)
2311 return err;
2312 } else {
2313 sprintf(name, "%s Playback Volume", chname[i]);
2314 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2315 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2316 if (err < 0)
2317 return err;
2318 sprintf(name, "%s Playback Switch", chname[i]);
2319 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2320 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2321 if (err < 0)
2322 return err;
2323 }
2324 }
2325 return 0;
2326}
2327
2328/* add playback controls for speaker and HP outputs */
2329static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2330 const char *pfx)
2331{
2332 struct ad198x_spec *spec = codec->spec;
2333 hda_nid_t nid;
2334 int idx, err;
2335 char name[32];
2336
2337 if (! pin)
2338 return 0;
2339
2340 idx = ad1988_pin_idx(pin);
2341 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002342 /* specify the DAC as the extra output */
2343 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002344 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002345 else
2346 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002347 /* control HP volume/switch on the output mixer amp */
2348 sprintf(name, "%s Playback Volume", pfx);
2349 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2350 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2351 return err;
2352 nid = ad1988_mixer_nids[idx];
2353 sprintf(name, "%s Playback Switch", pfx);
2354 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2355 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2356 return err;
2357 return 0;
2358}
2359
2360/* create input playback/capture controls for the given pin */
2361static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2362 const char *ctlname, int boost)
2363{
2364 char name[32];
2365 int err, idx;
2366
2367 sprintf(name, "%s Playback Volume", ctlname);
2368 idx = ad1988_pin_to_loopback_idx(pin);
2369 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2370 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2371 return err;
2372 sprintf(name, "%s Playback Switch", ctlname);
2373 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2374 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2375 return err;
2376 if (boost) {
2377 hda_nid_t bnid;
2378 idx = ad1988_pin_idx(pin);
2379 bnid = ad1988_boost_nids[idx];
2380 if (bnid) {
2381 sprintf(name, "%s Boost", ctlname);
2382 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2383 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2384
2385 }
2386 }
2387 return 0;
2388}
2389
2390/* create playback/capture controls for input pins */
2391static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2392 const struct auto_pin_cfg *cfg)
2393{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002394 struct hda_input_mux *imux = &spec->private_imux;
2395 int i, err;
2396
2397 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002398 err = new_analog_input(spec, cfg->input_pins[i],
2399 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002400 i <= AUTO_PIN_FRONT_MIC);
2401 if (err < 0)
2402 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002403 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002404 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2405 imux->num_items++;
2406 }
2407 imux->items[imux->num_items].label = "Mix";
2408 imux->items[imux->num_items].index = 9;
2409 imux->num_items++;
2410
2411 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2412 "Analog Mix Playback Volume",
2413 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2414 return err;
2415 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2416 "Analog Mix Playback Switch",
2417 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2418 return err;
2419
2420 return 0;
2421}
2422
2423static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2424 hda_nid_t nid, int pin_type,
2425 int dac_idx)
2426{
2427 /* set as output */
2428 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2429 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2430 switch (nid) {
2431 case 0x11: /* port-A - DAC 04 */
2432 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2433 break;
2434 case 0x14: /* port-B - DAC 06 */
2435 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2436 break;
2437 case 0x15: /* port-C - DAC 05 */
2438 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2439 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002440 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002441 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2442 break;
2443 case 0x13: /* mono - DAC 04 */
2444 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2445 break;
2446 }
2447}
2448
2449static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2450{
2451 struct ad198x_spec *spec = codec->spec;
2452 int i;
2453
2454 for (i = 0; i < spec->autocfg.line_outs; i++) {
2455 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2456 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2457 }
2458}
2459
2460static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2461{
2462 struct ad198x_spec *spec = codec->spec;
2463 hda_nid_t pin;
2464
Takashi Iwai82bc9552006-03-21 11:24:42 +01002465 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002466 if (pin) /* connect to front */
2467 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002468 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002469 if (pin) /* connect to front */
2470 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2471}
2472
2473static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2474{
2475 struct ad198x_spec *spec = codec->spec;
2476 int i, idx;
2477
2478 for (i = 0; i < AUTO_PIN_LAST; i++) {
2479 hda_nid_t nid = spec->autocfg.input_pins[i];
2480 if (! nid)
2481 continue;
2482 switch (nid) {
2483 case 0x15: /* port-C */
2484 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2485 break;
2486 case 0x17: /* port-E */
2487 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2488 break;
2489 }
2490 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2491 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2492 if (nid != AD1988_PIN_CD_NID)
2493 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2494 AMP_OUT_MUTE);
2495 idx = ad1988_pin_idx(nid);
2496 if (ad1988_boost_nids[idx])
2497 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2498 AC_VERB_SET_AMP_GAIN_MUTE,
2499 AMP_OUT_ZERO);
2500 }
2501}
2502
2503/* parse the BIOS configuration and set up the alc_spec */
2504/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2505static int ad1988_parse_auto_config(struct hda_codec *codec)
2506{
2507 struct ad198x_spec *spec = codec->spec;
2508 int err;
2509
Kailang Yangdf694da2005-12-05 19:42:22 +01002510 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002511 return err;
2512 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2513 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002514 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002515 return 0; /* can't find valid BIOS pin config */
2516 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002517 (err = ad1988_auto_create_extra_out(codec,
2518 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002519 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002520 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002521 "Headphone")) < 0 ||
2522 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2523 return err;
2524
2525 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2526
2527 if (spec->autocfg.dig_out_pin)
2528 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2529 if (spec->autocfg.dig_in_pin)
2530 spec->dig_in_nid = AD1988_SPDIF_IN;
2531
2532 if (spec->kctl_alloc)
2533 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2534
2535 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2536
2537 spec->input_mux = &spec->private_imux;
2538
2539 return 1;
2540}
2541
2542/* init callback for auto-configuration model -- overriding the default init */
2543static int ad1988_auto_init(struct hda_codec *codec)
2544{
2545 ad198x_init(codec);
2546 ad1988_auto_init_multi_out(codec);
2547 ad1988_auto_init_extra_out(codec);
2548 ad1988_auto_init_analog_input(codec);
2549 return 0;
2550}
2551
2552
2553/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002554 */
2555
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002556static const char *ad1988_models[AD1988_MODEL_LAST] = {
2557 [AD1988_6STACK] = "6stack",
2558 [AD1988_6STACK_DIG] = "6stack-dig",
2559 [AD1988_3STACK] = "3stack",
2560 [AD1988_3STACK_DIG] = "3stack-dig",
2561 [AD1988_LAPTOP] = "laptop",
2562 [AD1988_LAPTOP_DIG] = "laptop-dig",
2563 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002564};
2565
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002566static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2567 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Tobin Davis18768992007-03-12 22:20:51 +01002568 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002569 {}
2570};
2571
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002572static int patch_ad1988(struct hda_codec *codec)
2573{
2574 struct ad198x_spec *spec;
2575 int board_config;
2576
2577 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2578 if (spec == NULL)
2579 return -ENOMEM;
2580
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002581 codec->spec = spec;
2582
Takashi Iwai1a806f42006-07-03 15:58:16 +02002583 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002584 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2585
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002586 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002587 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002588 if (board_config < 0) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002589 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2590 board_config = AD1988_AUTO;
2591 }
2592
2593 if (board_config == AD1988_AUTO) {
2594 /* automatic parse from the BIOS config */
2595 int err = ad1988_parse_auto_config(codec);
2596 if (err < 0) {
2597 ad198x_free(codec);
2598 return err;
2599 } else if (! err) {
2600 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2601 board_config = AD1988_6STACK;
2602 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002603 }
2604
2605 switch (board_config) {
2606 case AD1988_6STACK:
2607 case AD1988_6STACK_DIG:
2608 spec->multiout.max_channels = 8;
2609 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002610 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002611 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2612 else
2613 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002614 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002615 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002616 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002617 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2618 else
2619 spec->mixers[0] = ad1988_6stack_mixers1;
2620 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002621 spec->num_init_verbs = 1;
2622 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2623 if (board_config == AD1988_6STACK_DIG) {
2624 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2625 spec->dig_in_nid = AD1988_SPDIF_IN;
2626 }
2627 break;
2628 case AD1988_3STACK:
2629 case AD1988_3STACK_DIG:
2630 spec->multiout.max_channels = 6;
2631 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002632 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002633 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2634 else
2635 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002636 spec->input_mux = &ad1988_6stack_capture_source;
2637 spec->channel_mode = ad1988_3stack_modes;
2638 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002639 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002640 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002641 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2642 else
2643 spec->mixers[0] = ad1988_3stack_mixers1;
2644 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002645 spec->num_init_verbs = 1;
2646 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2647 if (board_config == AD1988_3STACK_DIG)
2648 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2649 break;
2650 case AD1988_LAPTOP:
2651 case AD1988_LAPTOP_DIG:
2652 spec->multiout.max_channels = 2;
2653 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002654 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002655 spec->input_mux = &ad1988_laptop_capture_source;
2656 spec->num_mixers = 1;
2657 spec->mixers[0] = ad1988_laptop_mixers;
2658 spec->num_init_verbs = 1;
2659 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2660 if (board_config == AD1988_LAPTOP_DIG)
2661 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2662 break;
2663 }
2664
Takashi Iwaid32410b12005-11-24 16:06:23 +01002665 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2666 spec->adc_nids = ad1988_adc_nids;
2667 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002668 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2669 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2670 if (spec->multiout.dig_out_nid) {
2671 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2672 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2673 }
2674 if (spec->dig_in_nid)
2675 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2676
2677 codec->patch_ops = ad198x_patch_ops;
2678 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002679 case AD1988_AUTO:
2680 codec->patch_ops.init = ad1988_auto_init;
2681 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002682 case AD1988_LAPTOP:
2683 case AD1988_LAPTOP_DIG:
2684 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2685 break;
2686 }
2687
2688 return 0;
2689}
2690
2691
2692/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02002693 * AD1884 / AD1984
2694 *
2695 * port-B - front line/mic-in
2696 * port-E - aux in/out
2697 * port-F - aux in/out
2698 * port-C - rear line/mic-in
2699 * port-D - rear line/hp-out
2700 * port-A - front line/hp-out
2701 *
2702 * AD1984 = AD1884 + two digital mic-ins
2703 *
2704 * FIXME:
2705 * For simplicity, we share the single DAC for both HP and line-outs
2706 * right now. The inidividual playbacks could be easily implemented,
2707 * but no build-up framework is given, so far.
2708 */
2709
2710static hda_nid_t ad1884_dac_nids[1] = {
2711 0x04,
2712};
2713
2714static hda_nid_t ad1884_adc_nids[2] = {
2715 0x08, 0x09,
2716};
2717
2718static hda_nid_t ad1884_capsrc_nids[2] = {
2719 0x0c, 0x0d,
2720};
2721
2722#define AD1884_SPDIF_OUT 0x02
2723
2724static struct hda_input_mux ad1884_capture_source = {
2725 .num_items = 4,
2726 .items = {
2727 { "Front Mic", 0x0 },
2728 { "Mic", 0x1 },
2729 { "CD", 0x2 },
2730 { "Mix", 0x3 },
2731 },
2732};
2733
2734static struct snd_kcontrol_new ad1884_base_mixers[] = {
2735 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2736 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2737 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2738 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2739 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2740 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
2741 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2742 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2743 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2744 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2745 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
2746 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
2747 /*
2748 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
2749 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
2750 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2751 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2752 */
2753 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
2754 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
2755 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2756 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2757 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2758 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2759 {
2760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2761 /* The multiple "Capture Source" controls confuse alsamixer
2762 * So call somewhat different..
2763 * FIXME: the controls appear in the "playback" view!
2764 */
2765 /* .name = "Capture Source", */
2766 .name = "Input Source",
2767 .count = 2,
2768 .info = ad198x_mux_enum_info,
2769 .get = ad198x_mux_enum_get,
2770 .put = ad198x_mux_enum_put,
2771 },
2772 /* SPDIF controls */
2773 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2774 {
2775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2776 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2777 /* identical with ad1983 */
2778 .info = ad1983_spdif_route_info,
2779 .get = ad1983_spdif_route_get,
2780 .put = ad1983_spdif_route_put,
2781 },
2782 { } /* end */
2783};
2784
2785static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
2786 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
2787 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
2788 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02002789 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002790 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02002791 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002792 { } /* end */
2793};
2794
2795/*
2796 * initialization verbs
2797 */
2798static struct hda_verb ad1884_init_verbs[] = {
2799 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02002800 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2801 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02002802 /* Port-A (HP) mixer */
2803 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2804 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2805 /* Port-A pin */
2806 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2807 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2808 /* HP selector - select DAC2 */
2809 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
2810 /* Port-D (Line-out) mixer */
2811 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2812 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2813 /* Port-D pin */
2814 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2815 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2816 /* Mono-out mixer */
2817 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2818 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2819 /* Mono-out pin */
2820 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2821 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2822 /* Mono selector */
2823 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2824 /* Port-B (front mic) pin */
2825 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2826 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2827 /* Port-C (rear mic) pin */
2828 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2829 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2830 /* Analog mixer; mute as default */
2831 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2832 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2833 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2834 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2835 /* Analog Mix output amp */
2836 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2837 /* SPDIF output selector */
2838 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2839 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2840 { } /* end */
2841};
2842
2843static int patch_ad1884(struct hda_codec *codec)
2844{
2845 struct ad198x_spec *spec;
2846
2847 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2848 if (spec == NULL)
2849 return -ENOMEM;
2850
2851 mutex_init(&spec->amp_mutex);
2852 codec->spec = spec;
2853
2854 spec->multiout.max_channels = 2;
2855 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
2856 spec->multiout.dac_nids = ad1884_dac_nids;
2857 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
2858 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
2859 spec->adc_nids = ad1884_adc_nids;
2860 spec->capsrc_nids = ad1884_capsrc_nids;
2861 spec->input_mux = &ad1884_capture_source;
2862 spec->num_mixers = 1;
2863 spec->mixers[0] = ad1884_base_mixers;
2864 spec->num_init_verbs = 1;
2865 spec->init_verbs[0] = ad1884_init_verbs;
2866 spec->spdif_route = 0;
2867
2868 codec->patch_ops = ad198x_patch_ops;
2869
2870 return 0;
2871}
2872
2873/*
2874 * Lenovo Thinkpad T61/X61
2875 */
2876static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwai3b194402007-06-04 18:32:23 +02002877 .num_items = 3,
Takashi Iwai2bac6472007-05-18 18:21:41 +02002878 .items = {
2879 { "Mic", 0x0 },
2880 { "Internal Mic", 0x1 },
2881 { "Mix", 0x3 },
2882 },
2883};
2884
2885static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
2886 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2887 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2888 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2889 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2890 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2891 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2892 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2893 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2894 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
2895 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002896 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
2897 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02002898 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaib959d1f2007-06-08 12:25:25 +02002899 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
2900 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002901 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2902 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2903 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2904 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2905 {
2906 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2907 /* The multiple "Capture Source" controls confuse alsamixer
2908 * So call somewhat different..
2909 * FIXME: the controls appear in the "playback" view!
2910 */
2911 /* .name = "Capture Source", */
2912 .name = "Input Source",
2913 .count = 2,
2914 .info = ad198x_mux_enum_info,
2915 .get = ad198x_mux_enum_get,
2916 .put = ad198x_mux_enum_put,
2917 },
2918 { } /* end */
2919};
2920
2921/* additional verbs */
2922static struct hda_verb ad1984_thinkpad_init_verbs[] = {
2923 /* Port-E (docking station mic) pin */
2924 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2925 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2926 /* docking mic boost */
2927 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2928 /* Analog mixer - docking mic; mute as default */
2929 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02002930 /* enable EAPD bit */
2931 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02002932 { } /* end */
2933};
2934
2935/* Digial MIC ADC NID 0x05 + 0x06 */
2936static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
2937 struct hda_codec *codec,
2938 unsigned int stream_tag,
2939 unsigned int format,
2940 struct snd_pcm_substream *substream)
2941{
2942 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
2943 stream_tag, 0, format);
2944 return 0;
2945}
2946
2947static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
2948 struct hda_codec *codec,
2949 struct snd_pcm_substream *substream)
2950{
2951 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
2952 0, 0, 0);
2953 return 0;
2954}
2955
2956static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
2957 .substreams = 2,
2958 .channels_min = 2,
2959 .channels_max = 2,
2960 .nid = 0x05,
2961 .ops = {
2962 .prepare = ad1984_pcm_dmic_prepare,
2963 .cleanup = ad1984_pcm_dmic_cleanup
2964 },
2965};
2966
2967static int ad1984_build_pcms(struct hda_codec *codec)
2968{
2969 struct ad198x_spec *spec = codec->spec;
2970 struct hda_pcm *info;
2971 int err;
2972
2973 err = ad198x_build_pcms(codec);
2974 if (err < 0)
2975 return err;
2976
2977 info = spec->pcm_rec + codec->num_pcms;
2978 codec->num_pcms++;
2979 info->name = "AD1984 Digital Mic";
2980 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
2981 return 0;
2982}
2983
2984/* models */
2985enum {
2986 AD1984_BASIC,
2987 AD1984_THINKPAD,
2988 AD1984_MODELS
2989};
2990
2991static const char *ad1984_models[AD1984_MODELS] = {
2992 [AD1984_BASIC] = "basic",
2993 [AD1984_THINKPAD] = "thinkpad",
2994};
2995
2996static struct snd_pci_quirk ad1984_cfg_tbl[] = {
2997 /* Lenovo Thinkpad T61/X61 */
2998 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
2999 {}
3000};
3001
3002static int patch_ad1984(struct hda_codec *codec)
3003{
3004 struct ad198x_spec *spec;
3005 int board_config, err;
3006
3007 err = patch_ad1884(codec);
3008 if (err < 0)
3009 return err;
3010 spec = codec->spec;
3011 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3012 ad1984_models, ad1984_cfg_tbl);
3013 switch (board_config) {
3014 case AD1984_BASIC:
3015 /* additional digital mics */
3016 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3017 codec->patch_ops.build_pcms = ad1984_build_pcms;
3018 break;
3019 case AD1984_THINKPAD:
3020 spec->multiout.dig_out_nid = 0;
3021 spec->input_mux = &ad1984_thinkpad_capture_source;
3022 spec->mixers[0] = ad1984_thinkpad_mixers;
3023 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3024 break;
3025 }
3026 return 0;
3027}
3028
3029
3030/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02003031 * AD1882
3032 *
3033 * port-A - front hp-out
3034 * port-B - front mic-in
3035 * port-C - rear line-in, shared surr-out (3stack)
3036 * port-D - rear line-out
3037 * port-E - rear mic-in, shared clfe-out (3stack)
3038 * port-F - rear surr-out (6stack)
3039 * port-G - rear clfe-out (6stack)
3040 */
3041
3042static hda_nid_t ad1882_dac_nids[3] = {
3043 0x04, 0x03, 0x05
3044};
3045
3046static hda_nid_t ad1882_adc_nids[2] = {
3047 0x08, 0x09,
3048};
3049
3050static hda_nid_t ad1882_capsrc_nids[2] = {
3051 0x0c, 0x0d,
3052};
3053
3054#define AD1882_SPDIF_OUT 0x02
3055
3056/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3057static struct hda_input_mux ad1882_capture_source = {
3058 .num_items = 5,
3059 .items = {
3060 { "Front Mic", 0x1 },
3061 { "Mic", 0x4 },
3062 { "Line", 0x2 },
3063 { "CD", 0x3 },
3064 { "Mix", 0x7 },
3065 },
3066};
3067
3068static struct snd_kcontrol_new ad1882_base_mixers[] = {
3069 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3070 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3071 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3072 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3073 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3074 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3075 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3076 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3077 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3078 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3079 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3080 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3081 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3082 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3083 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3084 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3085 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3086 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3087 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3088 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3089 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3090 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3091 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3092 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3093 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3094 {
3095 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3096 /* The multiple "Capture Source" controls confuse alsamixer
3097 * So call somewhat different..
3098 * FIXME: the controls appear in the "playback" view!
3099 */
3100 /* .name = "Capture Source", */
3101 .name = "Input Source",
3102 .count = 2,
3103 .info = ad198x_mux_enum_info,
3104 .get = ad198x_mux_enum_get,
3105 .put = ad198x_mux_enum_put,
3106 },
3107 /* SPDIF controls */
3108 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3109 {
3110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3111 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3112 /* identical with ad1983 */
3113 .info = ad1983_spdif_route_info,
3114 .get = ad1983_spdif_route_get,
3115 .put = ad1983_spdif_route_put,
3116 },
3117 { } /* end */
3118};
3119
3120static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3121 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3122 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3123 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3124 {
3125 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3126 .name = "Channel Mode",
3127 .info = ad198x_ch_mode_info,
3128 .get = ad198x_ch_mode_get,
3129 .put = ad198x_ch_mode_put,
3130 },
3131 { } /* end */
3132};
3133
3134static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3135 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3136 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3137 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3138 { } /* end */
3139};
3140
3141static struct hda_verb ad1882_ch2_init[] = {
3142 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3143 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3144 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3145 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3146 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3147 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3148 { } /* end */
3149};
3150
3151static struct hda_verb ad1882_ch4_init[] = {
3152 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3153 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3154 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3155 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3156 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3157 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3158 { } /* end */
3159};
3160
3161static struct hda_verb ad1882_ch6_init[] = {
3162 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3163 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3165 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3166 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3167 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3168 { } /* end */
3169};
3170
3171static struct hda_channel_mode ad1882_modes[3] = {
3172 { 2, ad1882_ch2_init },
3173 { 4, ad1882_ch4_init },
3174 { 6, ad1882_ch6_init },
3175};
3176
3177/*
3178 * initialization verbs
3179 */
3180static struct hda_verb ad1882_init_verbs[] = {
3181 /* DACs; mute as default */
3182 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3183 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3184 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3185 /* Port-A (HP) mixer */
3186 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3187 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3188 /* Port-A pin */
3189 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3190 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3191 /* HP selector - select DAC2 */
3192 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
3193 /* Port-D (Line-out) mixer */
3194 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3195 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3196 /* Port-D pin */
3197 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3198 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3199 /* Mono-out mixer */
3200 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3201 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3202 /* Mono-out pin */
3203 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3204 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3205 /* Port-B (front mic) pin */
3206 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3207 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3208 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3209 /* Port-C (line-in) pin */
3210 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3211 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3212 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3213 /* Port-C mixer - mute as input */
3214 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3215 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3216 /* Port-E (mic-in) pin */
3217 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3218 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3219 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3220 /* Port-E mixer - mute as input */
3221 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3222 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3223 /* Port-F (surround) */
3224 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3225 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3226 /* Port-G (CLFE) */
3227 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3228 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3229 /* Analog mixer; mute as default */
3230 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
3231 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3232 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3233 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3234 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3235 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3236 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3237 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3238 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3239 /* Analog Mix output amp */
3240 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3241 /* SPDIF output selector */
3242 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3243 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3244 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3245 { } /* end */
3246};
3247
3248/* models */
3249enum {
3250 AD1882_3STACK,
3251 AD1882_6STACK,
3252 AD1882_MODELS
3253};
3254
3255static const char *ad1882_models[AD1986A_MODELS] = {
3256 [AD1882_3STACK] = "3stack",
3257 [AD1882_6STACK] = "6stack",
3258};
3259
3260
3261static int patch_ad1882(struct hda_codec *codec)
3262{
3263 struct ad198x_spec *spec;
3264 int board_config;
3265
3266 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3267 if (spec == NULL)
3268 return -ENOMEM;
3269
3270 mutex_init(&spec->amp_mutex);
3271 codec->spec = spec;
3272
3273 spec->multiout.max_channels = 6;
3274 spec->multiout.num_dacs = 3;
3275 spec->multiout.dac_nids = ad1882_dac_nids;
3276 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
3277 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
3278 spec->adc_nids = ad1882_adc_nids;
3279 spec->capsrc_nids = ad1882_capsrc_nids;
3280 spec->input_mux = &ad1882_capture_source;
3281 spec->num_mixers = 1;
3282 spec->mixers[0] = ad1882_base_mixers;
3283 spec->num_init_verbs = 1;
3284 spec->init_verbs[0] = ad1882_init_verbs;
3285 spec->spdif_route = 0;
3286
3287 codec->patch_ops = ad198x_patch_ops;
3288
3289 /* override some parameters */
3290 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
3291 ad1882_models, NULL);
3292 switch (board_config) {
3293 default:
3294 case AD1882_3STACK:
3295 spec->num_mixers = 2;
3296 spec->mixers[1] = ad1882_3stack_mixers;
3297 spec->channel_mode = ad1882_modes;
3298 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
3299 spec->need_dac_fix = 1;
3300 spec->multiout.max_channels = 2;
3301 spec->multiout.num_dacs = 1;
3302 break;
3303 case AD1882_6STACK:
3304 spec->num_mixers = 2;
3305 spec->mixers[1] = ad1882_6stack_mixers;
3306 break;
3307 }
3308 return 0;
3309}
3310
3311
3312/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 * patch entries
3314 */
3315struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02003316 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003317 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02003318 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3319 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003320 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003322 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02003323 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 {} /* terminator */
3325};