blob: 076365bc10e970706db63bbf99f52303347664fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002 * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
35
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
64 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
65
Ingo Molnar62932df2006-01-16 16:34:20 +010066 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020067 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010068
69 /* dynamic controls, init_verbs and input_mux */
70 struct auto_pin_cfg autocfg;
71 unsigned int num_kctl_alloc, num_kctl_used;
72 struct snd_kcontrol_new *kctl_alloc;
73 struct hda_input_mux private_imux;
74 hda_nid_t private_dac_nids[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020077/*
78 * input MUX handling (common part)
79 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010080static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020081{
82 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
83 struct ad198x_spec *spec = codec->spec;
84
85 return snd_hda_input_mux_info(spec->input_mux, uinfo);
86}
87
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010088static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020089{
90 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
91 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010092 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020093
Takashi Iwai985be542005-11-02 18:26:49 +010094 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020095 return 0;
96}
97
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010098static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
104 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100105 spec->capsrc_nids[adc_idx],
106 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200107}
108
109/*
110 * initialization (common callbacks)
111 */
112static int ad198x_init(struct hda_codec *codec)
113{
114 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100115 int i;
116
117 for (i = 0; i < spec->num_init_verbs; i++)
118 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200119 return 0;
120}
121
122static int ad198x_build_controls(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200126 int err;
127
Takashi Iwai985be542005-11-02 18:26:49 +0100128 for (i = 0; i < spec->num_mixers; i++) {
129 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
130 if (err < 0)
131 return err;
132 }
133 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200134 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100135 if (err < 0)
136 return err;
137 }
138 if (spec->dig_in_nid) {
139 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
140 if (err < 0)
141 return err;
142 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200143 return 0;
144}
145
146/*
147 * Analog playback callbacks
148 */
149static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100151 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200152{
153 struct ad198x_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
155}
156
157static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 unsigned int stream_tag,
160 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100161 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200162{
163 struct ad198x_spec *spec = codec->spec;
164 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
165 format, substream);
166}
167
168static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100170 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200171{
172 struct ad198x_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
174}
175
176/*
177 * Digital out
178 */
179static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100181 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200182{
183 struct ad198x_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
185}
186
187static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100189 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200190{
191 struct ad198x_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
193}
194
195/*
196 * Analog capture
197 */
198static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 unsigned int stream_tag,
201 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100202 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200203{
204 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100205 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
206 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200207 return 0;
208}
209
210static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100212 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200213{
214 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100215 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
216 0, 0, 0);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200217 return 0;
218}
219
220
221/*
222 */
223static struct hda_pcm_stream ad198x_pcm_analog_playback = {
224 .substreams = 1,
225 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100226 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200227 .nid = 0, /* fill later */
228 .ops = {
229 .open = ad198x_playback_pcm_open,
230 .prepare = ad198x_playback_pcm_prepare,
231 .cleanup = ad198x_playback_pcm_cleanup
232 },
233};
234
235static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100236 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200237 .channels_min = 2,
238 .channels_max = 2,
239 .nid = 0, /* fill later */
240 .ops = {
241 .prepare = ad198x_capture_pcm_prepare,
242 .cleanup = ad198x_capture_pcm_cleanup
243 },
244};
245
246static struct hda_pcm_stream ad198x_pcm_digital_playback = {
247 .substreams = 1,
248 .channels_min = 2,
249 .channels_max = 2,
250 .nid = 0, /* fill later */
251 .ops = {
252 .open = ad198x_dig_playback_pcm_open,
253 .close = ad198x_dig_playback_pcm_close
254 },
255};
256
Takashi Iwai985be542005-11-02 18:26:49 +0100257static struct hda_pcm_stream ad198x_pcm_digital_capture = {
258 .substreams = 1,
259 .channels_min = 2,
260 .channels_max = 2,
261 /* NID is set in alc_build_pcms */
262};
263
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200264static int ad198x_build_pcms(struct hda_codec *codec)
265{
266 struct ad198x_spec *spec = codec->spec;
267 struct hda_pcm *info = spec->pcm_rec;
268
269 codec->num_pcms = 1;
270 codec->pcm_info = info;
271
272 info->name = "AD198x Analog";
273 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
275 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
276 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100277 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
278 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200279
280 if (spec->multiout.dig_out_nid) {
281 info++;
282 codec->num_pcms++;
283 info->name = "AD198x Digital";
284 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100286 if (spec->dig_in_nid) {
287 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
288 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
289 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200290 }
291
292 return 0;
293}
294
295static void ad198x_free(struct hda_codec *codec)
296{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100297 struct ad198x_spec *spec = codec->spec;
298 unsigned int i;
299
300 if (spec->kctl_alloc) {
301 for (i = 0; i < spec->num_kctl_used; i++)
302 kfree(spec->kctl_alloc[i].name);
303 kfree(spec->kctl_alloc);
304 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200305 kfree(codec->spec);
306}
307
308#ifdef CONFIG_PM
309static int ad198x_resume(struct hda_codec *codec)
310{
311 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100312 int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200313
Takashi Iwai18a815d2006-03-01 19:54:39 +0100314 codec->patch_ops.init(codec);
Takashi Iwai985be542005-11-02 18:26:49 +0100315 for (i = 0; i < spec->num_mixers; i++)
316 snd_hda_resume_ctls(codec, spec->mixers[i]);
317 if (spec->multiout.dig_out_nid)
318 snd_hda_resume_spdif_out(codec);
319 if (spec->dig_in_nid)
320 snd_hda_resume_spdif_in(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200321 return 0;
322}
323#endif
324
325static struct hda_codec_ops ad198x_patch_ops = {
326 .build_controls = ad198x_build_controls,
327 .build_pcms = ad198x_build_pcms,
328 .init = ad198x_init,
329 .free = ad198x_free,
330#ifdef CONFIG_PM
331 .resume = ad198x_resume,
332#endif
333};
334
335
336/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100337 * EAPD control
338 * the private value = nid | (invert << 8)
339 */
340static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_info *uinfo)
342{
343 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
344 uinfo->count = 1;
345 uinfo->value.integer.min = 0;
346 uinfo->value.integer.max = 1;
347 return 0;
348}
349
350static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
352{
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 struct ad198x_spec *spec = codec->spec;
355 int invert = (kcontrol->private_value >> 8) & 1;
356 if (invert)
357 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
358 else
359 ucontrol->value.integer.value[0] = spec->cur_eapd;
360 return 0;
361}
362
363static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_value *ucontrol)
365{
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367 struct ad198x_spec *spec = codec->spec;
368 int invert = (kcontrol->private_value >> 8) & 1;
369 hda_nid_t nid = kcontrol->private_value & 0xff;
370 unsigned int eapd;
371 eapd = ucontrol->value.integer.value[0];
372 if (invert)
373 eapd = !eapd;
374 if (eapd == spec->cur_eapd && ! codec->in_resume)
375 return 0;
376 spec->cur_eapd = eapd;
377 snd_hda_codec_write(codec, nid,
378 0, AC_VERB_SET_EAPD_BTLENABLE,
379 eapd ? 0x02 : 0x00);
380 return 1;
381}
382
Takashi Iwai9230d212006-03-13 13:49:49 +0100383static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
384 struct snd_ctl_elem_info *uinfo);
385static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol);
387static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol);
389
390
Takashi Iwai18a815d2006-03-01 19:54:39 +0100391/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200392 * AD1986A specific
393 */
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define AD1986A_SPDIF_OUT 0x02
396#define AD1986A_FRONT_DAC 0x03
397#define AD1986A_SURR_DAC 0x04
398#define AD1986A_CLFE_DAC 0x05
399#define AD1986A_ADC 0x06
400
401static hda_nid_t ad1986a_dac_nids[3] = {
402 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
403};
Takashi Iwai985be542005-11-02 18:26:49 +0100404static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100405static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407static struct hda_input_mux ad1986a_capture_source = {
408 .num_items = 7,
409 .items = {
410 { "Mic", 0x0 },
411 { "CD", 0x1 },
412 { "Aux", 0x3 },
413 { "Line", 0x4 },
414 { "Mix", 0x5 },
415 { "Mono", 0x6 },
416 { "Phone", 0x7 },
417 },
418};
419
420/*
421 * PCM control
422 *
423 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
424 */
425
426#define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
427
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100428static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200431 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Ingo Molnar62932df2006-01-16 16:34:20 +0100433 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100435 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
437}
438
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100439static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200442 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 int i, change = 0;
444
Ingo Molnar62932df2006-01-16 16:34:20 +0100445 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
447 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
448 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
449 }
450 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100451 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return change;
453}
454
Takashi Iwaiead9b7c2005-06-08 14:48:19 +0200455#define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100457static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200460 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Ingo Molnar62932df2006-01-16 16:34:20 +0100462 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100464 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return 0;
466}
467
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100468static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200471 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 int i, change = 0;
473
Ingo Molnar62932df2006-01-16 16:34:20 +0100474 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
476 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
477 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
478 }
479 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100480 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return change;
482}
483
484/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 * mixers
486 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100487static struct snd_kcontrol_new ad1986a_mixers[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
490 .name = "PCM Playback Volume",
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200491 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
492 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
493 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .info = ad1986a_pcm_amp_vol_info,
495 .get = ad1986a_pcm_amp_vol_get,
496 .put = ad1986a_pcm_amp_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200497 .tlv = { .c = snd_hda_mixer_amp_tlv },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
499 },
500 {
501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
502 .name = "PCM Playback Switch",
503 .info = ad1986a_pcm_amp_sw_info,
504 .get = ad1986a_pcm_amp_sw_get,
505 .put = ad1986a_pcm_amp_sw_put,
506 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
507 },
508 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
509 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
510 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
511 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
512 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
513 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
515 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
516 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
517 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
528 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
529 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
530 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
531 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
532 {
533 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
534 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200535 .info = ad198x_mux_enum_info,
536 .get = ad198x_mux_enum_get,
537 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 },
539 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
540 { } /* end */
541};
542
Takashi Iwai9230d212006-03-13 13:49:49 +0100543/* additional mixers for 3stack mode */
544static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
545 {
546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
547 .name = "Channel Mode",
548 .info = ad198x_ch_mode_info,
549 .get = ad198x_ch_mode_get,
550 .put = ad198x_ch_mode_put,
551 },
552 { } /* end */
553};
554
555/* laptop model - 2ch only */
556static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
557
558static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
559 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
560 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
561 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
562 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
563 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
564 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
565 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
566 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
567 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
568 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
570 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
571 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
572 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
573 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
575 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
576 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
577 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
578 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
579 {
580 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
581 .name = "Capture Source",
582 .info = ad198x_mux_enum_info,
583 .get = ad198x_mux_enum_get,
584 .put = ad198x_mux_enum_put,
585 },
586 { } /* end */
587};
588
Takashi Iwai825aa972006-03-17 10:50:49 +0100589/* laptop-eapd model - 2ch only */
590
591/* master controls both pins 0x1a and 0x1b */
592static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
593 struct snd_ctl_elem_value *ucontrol)
594{
595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
596 long *valp = ucontrol->value.integer.value;
597 int change;
598
599 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
600 0x7f, valp[0] & 0x7f);
601 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
602 0x7f, valp[1] & 0x7f);
603 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
604 0x7f, valp[0] & 0x7f);
605 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
606 0x7f, valp[1] & 0x7f);
607 return change;
608}
609
610static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 long *valp = ucontrol->value.integer.value;
615 int change;
616
617 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
618 0x80, valp[0] ? 0 : 0x80);
619 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
620 0x80, valp[1] ? 0 : 0x80);
621 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
622 0x80, valp[0] ? 0 : 0x80);
623 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
624 0x80, valp[1] ? 0 : 0x80);
625 return change;
626}
627
628static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
629 .num_items = 3,
630 .items = {
631 { "Mic", 0x0 },
632 { "Internal Mic", 0x4 },
633 { "Mix", 0x5 },
634 },
635};
636
637static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
638 {
639 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
640 .name = "Master Playback Volume",
641 .info = snd_hda_mixer_amp_volume_info,
642 .get = snd_hda_mixer_amp_volume_get,
643 .put = ad1986a_laptop_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200644 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwai825aa972006-03-17 10:50:49 +0100645 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
646 },
647 {
648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
649 .name = "Master Playback Switch",
650 .info = snd_hda_mixer_amp_switch_info,
651 .get = snd_hda_mixer_amp_switch_get,
652 .put = ad1986a_laptop_master_sw_put,
653 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
654 },
655 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
656 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
657 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
658 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
659 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
660 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
661 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
662 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
663 {
664 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
665 .name = "Capture Source",
666 .info = ad198x_mux_enum_info,
667 .get = ad198x_mux_enum_get,
668 .put = ad198x_mux_enum_put,
669 },
670 {
671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
672 .name = "External Amplifier",
673 .info = ad198x_eapd_info,
674 .get = ad198x_eapd_get,
675 .put = ad198x_eapd_put,
676 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
677 },
678 { } /* end */
679};
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681/*
682 * initialization verbs
683 */
684static struct hda_verb ad1986a_init_verbs[] = {
685 /* Front, Surround, CLFE DAC; mute as default */
686 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
687 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
688 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
689 /* Downmix - off */
690 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
691 /* HP, Line-Out, Surround, CLFE selectors */
692 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
693 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
694 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
695 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
696 /* Mono selector */
697 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
698 /* Mic selector: Mic 1/2 pin */
699 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
700 /* Line-in selector: Line-in */
701 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
702 /* Mic 1/2 swap */
703 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
704 /* Record selector: mic */
705 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
706 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
707 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
709 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
710 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
711 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
712 /* PC beep */
713 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
714 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
715 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
716 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
717 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
718 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
719 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200720 /* HP Pin */
721 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
722 /* Front, Surround, CLFE Pins */
723 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
724 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
725 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
726 /* Mono Pin */
727 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
728 /* Mic Pin */
729 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
730 /* Line, Aux, CD, Beep-In Pin */
731 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
732 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
733 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
734 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
735 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 { } /* end */
737};
738
Takashi Iwai9230d212006-03-13 13:49:49 +0100739/* additional verbs for 3-stack model */
740static struct hda_verb ad1986a_3st_init_verbs[] = {
741 /* Mic and line-in selectors */
742 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
743 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
744 { } /* end */
745};
746
747static struct hda_verb ad1986a_ch2_init[] = {
748 /* Surround out -> Line In */
749 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
750 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
751 /* CLFE -> Mic in */
752 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
753 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
754 { } /* end */
755};
756
757static struct hda_verb ad1986a_ch4_init[] = {
758 /* Surround out -> Surround */
759 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
760 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
761 /* CLFE -> Mic in */
762 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
763 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
764 { } /* end */
765};
766
767static struct hda_verb ad1986a_ch6_init[] = {
768 /* Surround out -> Surround out */
769 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
770 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
771 /* CLFE -> CLFE */
772 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
773 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
774 { } /* end */
775};
776
777static struct hda_channel_mode ad1986a_modes[3] = {
778 { 2, ad1986a_ch2_init },
779 { 4, ad1986a_ch4_init },
780 { 6, ad1986a_ch6_init },
781};
782
Takashi Iwai825aa972006-03-17 10:50:49 +0100783/* eapd initialization */
784static struct hda_verb ad1986a_eapd_init_verbs[] = {
785 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00},
786 {}
787};
788
Takashi Iwai9230d212006-03-13 13:49:49 +0100789/* models */
Takashi Iwai825aa972006-03-17 10:50:49 +0100790enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP, AD1986A_LAPTOP_EAPD };
Takashi Iwai9230d212006-03-13 13:49:49 +0100791
792static struct hda_board_config ad1986a_cfg_tbl[] = {
793 { .modelname = "6stack", .config = AD1986A_6STACK },
794 { .modelname = "3stack", .config = AD1986A_3STACK },
Takashi Iwai82bc9552006-03-21 11:24:42 +0100795 { .pci_subvendor = 0x10de, .pci_subdevice = 0xcb84,
796 .config = AD1986A_3STACK }, /* ASUS A8N-VM CSM */
Nickolay V. Shmyreva48bb282006-11-21 18:56:37 +0100797 { .pci_subvendor = 0x1043, .pci_subdevice = 0x817f,
798 .config = AD1986A_3STACK }, /* ASUS P5P-L2 */
Takashi Iwai41f0cd32006-06-21 12:14:40 +0200799 { .pci_subvendor = 0x1043, .pci_subdevice = 0x81b3,
800 .config = AD1986A_3STACK }, /* ASUS P5RD2-VM / P5GPL-X SE */
Takashi Iwai827a56e2006-07-25 14:51:16 +0200801 { .pci_subvendor = 0x1043, .pci_subdevice = 0x81cb,
802 .config = AD1986A_3STACK }, /* ASUS M2NPV-VM */
Takashi Iwai9230d212006-03-13 13:49:49 +0100803 { .modelname = "laptop", .config = AD1986A_LAPTOP },
804 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
805 .config = AD1986A_LAPTOP }, /* FSC V2060 */
806 { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
807 .config = AD1986A_LAPTOP }, /* Samsung M50 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100808 { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
809 .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
810 { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD },
Takashi Iwaib2e1b0c2006-06-27 12:48:59 +0200811 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc023,
812 .config = AD1986A_LAPTOP_EAPD }, /* Samsung X60 Chane */
Takashi Iwai825aa972006-03-17 10:50:49 +0100813 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
814 .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
Takashi Iwai0a197f02006-07-25 14:51:14 +0200815 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc026,
Christian Hesseba8bdf82006-11-08 15:50:41 +0100816 .config = AD1986A_LAPTOP_EAPD }, /* Samsung X11-T2300 Culesa */
Takashi Iwai61a74542006-04-20 16:42:34 +0200817 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1153,
818 .config = AD1986A_LAPTOP_EAPD }, /* ASUS M9 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100819 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
820 .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
Takashi Iwaie0922282006-04-10 19:09:01 +0200821 { .pci_subvendor = 0x1043, .pci_subdevice = 0x11f7,
822 .config = AD1986A_LAPTOP_EAPD }, /* ASUS U5A */
Takashi Iwai264e6e32006-10-13 12:40:51 +0200823 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1263,
824 .config = AD1986A_LAPTOP_EAPD }, /* ASUS U5F */
Takashi Iwaie0292bd2006-04-26 17:44:18 +0200825 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1297,
826 .config = AD1986A_LAPTOP_EAPD }, /* ASUS Z62F */
Takashi Iwai4a95cd82006-11-07 13:48:42 +0100827 { .pci_subvendor = 0x1043, .pci_subdevice = 0x12b3,
828 .config = AD1986A_LAPTOP_EAPD }, /* ASUS V1j */
Coywolf Qi Huntbe28e7c2006-04-10 10:47:11 +0200829 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30af,
830 .config = AD1986A_LAPTOP_EAPD }, /* HP Compaq Presario B2800 */
Daniel T Chen6dac9a62006-06-21 08:51:07 +0200831 { .pci_subvendor = 0x17aa, .pci_subdevice = 0x2066,
832 .config = AD1986A_LAPTOP_EAPD }, /* Lenovo 3000 N100-07684JU */
Takashi Iwai9230d212006-03-13 13:49:49 +0100833 {}
834};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836static int patch_ad1986a(struct hda_codec *codec)
837{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200838 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100839 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200841 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 if (spec == NULL)
843 return -ENOMEM;
844
Ingo Molnar62932df2006-01-16 16:34:20 +0100845 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 codec->spec = spec;
847
848 spec->multiout.max_channels = 6;
849 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
850 spec->multiout.dac_nids = ad1986a_dac_nids;
851 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100852 spec->num_adc_nids = 1;
853 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100854 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200855 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100856 spec->num_mixers = 1;
857 spec->mixers[0] = ad1986a_mixers;
858 spec->num_init_verbs = 1;
859 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200861 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Takashi Iwai9230d212006-03-13 13:49:49 +0100863 /* override some parameters */
864 board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
865 switch (board_config) {
866 case AD1986A_3STACK:
867 spec->num_mixers = 2;
868 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200869 spec->num_init_verbs = 3;
Takashi Iwai9230d212006-03-13 13:49:49 +0100870 spec->init_verbs[1] = ad1986a_3st_init_verbs;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200871 spec->init_verbs[2] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100872 spec->channel_mode = ad1986a_modes;
873 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200874 spec->need_dac_fix = 1;
875 spec->multiout.max_channels = 2;
876 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100877 break;
878 case AD1986A_LAPTOP:
879 spec->mixers[0] = ad1986a_laptop_mixers;
880 spec->multiout.max_channels = 2;
881 spec->multiout.num_dacs = 1;
882 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
883 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100884 case AD1986A_LAPTOP_EAPD:
885 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
886 spec->num_init_verbs = 2;
887 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
888 spec->multiout.max_channels = 2;
889 spec->multiout.num_dacs = 1;
890 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
891 spec->multiout.dig_out_nid = 0;
892 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
893 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100894 }
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 return 0;
897}
898
899/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200900 * AD1983 specific
901 */
902
903#define AD1983_SPDIF_OUT 0x02
904#define AD1983_DAC 0x03
905#define AD1983_ADC 0x04
906
907static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100908static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100909static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200910
911static struct hda_input_mux ad1983_capture_source = {
912 .num_items = 4,
913 .items = {
914 { "Mic", 0x0 },
915 { "Line", 0x1 },
916 { "Mix", 0x2 },
917 { "Mix Mono", 0x3 },
918 },
919};
920
921/*
922 * SPDIF playback route
923 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100924static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200925{
926 static char *texts[] = { "PCM", "ADC" };
927
928 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
929 uinfo->count = 1;
930 uinfo->value.enumerated.items = 2;
931 if (uinfo->value.enumerated.item > 1)
932 uinfo->value.enumerated.item = 1;
933 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
934 return 0;
935}
936
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100937static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200938{
939 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
940 struct ad198x_spec *spec = codec->spec;
941
942 ucontrol->value.enumerated.item[0] = spec->spdif_route;
943 return 0;
944}
945
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100946static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200947{
948 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
949 struct ad198x_spec *spec = codec->spec;
950
951 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
952 spec->spdif_route = ucontrol->value.enumerated.item[0];
953 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
954 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
955 return 1;
956 }
957 return 0;
958}
959
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100960static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200961 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
962 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
963 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
964 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
965 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
966 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
967 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
968 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
969 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
970 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
971 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
972 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
973 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
974 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
975 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
976 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
977 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
978 {
979 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
980 .name = "Capture Source",
981 .info = ad198x_mux_enum_info,
982 .get = ad198x_mux_enum_get,
983 .put = ad198x_mux_enum_put,
984 },
985 {
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +0200987 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200988 .info = ad1983_spdif_route_info,
989 .get = ad1983_spdif_route_get,
990 .put = ad1983_spdif_route_put,
991 },
992 { } /* end */
993};
994
995static struct hda_verb ad1983_init_verbs[] = {
996 /* Front, HP, Mono; mute as default */
997 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
998 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
999 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1000 /* Beep, PCM, Mic, Line-In: mute */
1001 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1002 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1003 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1004 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1005 /* Front, HP selectors; from Mix */
1006 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1007 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1008 /* Mono selector; from Mix */
1009 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1010 /* Mic selector; Mic */
1011 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1012 /* Line-in selector: Line-in */
1013 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1014 /* Mic boost: 0dB */
1015 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1016 /* Record selector: mic */
1017 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1018 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1019 /* SPDIF route: PCM */
1020 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1021 /* Front Pin */
1022 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1023 /* HP Pin */
1024 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1025 /* Mono Pin */
1026 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1027 /* Mic Pin */
1028 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1029 /* Line Pin */
1030 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1031 { } /* end */
1032};
1033
Takashi Iwai985be542005-11-02 18:26:49 +01001034
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001035static int patch_ad1983(struct hda_codec *codec)
1036{
1037 struct ad198x_spec *spec;
1038
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001039 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001040 if (spec == NULL)
1041 return -ENOMEM;
1042
Ingo Molnar62932df2006-01-16 16:34:20 +01001043 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001044 codec->spec = spec;
1045
1046 spec->multiout.max_channels = 2;
1047 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1048 spec->multiout.dac_nids = ad1983_dac_nids;
1049 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001050 spec->num_adc_nids = 1;
1051 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001052 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001053 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001054 spec->num_mixers = 1;
1055 spec->mixers[0] = ad1983_mixers;
1056 spec->num_init_verbs = 1;
1057 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001058 spec->spdif_route = 0;
1059
1060 codec->patch_ops = ad198x_patch_ops;
1061
1062 return 0;
1063}
1064
1065
1066/*
1067 * AD1981 HD specific
1068 */
1069
1070#define AD1981_SPDIF_OUT 0x02
1071#define AD1981_DAC 0x03
1072#define AD1981_ADC 0x04
1073
1074static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001075static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001076static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001077
1078/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1079static struct hda_input_mux ad1981_capture_source = {
1080 .num_items = 7,
1081 .items = {
1082 { "Front Mic", 0x0 },
1083 { "Line", 0x1 },
1084 { "Mix", 0x2 },
1085 { "Mix Mono", 0x3 },
1086 { "CD", 0x4 },
1087 { "Mic", 0x6 },
1088 { "Aux", 0x7 },
1089 },
1090};
1091
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001092static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001093 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1094 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1095 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1096 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1097 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1098 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1100 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1103 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1104 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1105 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1106 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1107 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1108 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1109 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1110 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1111 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1112 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1113 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1114 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1115 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1116 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1117 {
1118 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1119 .name = "Capture Source",
1120 .info = ad198x_mux_enum_info,
1121 .get = ad198x_mux_enum_get,
1122 .put = ad198x_mux_enum_put,
1123 },
1124 /* identical with AD1983 */
1125 {
1126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001127 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001128 .info = ad1983_spdif_route_info,
1129 .get = ad1983_spdif_route_get,
1130 .put = ad1983_spdif_route_put,
1131 },
1132 { } /* end */
1133};
1134
1135static struct hda_verb ad1981_init_verbs[] = {
1136 /* Front, HP, Mono; mute as default */
1137 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1138 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1139 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1140 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1141 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1142 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1143 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1144 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1145 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1146 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1147 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1148 /* Front, HP selectors; from Mix */
1149 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1150 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1151 /* Mono selector; from Mix */
1152 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1153 /* Mic Mixer; select Front Mic */
1154 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1155 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1156 /* Mic boost: 0dB */
1157 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1158 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1159 /* Record selector: Front mic */
1160 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1161 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1162 /* SPDIF route: PCM */
1163 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1164 /* Front Pin */
1165 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1166 /* HP Pin */
1167 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1168 /* Mono Pin */
1169 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1170 /* Front & Rear Mic Pins */
1171 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1172 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1173 /* Line Pin */
1174 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1175 /* Digital Beep */
1176 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1177 /* Line-Out as Input: disabled */
1178 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1179 { } /* end */
1180};
1181
Takashi Iwai18a815d2006-03-01 19:54:39 +01001182/*
1183 * Patch for HP nx6320
1184 *
1185 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
1186 * speaker output enabled _and_ mute-LED off.
1187 */
1188
1189#define AD1981_HP_EVENT 0x37
1190#define AD1981_MIC_EVENT 0x38
1191
1192static struct hda_verb ad1981_hp_init_verbs[] = {
1193 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1194 /* pin sensing on HP and Mic jacks */
1195 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1196 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1197 {}
1198};
1199
1200/* turn on/off EAPD (+ mute HP) as a master switch */
1201static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1202 struct snd_ctl_elem_value *ucontrol)
1203{
1204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1205 struct ad198x_spec *spec = codec->spec;
1206
1207 if (! ad198x_eapd_put(kcontrol, ucontrol))
1208 return 0;
1209
1210 /* toggle HP mute appropriately */
1211 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1212 0x80, spec->cur_eapd ? 0 : 0x80);
1213 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1214 0x80, spec->cur_eapd ? 0 : 0x80);
1215 return 1;
1216}
1217
1218/* bind volumes of both NID 0x05 and 0x06 */
1219static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1220 struct snd_ctl_elem_value *ucontrol)
1221{
1222 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1223 long *valp = ucontrol->value.integer.value;
1224 int change;
1225
1226 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1227 0x7f, valp[0] & 0x7f);
1228 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1229 0x7f, valp[1] & 0x7f);
1230 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1231 0x7f, valp[0] & 0x7f);
1232 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1233 0x7f, valp[1] & 0x7f);
1234 return change;
1235}
1236
1237/* mute internal speaker if HP is plugged */
1238static void ad1981_hp_automute(struct hda_codec *codec)
1239{
1240 unsigned int present;
1241
1242 present = snd_hda_codec_read(codec, 0x06, 0,
1243 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1244 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1245 0x80, present ? 0x80 : 0);
1246 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1247 0x80, present ? 0x80 : 0);
1248}
1249
1250/* toggle input of built-in and mic jack appropriately */
1251static void ad1981_hp_automic(struct hda_codec *codec)
1252{
1253 static struct hda_verb mic_jack_on[] = {
1254 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1255 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1256 {}
1257 };
1258 static struct hda_verb mic_jack_off[] = {
1259 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1260 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1261 {}
1262 };
1263 unsigned int present;
1264
1265 present = snd_hda_codec_read(codec, 0x08, 0,
1266 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1267 if (present)
1268 snd_hda_sequence_write(codec, mic_jack_on);
1269 else
1270 snd_hda_sequence_write(codec, mic_jack_off);
1271}
1272
1273/* unsolicited event for HP jack sensing */
1274static void ad1981_hp_unsol_event(struct hda_codec *codec,
1275 unsigned int res)
1276{
1277 res >>= 26;
1278 switch (res) {
1279 case AD1981_HP_EVENT:
1280 ad1981_hp_automute(codec);
1281 break;
1282 case AD1981_MIC_EVENT:
1283 ad1981_hp_automic(codec);
1284 break;
1285 }
1286}
1287
1288static struct hda_input_mux ad1981_hp_capture_source = {
1289 .num_items = 3,
1290 .items = {
1291 { "Mic", 0x0 },
1292 { "Docking-Station", 0x1 },
1293 { "Mix", 0x2 },
1294 },
1295};
1296
1297static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1298 {
1299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1300 .name = "Master Playback Volume",
1301 .info = snd_hda_mixer_amp_volume_info,
1302 .get = snd_hda_mixer_amp_volume_get,
1303 .put = ad1981_hp_master_vol_put,
1304 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1305 },
1306 {
1307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1308 .name = "Master Playback Switch",
1309 .info = ad198x_eapd_info,
1310 .get = ad198x_eapd_get,
1311 .put = ad1981_hp_master_sw_put,
1312 .private_value = 0x05,
1313 },
1314 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1315 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1316#if 0
1317 /* FIXME: analog mic/line loopback doesn't work with my tests...
1318 * (although recording is OK)
1319 */
1320 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1321 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1322 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1323 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1324 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1325 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1326 /* FIXME: does this laptop have analog CD connection? */
1327 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1328 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1329#endif
1330 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1331 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1332 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1333 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1334 {
1335 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1336 .name = "Capture Source",
1337 .info = ad198x_mux_enum_info,
1338 .get = ad198x_mux_enum_get,
1339 .put = ad198x_mux_enum_put,
1340 },
1341 { } /* end */
1342};
1343
1344/* initialize jack-sensing, too */
1345static int ad1981_hp_init(struct hda_codec *codec)
1346{
1347 ad198x_init(codec);
1348 ad1981_hp_automute(codec);
1349 ad1981_hp_automic(codec);
1350 return 0;
1351}
1352
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001353/* configuration for Lenovo Thinkpad T60 */
1354static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1355 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1356 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1357 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1364 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1366 {
1367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1368 .name = "Capture Source",
1369 .info = ad198x_mux_enum_info,
1370 .get = ad198x_mux_enum_get,
1371 .put = ad198x_mux_enum_put,
1372 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001373 /* identical with AD1983 */
1374 {
1375 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1376 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1377 .info = ad1983_spdif_route_info,
1378 .get = ad1983_spdif_route_get,
1379 .put = ad1983_spdif_route_put,
1380 },
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001381 { } /* end */
1382};
1383
1384static struct hda_input_mux ad1981_thinkpad_capture_source = {
1385 .num_items = 3,
1386 .items = {
1387 { "Mic", 0x0 },
1388 { "Mix", 0x2 },
1389 { "CD", 0x4 },
1390 },
1391};
1392
Takashi Iwai18a815d2006-03-01 19:54:39 +01001393/* models */
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001394enum { AD1981_BASIC, AD1981_HP, AD1981_THINKPAD };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001395
1396static struct hda_board_config ad1981_cfg_tbl[] = {
1397 { .modelname = "hp", .config = AD1981_HP },
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001398 /* All HP models */
1399 { .pci_subvendor = 0x103c, .config = AD1981_HP },
Takashi Iwaif8e9f342006-06-01 21:08:53 +02001400 { .pci_subvendor = 0x30b0, .pci_subdevice = 0x103c,
1401 .config = AD1981_HP }, /* HP nx6320 (reversed SSID, H/W bug) */
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001402 { .modelname = "thinkpad", .config = AD1981_THINKPAD },
1403 /* Lenovo Thinkpad T60/X60/Z6xx */
1404 { .pci_subvendor = 0x17aa, .config = AD1981_THINKPAD },
Takashi Iwai887709b2006-04-18 13:27:31 +02001405 { .pci_subvendor = 0x1014, .pci_subdevice = 0x0597,
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001406 .config = AD1981_THINKPAD }, /* Z60m/t */
Takashi Iwai18a815d2006-03-01 19:54:39 +01001407 { .modelname = "basic", .config = AD1981_BASIC },
1408 {}
1409};
1410
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001411static int patch_ad1981(struct hda_codec *codec)
1412{
1413 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001414 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001415
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001416 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001417 if (spec == NULL)
1418 return -ENOMEM;
1419
Ingo Molnar62932df2006-01-16 16:34:20 +01001420 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001421 codec->spec = spec;
1422
1423 spec->multiout.max_channels = 2;
1424 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1425 spec->multiout.dac_nids = ad1981_dac_nids;
1426 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001427 spec->num_adc_nids = 1;
1428 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001429 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001430 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001431 spec->num_mixers = 1;
1432 spec->mixers[0] = ad1981_mixers;
1433 spec->num_init_verbs = 1;
1434 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001435 spec->spdif_route = 0;
1436
1437 codec->patch_ops = ad198x_patch_ops;
1438
Takashi Iwai18a815d2006-03-01 19:54:39 +01001439 /* override some parameters */
1440 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1441 switch (board_config) {
1442 case AD1981_HP:
1443 spec->mixers[0] = ad1981_hp_mixers;
1444 spec->num_init_verbs = 2;
1445 spec->init_verbs[1] = ad1981_hp_init_verbs;
1446 spec->multiout.dig_out_nid = 0;
1447 spec->input_mux = &ad1981_hp_capture_source;
1448
1449 codec->patch_ops.init = ad1981_hp_init;
1450 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1451 break;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001452 case AD1981_THINKPAD:
1453 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001454 spec->input_mux = &ad1981_thinkpad_capture_source;
1455 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001456 }
1457
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001458 return 0;
1459}
1460
1461
1462/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001463 * AD1988
1464 *
1465 * Output pins and routes
1466 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001467 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001468 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1469 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1470 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1471 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1472 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1473 * port-F 0x16 (mute) <- 0x2a <- 06
1474 * port-G 0x24 (mute) <- 0x27 <- 05
1475 * port-H 0x25 (mute) <- 0x28 <- 0a
1476 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1477 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001478 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1479 * (*) 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 +01001480 *
1481 * Input pins and routes
1482 *
1483 * pin boost mix input # / adc input #
1484 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1485 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1486 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1487 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1488 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1489 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1490 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1491 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1492 *
1493 *
1494 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001495 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001496 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001497 *
1498 * Inputs of Analog Mix (0x20)
1499 * 0:Port-B (front mic)
1500 * 1:Port-C/G/H (line-in)
1501 * 2:Port-A
1502 * 3:Port-D (line-in/2)
1503 * 4:Port-E/G/H (mic-in)
1504 * 5:Port-F (mic2-in)
1505 * 6:CD
1506 * 7:Beep
1507 *
1508 * ADC selection
1509 * 0:Port-A
1510 * 1:Port-B (front mic-in)
1511 * 2:Port-C (line-in)
1512 * 3:Port-F (mic2-in)
1513 * 4:Port-E (mic-in)
1514 * 5:CD
1515 * 6:Port-G
1516 * 7:Port-H
1517 * 8:Port-D (line-in/2)
1518 * 9:Mix
1519 *
1520 * Proposed pin assignments by the datasheet
1521 *
1522 * 6-stack
1523 * Port-A front headphone
1524 * B front mic-in
1525 * C rear line-in
1526 * D rear front-out
1527 * E rear mic-in
1528 * F rear surround
1529 * G rear CLFE
1530 * H rear side
1531 *
1532 * 3-stack
1533 * Port-A front headphone
1534 * B front mic
1535 * C rear line-in/surround
1536 * D rear front-out
1537 * E rear mic-in/CLFE
1538 *
1539 * laptop
1540 * Port-A headphone
1541 * B mic-in
1542 * C docking station
1543 * D internal speaker (with EAPD)
1544 * E/F quad mic array
1545 */
1546
1547
1548/* models */
1549enum {
1550 AD1988_6STACK,
1551 AD1988_6STACK_DIG,
1552 AD1988_3STACK,
1553 AD1988_3STACK_DIG,
1554 AD1988_LAPTOP,
1555 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001556 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001557 AD1988_MODEL_LAST,
1558};
1559
Takashi Iwaid32410b12005-11-24 16:06:23 +01001560/* reivision id to check workarounds */
1561#define AD1988A_REV2 0x100200
1562
Takashi Iwai1a806f42006-07-03 15:58:16 +02001563#define is_rev2(codec) \
1564 ((codec)->vendor_id == 0x11d41988 && \
1565 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001566
1567/*
1568 * mixers
1569 */
1570
Takashi Iwaid32410b12005-11-24 16:06:23 +01001571static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001572 0x04, 0x06, 0x05, 0x0a
1573};
1574
Takashi Iwaid32410b12005-11-24 16:06:23 +01001575static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001576 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001577};
1578
1579/* for AD1988A revision-2, DAC2-4 are swapped */
1580static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1581 0x04, 0x05, 0x0a, 0x06
1582};
1583
1584static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001585 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001586};
1587
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001588static hda_nid_t ad1988_adc_nids[3] = {
1589 0x08, 0x09, 0x0f
1590};
1591
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001592static hda_nid_t ad1988_capsrc_nids[3] = {
1593 0x0c, 0x0d, 0x0e
1594};
1595
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001596#define AD1988_SPDIF_OUT 0x02
1597#define AD1988_SPDIF_IN 0x07
1598
1599static struct hda_input_mux ad1988_6stack_capture_source = {
1600 .num_items = 5,
1601 .items = {
1602 { "Front Mic", 0x0 },
1603 { "Line", 0x1 },
1604 { "Mic", 0x4 },
1605 { "CD", 0x5 },
1606 { "Mix", 0x9 },
1607 },
1608};
1609
1610static struct hda_input_mux ad1988_laptop_capture_source = {
1611 .num_items = 3,
1612 .items = {
1613 { "Mic/Line", 0x0 },
1614 { "CD", 0x5 },
1615 { "Mix", 0x9 },
1616 },
1617};
1618
1619/*
1620 */
1621static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_info *uinfo)
1623{
1624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1625 struct ad198x_spec *spec = codec->spec;
1626 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1627 spec->num_channel_mode);
1628}
1629
1630static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1631 struct snd_ctl_elem_value *ucontrol)
1632{
1633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1634 struct ad198x_spec *spec = codec->spec;
1635 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1636 spec->num_channel_mode, spec->multiout.max_channels);
1637}
1638
1639static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1640 struct snd_ctl_elem_value *ucontrol)
1641{
1642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1643 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001644 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1645 spec->num_channel_mode,
1646 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001647 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001648 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001649 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001650}
1651
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001652/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001653static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001654 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1655 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1656 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1657 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1658 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001659 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001660};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001661
Takashi Iwaid32410b12005-11-24 16:06:23 +01001662static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1663 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1664 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1665 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1666 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1667 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001668 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001669};
1670
1671static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001672 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1673 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1674 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1675 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1676 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1677 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1678 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1679
1680 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1681 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1682 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1683 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1684 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1685 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1686 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1687 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1688
1689 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1690 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1691
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001692 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001693 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1694
1695 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1696 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1697
1698 { } /* end */
1699};
1700
1701/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001702static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001703 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001704 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001705 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1706 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001707 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001708};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001709
Takashi Iwaid32410b12005-11-24 16:06:23 +01001710static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1711 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001712 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1713 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1714 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001715 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001716};
1717
1718static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001719 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001720 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1721 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1722 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001723 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, 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("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1729 HDA_CODEC_MUTE("Front 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 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1733 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1734
1735 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1736 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1737
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001738 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001739 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1740
1741 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1742 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1743 {
1744 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1745 .name = "Channel Mode",
1746 .info = ad198x_ch_mode_info,
1747 .get = ad198x_ch_mode_get,
1748 .put = ad198x_ch_mode_put,
1749 },
1750
1751 { } /* end */
1752};
1753
1754/* laptop mode */
1755static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1756 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1757 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1758 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1759
1760 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1761 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1762 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1763 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1764 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1765 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1766
1767 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1768 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1769
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001770 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001771 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1772
1773 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1774
1775 {
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001778 .info = ad198x_eapd_info,
1779 .get = ad198x_eapd_get,
1780 .put = ad198x_eapd_put,
1781 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001782 },
1783
1784 { } /* end */
1785};
1786
1787/* capture */
1788static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1789 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1790 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1791 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1792 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1793 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1794 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1795 {
1796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1797 /* The multiple "Capture Source" controls confuse alsamixer
1798 * So call somewhat different..
1799 * FIXME: the controls appear in the "playback" view!
1800 */
1801 /* .name = "Capture Source", */
1802 .name = "Input Source",
1803 .count = 3,
1804 .info = ad198x_mux_enum_info,
1805 .get = ad198x_mux_enum_get,
1806 .put = ad198x_mux_enum_put,
1807 },
1808 { } /* end */
1809};
1810
1811static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1812 struct snd_ctl_elem_info *uinfo)
1813{
1814 static char *texts[] = {
1815 "PCM", "ADC1", "ADC2", "ADC3"
1816 };
1817 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1818 uinfo->count = 1;
1819 uinfo->value.enumerated.items = 4;
1820 if (uinfo->value.enumerated.item >= 4)
1821 uinfo->value.enumerated.item = 3;
1822 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1823 return 0;
1824}
1825
1826static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1827 struct snd_ctl_elem_value *ucontrol)
1828{
1829 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1830 unsigned int sel;
1831
1832 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1833 if (sel > 0) {
1834 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1835 if (sel <= 3)
1836 sel++;
1837 else
1838 sel = 0;
1839 }
1840 ucontrol->value.enumerated.item[0] = sel;
1841 return 0;
1842}
1843
1844static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1845 struct snd_ctl_elem_value *ucontrol)
1846{
1847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1848 unsigned int sel;
1849 int change;
1850
1851 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1852 if (! ucontrol->value.enumerated.item[0]) {
1853 change = sel != 0;
1854 if (change)
1855 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1856 } else {
1857 change = sel == 0;
1858 if (change)
1859 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1860 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1861 change |= sel == ucontrol->value.enumerated.item[0];
1862 if (change)
1863 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1864 ucontrol->value.enumerated.item[0] - 1);
1865 }
1866 return change;
1867}
1868
1869static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1870 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1871 {
1872 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1873 .name = "IEC958 Playback Source",
1874 .info = ad1988_spdif_playback_source_info,
1875 .get = ad1988_spdif_playback_source_get,
1876 .put = ad1988_spdif_playback_source_put,
1877 },
1878 { } /* end */
1879};
1880
1881static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1882 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1883 { } /* end */
1884};
1885
1886
1887/*
1888 * initialization verbs
1889 */
1890
1891/*
1892 * for 6-stack (+dig)
1893 */
1894static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001895 /* Front, Surround, CLFE, side DAC; unmute as default */
1896 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1898 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1899 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001900 /* Port-A front headphon path */
1901 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1902 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1903 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1904 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1905 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1906 /* Port-D line-out path */
1907 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1908 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1909 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1910 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1911 /* Port-F surround path */
1912 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1913 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1914 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1915 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1916 /* Port-G CLFE path */
1917 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1918 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1919 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1920 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1921 /* Port-H side path */
1922 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1923 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1924 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1925 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1926 /* Mono out path */
1927 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1928 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1929 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1930 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1931 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1932 /* Port-B front mic-in path */
1933 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1934 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1935 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1936 /* Port-C line-in path */
1937 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1938 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1939 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1940 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1941 /* Port-E mic-in path */
1942 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1943 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1944 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1945 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1946
1947 { }
1948};
1949
1950static struct hda_verb ad1988_capture_init_verbs[] = {
1951 /* mute analog mix */
1952 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1953 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1954 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1955 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1956 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1957 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1958 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1959 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1960 /* select ADCs - front-mic */
1961 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1962 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1963 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1964 /* ADCs; muted */
1965 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1966 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1967 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1968
1969 { }
1970};
1971
1972static struct hda_verb ad1988_spdif_init_verbs[] = {
1973 /* SPDIF out sel */
1974 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1975 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1976 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1977 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1978 /* SPDIF out pin */
1979 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1980 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1981
1982 { }
1983};
1984
1985/*
1986 * verbs for 3stack (+dig)
1987 */
1988static struct hda_verb ad1988_3stack_ch2_init[] = {
1989 /* set port-C to line-in */
1990 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1991 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1992 /* set port-E to mic-in */
1993 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1994 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1995 { } /* end */
1996};
1997
1998static struct hda_verb ad1988_3stack_ch6_init[] = {
1999 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002000 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002001 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002002 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002003 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002004 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002005 { } /* end */
2006};
2007
2008static struct hda_channel_mode ad1988_3stack_modes[2] = {
2009 { 2, ad1988_3stack_ch2_init },
2010 { 6, ad1988_3stack_ch6_init },
2011};
2012
2013static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002014 /* Front, Surround, CLFE, side DAC; unmute as default */
2015 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2017 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2018 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002019 /* Port-A front headphon path */
2020 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2021 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2022 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2023 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2024 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2025 /* Port-D line-out path */
2026 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2027 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2028 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2029 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2030 /* Mono out path */
2031 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2032 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2033 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2034 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2035 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2036 /* Port-B front mic-in path */
2037 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2038 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2039 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002040 /* Port-C line-in/surround path - 6ch mode as default */
2041 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2042 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002043 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002044 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002045 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002046 /* Port-E mic-in/CLFE path - 6ch mode as default */
2047 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2048 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002049 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002050 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002051 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2052 /* mute analog mix */
2053 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2054 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2055 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2056 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2057 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2058 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2059 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2060 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2061 /* select ADCs - front-mic */
2062 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2063 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2064 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2065 /* ADCs; muted */
2066 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2067 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2068 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2069 { }
2070};
2071
2072/*
2073 * verbs for laptop mode (+dig)
2074 */
2075static struct hda_verb ad1988_laptop_hp_on[] = {
2076 /* unmute port-A and mute port-D */
2077 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2078 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2079 { } /* end */
2080};
2081static struct hda_verb ad1988_laptop_hp_off[] = {
2082 /* mute port-A and unmute port-D */
2083 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2084 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2085 { } /* end */
2086};
2087
2088#define AD1988_HP_EVENT 0x01
2089
2090static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002091 /* Front, Surround, CLFE, side DAC; unmute as default */
2092 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2093 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2094 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2095 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002096 /* Port-A front headphon path */
2097 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2098 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2099 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2100 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2101 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2102 /* unsolicited event for pin-sense */
2103 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2104 /* Port-D line-out path + EAPD */
2105 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2106 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2107 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2108 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2109 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2110 /* Mono out path */
2111 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2112 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2113 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2114 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2115 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2116 /* Port-B mic-in path */
2117 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2118 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2119 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2120 /* Port-C docking station - try to output */
2121 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2122 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2123 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2124 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2125 /* mute analog mix */
2126 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2127 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2128 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2129 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2130 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2131 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2132 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2133 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2134 /* select ADCs - mic */
2135 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2136 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2137 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2138 /* ADCs; muted */
2139 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2140 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2141 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2142 { }
2143};
2144
2145static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2146{
2147 if ((res >> 26) != AD1988_HP_EVENT)
2148 return;
2149 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2150 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2151 else
2152 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2153}
2154
2155
2156/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002157 * Automatic parse of I/O pins from the BIOS configuration
2158 */
2159
2160#define NUM_CONTROL_ALLOC 32
2161#define NUM_VERB_ALLOC 32
2162
2163enum {
2164 AD_CTL_WIDGET_VOL,
2165 AD_CTL_WIDGET_MUTE,
2166 AD_CTL_BIND_MUTE,
2167};
2168static struct snd_kcontrol_new ad1988_control_templates[] = {
2169 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2170 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2171 HDA_BIND_MUTE(NULL, 0, 0, 0),
2172};
2173
2174/* add dynamic controls */
2175static int add_control(struct ad198x_spec *spec, int type, const char *name,
2176 unsigned long val)
2177{
2178 struct snd_kcontrol_new *knew;
2179
2180 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2181 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2182
2183 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2184 if (! knew)
2185 return -ENOMEM;
2186 if (spec->kctl_alloc) {
2187 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2188 kfree(spec->kctl_alloc);
2189 }
2190 spec->kctl_alloc = knew;
2191 spec->num_kctl_alloc = num;
2192 }
2193
2194 knew = &spec->kctl_alloc[spec->num_kctl_used];
2195 *knew = ad1988_control_templates[type];
2196 knew->name = kstrdup(name, GFP_KERNEL);
2197 if (! knew->name)
2198 return -ENOMEM;
2199 knew->private_value = val;
2200 spec->num_kctl_used++;
2201 return 0;
2202}
2203
2204#define AD1988_PIN_CD_NID 0x18
2205#define AD1988_PIN_BEEP_NID 0x10
2206
2207static hda_nid_t ad1988_mixer_nids[8] = {
2208 /* A B C D E F G H */
2209 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2210};
2211
2212static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2213{
2214 static hda_nid_t idx_to_dac[8] = {
2215 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002216 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002217 };
2218 static hda_nid_t idx_to_dac_rev2[8] = {
2219 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002220 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002221 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002222 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002223 return idx_to_dac_rev2[idx];
2224 else
2225 return idx_to_dac[idx];
2226}
2227
2228static hda_nid_t ad1988_boost_nids[8] = {
2229 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2230};
2231
2232static int ad1988_pin_idx(hda_nid_t nid)
2233{
2234 static hda_nid_t ad1988_io_pins[8] = {
2235 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2236 };
2237 int i;
2238 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2239 if (ad1988_io_pins[i] == nid)
2240 return i;
2241 return 0; /* should be -1 */
2242}
2243
2244static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2245{
2246 static int loopback_idx[8] = {
2247 2, 0, 1, 3, 4, 5, 1, 4
2248 };
2249 switch (nid) {
2250 case AD1988_PIN_CD_NID:
2251 return 6;
2252 default:
2253 return loopback_idx[ad1988_pin_idx(nid)];
2254 }
2255}
2256
2257static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2258{
2259 static int adc_idx[8] = {
2260 0, 1, 2, 8, 4, 3, 6, 7
2261 };
2262 switch (nid) {
2263 case AD1988_PIN_CD_NID:
2264 return 5;
2265 default:
2266 return adc_idx[ad1988_pin_idx(nid)];
2267 }
2268}
2269
2270/* fill in the dac_nids table from the parsed pin configuration */
2271static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2272 const struct auto_pin_cfg *cfg)
2273{
2274 struct ad198x_spec *spec = codec->spec;
2275 int i, idx;
2276
2277 spec->multiout.dac_nids = spec->private_dac_nids;
2278
2279 /* check the pins hardwired to audio widget */
2280 for (i = 0; i < cfg->line_outs; i++) {
2281 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2282 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2283 }
2284 spec->multiout.num_dacs = cfg->line_outs;
2285 return 0;
2286}
2287
2288/* add playback controls from the parsed DAC table */
2289static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2290 const struct auto_pin_cfg *cfg)
2291{
2292 char name[32];
2293 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2294 hda_nid_t nid;
2295 int i, err;
2296
2297 for (i = 0; i < cfg->line_outs; i++) {
2298 hda_nid_t dac = spec->multiout.dac_nids[i];
2299 if (! dac)
2300 continue;
2301 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2302 if (i == 2) {
2303 /* Center/LFE */
2304 err = add_control(spec, AD_CTL_WIDGET_VOL,
2305 "Center Playback Volume",
2306 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2307 if (err < 0)
2308 return err;
2309 err = add_control(spec, AD_CTL_WIDGET_VOL,
2310 "LFE Playback Volume",
2311 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2312 if (err < 0)
2313 return err;
2314 err = add_control(spec, AD_CTL_BIND_MUTE,
2315 "Center Playback Switch",
2316 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2317 if (err < 0)
2318 return err;
2319 err = add_control(spec, AD_CTL_BIND_MUTE,
2320 "LFE Playback Switch",
2321 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2322 if (err < 0)
2323 return err;
2324 } else {
2325 sprintf(name, "%s Playback Volume", chname[i]);
2326 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2327 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2328 if (err < 0)
2329 return err;
2330 sprintf(name, "%s Playback Switch", chname[i]);
2331 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2332 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2333 if (err < 0)
2334 return err;
2335 }
2336 }
2337 return 0;
2338}
2339
2340/* add playback controls for speaker and HP outputs */
2341static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2342 const char *pfx)
2343{
2344 struct ad198x_spec *spec = codec->spec;
2345 hda_nid_t nid;
2346 int idx, err;
2347 char name[32];
2348
2349 if (! pin)
2350 return 0;
2351
2352 idx = ad1988_pin_idx(pin);
2353 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002354 /* specify the DAC as the extra output */
2355 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002356 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002357 else
2358 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002359 /* control HP volume/switch on the output mixer amp */
2360 sprintf(name, "%s Playback Volume", pfx);
2361 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2362 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2363 return err;
2364 nid = ad1988_mixer_nids[idx];
2365 sprintf(name, "%s Playback Switch", pfx);
2366 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2367 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2368 return err;
2369 return 0;
2370}
2371
2372/* create input playback/capture controls for the given pin */
2373static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2374 const char *ctlname, int boost)
2375{
2376 char name[32];
2377 int err, idx;
2378
2379 sprintf(name, "%s Playback Volume", ctlname);
2380 idx = ad1988_pin_to_loopback_idx(pin);
2381 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2382 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2383 return err;
2384 sprintf(name, "%s Playback Switch", ctlname);
2385 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2386 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2387 return err;
2388 if (boost) {
2389 hda_nid_t bnid;
2390 idx = ad1988_pin_idx(pin);
2391 bnid = ad1988_boost_nids[idx];
2392 if (bnid) {
2393 sprintf(name, "%s Boost", ctlname);
2394 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2395 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2396
2397 }
2398 }
2399 return 0;
2400}
2401
2402/* create playback/capture controls for input pins */
2403static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2404 const struct auto_pin_cfg *cfg)
2405{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002406 struct hda_input_mux *imux = &spec->private_imux;
2407 int i, err;
2408
2409 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002410 err = new_analog_input(spec, cfg->input_pins[i],
2411 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002412 i <= AUTO_PIN_FRONT_MIC);
2413 if (err < 0)
2414 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002415 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002416 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2417 imux->num_items++;
2418 }
2419 imux->items[imux->num_items].label = "Mix";
2420 imux->items[imux->num_items].index = 9;
2421 imux->num_items++;
2422
2423 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2424 "Analog Mix Playback Volume",
2425 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2426 return err;
2427 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2428 "Analog Mix Playback Switch",
2429 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2430 return err;
2431
2432 return 0;
2433}
2434
2435static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2436 hda_nid_t nid, int pin_type,
2437 int dac_idx)
2438{
2439 /* set as output */
2440 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2441 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2442 switch (nid) {
2443 case 0x11: /* port-A - DAC 04 */
2444 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2445 break;
2446 case 0x14: /* port-B - DAC 06 */
2447 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2448 break;
2449 case 0x15: /* port-C - DAC 05 */
2450 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2451 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002452 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002453 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2454 break;
2455 case 0x13: /* mono - DAC 04 */
2456 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2457 break;
2458 }
2459}
2460
2461static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2462{
2463 struct ad198x_spec *spec = codec->spec;
2464 int i;
2465
2466 for (i = 0; i < spec->autocfg.line_outs; i++) {
2467 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2468 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2469 }
2470}
2471
2472static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2473{
2474 struct ad198x_spec *spec = codec->spec;
2475 hda_nid_t pin;
2476
Takashi Iwai82bc9552006-03-21 11:24:42 +01002477 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002478 if (pin) /* connect to front */
2479 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002480 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002481 if (pin) /* connect to front */
2482 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2483}
2484
2485static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2486{
2487 struct ad198x_spec *spec = codec->spec;
2488 int i, idx;
2489
2490 for (i = 0; i < AUTO_PIN_LAST; i++) {
2491 hda_nid_t nid = spec->autocfg.input_pins[i];
2492 if (! nid)
2493 continue;
2494 switch (nid) {
2495 case 0x15: /* port-C */
2496 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2497 break;
2498 case 0x17: /* port-E */
2499 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2500 break;
2501 }
2502 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2503 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2504 if (nid != AD1988_PIN_CD_NID)
2505 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2506 AMP_OUT_MUTE);
2507 idx = ad1988_pin_idx(nid);
2508 if (ad1988_boost_nids[idx])
2509 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2510 AC_VERB_SET_AMP_GAIN_MUTE,
2511 AMP_OUT_ZERO);
2512 }
2513}
2514
2515/* parse the BIOS configuration and set up the alc_spec */
2516/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2517static int ad1988_parse_auto_config(struct hda_codec *codec)
2518{
2519 struct ad198x_spec *spec = codec->spec;
2520 int err;
2521
Kailang Yangdf694da2005-12-05 19:42:22 +01002522 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002523 return err;
2524 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2525 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002526 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002527 return 0; /* can't find valid BIOS pin config */
2528 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002529 (err = ad1988_auto_create_extra_out(codec,
2530 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002531 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002532 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002533 "Headphone")) < 0 ||
2534 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2535 return err;
2536
2537 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2538
2539 if (spec->autocfg.dig_out_pin)
2540 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2541 if (spec->autocfg.dig_in_pin)
2542 spec->dig_in_nid = AD1988_SPDIF_IN;
2543
2544 if (spec->kctl_alloc)
2545 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2546
2547 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2548
2549 spec->input_mux = &spec->private_imux;
2550
2551 return 1;
2552}
2553
2554/* init callback for auto-configuration model -- overriding the default init */
2555static int ad1988_auto_init(struct hda_codec *codec)
2556{
2557 ad198x_init(codec);
2558 ad1988_auto_init_multi_out(codec);
2559 ad1988_auto_init_extra_out(codec);
2560 ad1988_auto_init_analog_input(codec);
2561 return 0;
2562}
2563
2564
2565/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002566 */
2567
2568static struct hda_board_config ad1988_cfg_tbl[] = {
2569 { .modelname = "6stack", .config = AD1988_6STACK },
2570 { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
2571 { .modelname = "3stack", .config = AD1988_3STACK },
2572 { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
2573 { .modelname = "laptop", .config = AD1988_LAPTOP },
2574 { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002575 { .modelname = "auto", .config = AD1988_AUTO },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002576 {}
2577};
2578
2579static int patch_ad1988(struct hda_codec *codec)
2580{
2581 struct ad198x_spec *spec;
2582 int board_config;
2583
2584 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2585 if (spec == NULL)
2586 return -ENOMEM;
2587
Ingo Molnar62932df2006-01-16 16:34:20 +01002588 mutex_init(&spec->amp_mutex);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002589 codec->spec = spec;
2590
Takashi Iwai1a806f42006-07-03 15:58:16 +02002591 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002592 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2593
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002594 board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2595 if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002596 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2597 board_config = AD1988_AUTO;
2598 }
2599
2600 if (board_config == AD1988_AUTO) {
2601 /* automatic parse from the BIOS config */
2602 int err = ad1988_parse_auto_config(codec);
2603 if (err < 0) {
2604 ad198x_free(codec);
2605 return err;
2606 } else if (! err) {
2607 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2608 board_config = AD1988_6STACK;
2609 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002610 }
2611
2612 switch (board_config) {
2613 case AD1988_6STACK:
2614 case AD1988_6STACK_DIG:
2615 spec->multiout.max_channels = 8;
2616 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002617 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002618 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2619 else
2620 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002621 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002622 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002623 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002624 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2625 else
2626 spec->mixers[0] = ad1988_6stack_mixers1;
2627 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002628 spec->num_init_verbs = 1;
2629 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2630 if (board_config == AD1988_6STACK_DIG) {
2631 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2632 spec->dig_in_nid = AD1988_SPDIF_IN;
2633 }
2634 break;
2635 case AD1988_3STACK:
2636 case AD1988_3STACK_DIG:
2637 spec->multiout.max_channels = 6;
2638 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002639 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002640 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2641 else
2642 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002643 spec->input_mux = &ad1988_6stack_capture_source;
2644 spec->channel_mode = ad1988_3stack_modes;
2645 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002646 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002647 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002648 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2649 else
2650 spec->mixers[0] = ad1988_3stack_mixers1;
2651 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002652 spec->num_init_verbs = 1;
2653 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2654 if (board_config == AD1988_3STACK_DIG)
2655 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2656 break;
2657 case AD1988_LAPTOP:
2658 case AD1988_LAPTOP_DIG:
2659 spec->multiout.max_channels = 2;
2660 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002661 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002662 spec->input_mux = &ad1988_laptop_capture_source;
2663 spec->num_mixers = 1;
2664 spec->mixers[0] = ad1988_laptop_mixers;
2665 spec->num_init_verbs = 1;
2666 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2667 if (board_config == AD1988_LAPTOP_DIG)
2668 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2669 break;
2670 }
2671
Takashi Iwaid32410b12005-11-24 16:06:23 +01002672 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2673 spec->adc_nids = ad1988_adc_nids;
2674 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002675 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2676 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2677 if (spec->multiout.dig_out_nid) {
2678 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2679 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2680 }
2681 if (spec->dig_in_nid)
2682 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2683
2684 codec->patch_ops = ad198x_patch_ops;
2685 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002686 case AD1988_AUTO:
2687 codec->patch_ops.init = ad1988_auto_init;
2688 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002689 case AD1988_LAPTOP:
2690 case AD1988_LAPTOP_DIG:
2691 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2692 break;
2693 }
2694
2695 return 0;
2696}
2697
2698
2699/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 * patch entries
2701 */
2702struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002703 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2704 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002706 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02002707 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 {} /* terminator */
2709};