blob: 54506d4e57d5773765e99b238224dc8dcdba5319 [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
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200455static int ad1986a_pcm_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
456 unsigned int size, unsigned int __user *_tlv)
457{
458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459 struct ad198x_spec *ad = codec->spec;
460
461 mutex_lock(&ad->amp_mutex);
462 snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, _tlv);
463 mutex_unlock(&ad->amp_mutex);
464 return 0;
465}
466
467
Takashi Iwaiead9b7c2005-06-08 14:48:19 +0200468#define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100470static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200473 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Ingo Molnar62932df2006-01-16 16:34:20 +0100475 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100477 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return 0;
479}
480
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100481static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200484 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 int i, change = 0;
486
Ingo Molnar62932df2006-01-16 16:34:20 +0100487 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
489 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
490 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
491 }
492 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100493 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 return change;
495}
496
497/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 * mixers
499 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100500static struct snd_kcontrol_new ad1986a_mixers[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 {
502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
503 .name = "PCM Playback Volume",
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200504 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
505 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
506 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .info = ad1986a_pcm_amp_vol_info,
508 .get = ad1986a_pcm_amp_vol_get,
509 .put = ad1986a_pcm_amp_vol_put,
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200510 .tlv.c = ad1986a_pcm_amp_tlv,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
512 },
513 {
514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
515 .name = "PCM Playback Switch",
516 .info = ad1986a_pcm_amp_sw_info,
517 .get = ad1986a_pcm_amp_sw_get,
518 .put = ad1986a_pcm_amp_sw_put,
519 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
520 },
521 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
522 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
523 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
524 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
525 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
528 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
535 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
536 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
537 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
538 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
539 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
540 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
541 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
542 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
543 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
544 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
545 {
546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
547 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200548 .info = ad198x_mux_enum_info,
549 .get = ad198x_mux_enum_get,
550 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
553 { } /* end */
554};
555
Takashi Iwai9230d212006-03-13 13:49:49 +0100556/* additional mixers for 3stack mode */
557static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
558 {
559 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
560 .name = "Channel Mode",
561 .info = ad198x_ch_mode_info,
562 .get = ad198x_ch_mode_get,
563 .put = ad198x_ch_mode_put,
564 },
565 { } /* end */
566};
567
568/* laptop model - 2ch only */
569static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
570
571static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
572 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
574 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
575 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
576 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
578 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
580 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
581 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
582 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
583 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
584 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
585 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
586 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
587 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
588 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
589 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
590 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
591 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
592 {
593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
594 .name = "Capture Source",
595 .info = ad198x_mux_enum_info,
596 .get = ad198x_mux_enum_get,
597 .put = ad198x_mux_enum_put,
598 },
599 { } /* end */
600};
601
Takashi Iwai825aa972006-03-17 10:50:49 +0100602/* laptop-eapd model - 2ch only */
603
604/* master controls both pins 0x1a and 0x1b */
605static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_value *ucontrol)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 long *valp = ucontrol->value.integer.value;
610 int change;
611
612 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
613 0x7f, valp[0] & 0x7f);
614 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
615 0x7f, valp[1] & 0x7f);
616 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
617 0x7f, valp[0] & 0x7f);
618 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
619 0x7f, valp[1] & 0x7f);
620 return change;
621}
622
623static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 long *valp = ucontrol->value.integer.value;
628 int change;
629
630 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
631 0x80, valp[0] ? 0 : 0x80);
632 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
633 0x80, valp[1] ? 0 : 0x80);
634 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
635 0x80, valp[0] ? 0 : 0x80);
636 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
637 0x80, valp[1] ? 0 : 0x80);
638 return change;
639}
640
641static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
642 .num_items = 3,
643 .items = {
644 { "Mic", 0x0 },
645 { "Internal Mic", 0x4 },
646 { "Mix", 0x5 },
647 },
648};
649
650static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
651 {
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
653 .name = "Master Playback Volume",
654 .info = snd_hda_mixer_amp_volume_info,
655 .get = snd_hda_mixer_amp_volume_get,
656 .put = ad1986a_laptop_master_vol_put,
657 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
658 },
659 {
660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
661 .name = "Master Playback Switch",
662 .info = snd_hda_mixer_amp_switch_info,
663 .get = snd_hda_mixer_amp_switch_get,
664 .put = ad1986a_laptop_master_sw_put,
665 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
666 },
667 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
668 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
669 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
670 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
671 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
672 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
673 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
674 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
675 {
676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
677 .name = "Capture Source",
678 .info = ad198x_mux_enum_info,
679 .get = ad198x_mux_enum_get,
680 .put = ad198x_mux_enum_put,
681 },
682 {
683 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
684 .name = "External Amplifier",
685 .info = ad198x_eapd_info,
686 .get = ad198x_eapd_get,
687 .put = ad198x_eapd_put,
688 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
689 },
690 { } /* end */
691};
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693/*
694 * initialization verbs
695 */
696static struct hda_verb ad1986a_init_verbs[] = {
697 /* Front, Surround, CLFE DAC; mute as default */
698 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
699 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
700 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
701 /* Downmix - off */
702 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
703 /* HP, Line-Out, Surround, CLFE selectors */
704 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
705 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
706 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
707 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
708 /* Mono selector */
709 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
710 /* Mic selector: Mic 1/2 pin */
711 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
712 /* Line-in selector: Line-in */
713 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
714 /* Mic 1/2 swap */
715 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
716 /* Record selector: mic */
717 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
718 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
719 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
720 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724 /* PC beep */
725 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
726 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
727 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
728 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
729 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
730 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
731 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200732 /* HP Pin */
733 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
734 /* Front, Surround, CLFE Pins */
735 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
736 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
737 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
738 /* Mono Pin */
739 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
740 /* Mic Pin */
741 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
742 /* Line, Aux, CD, Beep-In Pin */
743 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
744 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
745 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
746 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
747 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 { } /* end */
749};
750
Takashi Iwai9230d212006-03-13 13:49:49 +0100751/* additional verbs for 3-stack model */
752static struct hda_verb ad1986a_3st_init_verbs[] = {
753 /* Mic and line-in selectors */
754 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
755 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
756 { } /* end */
757};
758
759static struct hda_verb ad1986a_ch2_init[] = {
760 /* Surround out -> Line In */
761 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
762 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
763 /* CLFE -> Mic in */
764 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
765 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
766 { } /* end */
767};
768
769static struct hda_verb ad1986a_ch4_init[] = {
770 /* Surround out -> Surround */
771 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
772 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
773 /* CLFE -> Mic in */
774 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
775 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
776 { } /* end */
777};
778
779static struct hda_verb ad1986a_ch6_init[] = {
780 /* Surround out -> Surround out */
781 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
782 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
783 /* CLFE -> CLFE */
784 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
785 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
786 { } /* end */
787};
788
789static struct hda_channel_mode ad1986a_modes[3] = {
790 { 2, ad1986a_ch2_init },
791 { 4, ad1986a_ch4_init },
792 { 6, ad1986a_ch6_init },
793};
794
Takashi Iwai825aa972006-03-17 10:50:49 +0100795/* eapd initialization */
796static struct hda_verb ad1986a_eapd_init_verbs[] = {
797 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00},
798 {}
799};
800
Takashi Iwai9230d212006-03-13 13:49:49 +0100801/* models */
Takashi Iwai825aa972006-03-17 10:50:49 +0100802enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP, AD1986A_LAPTOP_EAPD };
Takashi Iwai9230d212006-03-13 13:49:49 +0100803
804static struct hda_board_config ad1986a_cfg_tbl[] = {
805 { .modelname = "6stack", .config = AD1986A_6STACK },
806 { .modelname = "3stack", .config = AD1986A_3STACK },
Takashi Iwai82bc9552006-03-21 11:24:42 +0100807 { .pci_subvendor = 0x10de, .pci_subdevice = 0xcb84,
808 .config = AD1986A_3STACK }, /* ASUS A8N-VM CSM */
Takashi Iwai41f0cd32006-06-21 12:14:40 +0200809 { .pci_subvendor = 0x1043, .pci_subdevice = 0x81b3,
810 .config = AD1986A_3STACK }, /* ASUS P5RD2-VM / P5GPL-X SE */
Takashi Iwai9230d212006-03-13 13:49:49 +0100811 { .modelname = "laptop", .config = AD1986A_LAPTOP },
812 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
813 .config = AD1986A_LAPTOP }, /* FSC V2060 */
814 { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
815 .config = AD1986A_LAPTOP }, /* Samsung M50 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100816 { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
817 .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
818 { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD },
Takashi Iwaib2e1b0c2006-06-27 12:48:59 +0200819 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc023,
820 .config = AD1986A_LAPTOP_EAPD }, /* Samsung X60 Chane */
Takashi Iwai825aa972006-03-17 10:50:49 +0100821 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
822 .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
Takashi Iwai61a74542006-04-20 16:42:34 +0200823 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1153,
824 .config = AD1986A_LAPTOP_EAPD }, /* ASUS M9 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100825 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
826 .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
Takashi Iwaie0922282006-04-10 19:09:01 +0200827 { .pci_subvendor = 0x1043, .pci_subdevice = 0x11f7,
828 .config = AD1986A_LAPTOP_EAPD }, /* ASUS U5A */
Takashi Iwaie0292bd2006-04-26 17:44:18 +0200829 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1297,
830 .config = AD1986A_LAPTOP_EAPD }, /* ASUS Z62F */
Coywolf Qi Huntbe28e7c2006-04-10 10:47:11 +0200831 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30af,
832 .config = AD1986A_LAPTOP_EAPD }, /* HP Compaq Presario B2800 */
Daniel T Chen6dac9a62006-06-21 08:51:07 +0200833 { .pci_subvendor = 0x17aa, .pci_subdevice = 0x2066,
834 .config = AD1986A_LAPTOP_EAPD }, /* Lenovo 3000 N100-07684JU */
Takashi Iwai9230d212006-03-13 13:49:49 +0100835 {}
836};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838static int patch_ad1986a(struct hda_codec *codec)
839{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200840 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100841 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200843 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 if (spec == NULL)
845 return -ENOMEM;
846
Ingo Molnar62932df2006-01-16 16:34:20 +0100847 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 codec->spec = spec;
849
850 spec->multiout.max_channels = 6;
851 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
852 spec->multiout.dac_nids = ad1986a_dac_nids;
853 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100854 spec->num_adc_nids = 1;
855 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100856 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200857 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100858 spec->num_mixers = 1;
859 spec->mixers[0] = ad1986a_mixers;
860 spec->num_init_verbs = 1;
861 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200863 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Takashi Iwai9230d212006-03-13 13:49:49 +0100865 /* override some parameters */
866 board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
867 switch (board_config) {
868 case AD1986A_3STACK:
869 spec->num_mixers = 2;
870 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200871 spec->num_init_verbs = 3;
Takashi Iwai9230d212006-03-13 13:49:49 +0100872 spec->init_verbs[1] = ad1986a_3st_init_verbs;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200873 spec->init_verbs[2] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100874 spec->channel_mode = ad1986a_modes;
875 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200876 spec->need_dac_fix = 1;
877 spec->multiout.max_channels = 2;
878 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100879 break;
880 case AD1986A_LAPTOP:
881 spec->mixers[0] = ad1986a_laptop_mixers;
882 spec->multiout.max_channels = 2;
883 spec->multiout.num_dacs = 1;
884 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
885 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100886 case AD1986A_LAPTOP_EAPD:
887 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
888 spec->num_init_verbs = 2;
889 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
890 spec->multiout.max_channels = 2;
891 spec->multiout.num_dacs = 1;
892 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
893 spec->multiout.dig_out_nid = 0;
894 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
895 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100896 }
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return 0;
899}
900
901/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200902 * AD1983 specific
903 */
904
905#define AD1983_SPDIF_OUT 0x02
906#define AD1983_DAC 0x03
907#define AD1983_ADC 0x04
908
909static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100910static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100911static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200912
913static struct hda_input_mux ad1983_capture_source = {
914 .num_items = 4,
915 .items = {
916 { "Mic", 0x0 },
917 { "Line", 0x1 },
918 { "Mix", 0x2 },
919 { "Mix Mono", 0x3 },
920 },
921};
922
923/*
924 * SPDIF playback route
925 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100926static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200927{
928 static char *texts[] = { "PCM", "ADC" };
929
930 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
931 uinfo->count = 1;
932 uinfo->value.enumerated.items = 2;
933 if (uinfo->value.enumerated.item > 1)
934 uinfo->value.enumerated.item = 1;
935 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
936 return 0;
937}
938
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100939static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200940{
941 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942 struct ad198x_spec *spec = codec->spec;
943
944 ucontrol->value.enumerated.item[0] = spec->spdif_route;
945 return 0;
946}
947
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100948static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200949{
950 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
951 struct ad198x_spec *spec = codec->spec;
952
953 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
954 spec->spdif_route = ucontrol->value.enumerated.item[0];
955 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
956 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
957 return 1;
958 }
959 return 0;
960}
961
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100962static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200963 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
964 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
965 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
966 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
967 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
968 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
969 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
970 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
971 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
972 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
973 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
974 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
975 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
976 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
977 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
978 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
979 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
980 {
981 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
982 .name = "Capture Source",
983 .info = ad198x_mux_enum_info,
984 .get = ad198x_mux_enum_get,
985 .put = ad198x_mux_enum_put,
986 },
987 {
988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +0200989 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200990 .info = ad1983_spdif_route_info,
991 .get = ad1983_spdif_route_get,
992 .put = ad1983_spdif_route_put,
993 },
994 { } /* end */
995};
996
997static struct hda_verb ad1983_init_verbs[] = {
998 /* Front, HP, Mono; mute as default */
999 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1000 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1001 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1002 /* Beep, PCM, Mic, Line-In: mute */
1003 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1004 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1005 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1006 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1007 /* Front, HP selectors; from Mix */
1008 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1009 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1010 /* Mono selector; from Mix */
1011 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1012 /* Mic selector; Mic */
1013 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1014 /* Line-in selector: Line-in */
1015 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1016 /* Mic boost: 0dB */
1017 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1018 /* Record selector: mic */
1019 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1020 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1021 /* SPDIF route: PCM */
1022 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1023 /* Front Pin */
1024 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1025 /* HP Pin */
1026 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1027 /* Mono Pin */
1028 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1029 /* Mic Pin */
1030 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1031 /* Line Pin */
1032 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1033 { } /* end */
1034};
1035
Takashi Iwai985be542005-11-02 18:26:49 +01001036
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001037static int patch_ad1983(struct hda_codec *codec)
1038{
1039 struct ad198x_spec *spec;
1040
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001041 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001042 if (spec == NULL)
1043 return -ENOMEM;
1044
Ingo Molnar62932df2006-01-16 16:34:20 +01001045 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001046 codec->spec = spec;
1047
1048 spec->multiout.max_channels = 2;
1049 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1050 spec->multiout.dac_nids = ad1983_dac_nids;
1051 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001052 spec->num_adc_nids = 1;
1053 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001054 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001055 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001056 spec->num_mixers = 1;
1057 spec->mixers[0] = ad1983_mixers;
1058 spec->num_init_verbs = 1;
1059 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001060 spec->spdif_route = 0;
1061
1062 codec->patch_ops = ad198x_patch_ops;
1063
1064 return 0;
1065}
1066
1067
1068/*
1069 * AD1981 HD specific
1070 */
1071
1072#define AD1981_SPDIF_OUT 0x02
1073#define AD1981_DAC 0x03
1074#define AD1981_ADC 0x04
1075
1076static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001077static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001078static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001079
1080/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1081static struct hda_input_mux ad1981_capture_source = {
1082 .num_items = 7,
1083 .items = {
1084 { "Front Mic", 0x0 },
1085 { "Line", 0x1 },
1086 { "Mix", 0x2 },
1087 { "Mix Mono", 0x3 },
1088 { "CD", 0x4 },
1089 { "Mic", 0x6 },
1090 { "Aux", 0x7 },
1091 },
1092};
1093
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001094static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001095 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1096 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1097 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1098 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1100 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1103 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1104 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1105 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1106 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1107 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1108 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1109 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1110 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1111 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1112 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1113 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1114 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1115 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1116 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1117 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1118 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1119 {
1120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1121 .name = "Capture Source",
1122 .info = ad198x_mux_enum_info,
1123 .get = ad198x_mux_enum_get,
1124 .put = ad198x_mux_enum_put,
1125 },
1126 /* identical with AD1983 */
1127 {
1128 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001129 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001130 .info = ad1983_spdif_route_info,
1131 .get = ad1983_spdif_route_get,
1132 .put = ad1983_spdif_route_put,
1133 },
1134 { } /* end */
1135};
1136
1137static struct hda_verb ad1981_init_verbs[] = {
1138 /* Front, HP, Mono; mute as default */
1139 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1140 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1141 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1142 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1143 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1144 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1145 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1146 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1147 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1148 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1149 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1150 /* Front, HP selectors; from Mix */
1151 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1152 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1153 /* Mono selector; from Mix */
1154 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1155 /* Mic Mixer; select Front Mic */
1156 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1157 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1158 /* Mic boost: 0dB */
1159 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1160 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1161 /* Record selector: Front mic */
1162 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1163 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1164 /* SPDIF route: PCM */
1165 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1166 /* Front Pin */
1167 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1168 /* HP Pin */
1169 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1170 /* Mono Pin */
1171 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1172 /* Front & Rear Mic Pins */
1173 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1174 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1175 /* Line Pin */
1176 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1177 /* Digital Beep */
1178 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1179 /* Line-Out as Input: disabled */
1180 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1181 { } /* end */
1182};
1183
Takashi Iwai18a815d2006-03-01 19:54:39 +01001184/*
1185 * Patch for HP nx6320
1186 *
1187 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
1188 * speaker output enabled _and_ mute-LED off.
1189 */
1190
1191#define AD1981_HP_EVENT 0x37
1192#define AD1981_MIC_EVENT 0x38
1193
1194static struct hda_verb ad1981_hp_init_verbs[] = {
1195 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1196 /* pin sensing on HP and Mic jacks */
1197 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1198 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1199 {}
1200};
1201
1202/* turn on/off EAPD (+ mute HP) as a master switch */
1203static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1204 struct snd_ctl_elem_value *ucontrol)
1205{
1206 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1207 struct ad198x_spec *spec = codec->spec;
1208
1209 if (! ad198x_eapd_put(kcontrol, ucontrol))
1210 return 0;
1211
1212 /* toggle HP mute appropriately */
1213 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1214 0x80, spec->cur_eapd ? 0 : 0x80);
1215 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1216 0x80, spec->cur_eapd ? 0 : 0x80);
1217 return 1;
1218}
1219
1220/* bind volumes of both NID 0x05 and 0x06 */
1221static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1222 struct snd_ctl_elem_value *ucontrol)
1223{
1224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1225 long *valp = ucontrol->value.integer.value;
1226 int change;
1227
1228 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1229 0x7f, valp[0] & 0x7f);
1230 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1231 0x7f, valp[1] & 0x7f);
1232 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1233 0x7f, valp[0] & 0x7f);
1234 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1235 0x7f, valp[1] & 0x7f);
1236 return change;
1237}
1238
1239/* mute internal speaker if HP is plugged */
1240static void ad1981_hp_automute(struct hda_codec *codec)
1241{
1242 unsigned int present;
1243
1244 present = snd_hda_codec_read(codec, 0x06, 0,
1245 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1246 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1247 0x80, present ? 0x80 : 0);
1248 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1249 0x80, present ? 0x80 : 0);
1250}
1251
1252/* toggle input of built-in and mic jack appropriately */
1253static void ad1981_hp_automic(struct hda_codec *codec)
1254{
1255 static struct hda_verb mic_jack_on[] = {
1256 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1257 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1258 {}
1259 };
1260 static struct hda_verb mic_jack_off[] = {
1261 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1262 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1263 {}
1264 };
1265 unsigned int present;
1266
1267 present = snd_hda_codec_read(codec, 0x08, 0,
1268 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1269 if (present)
1270 snd_hda_sequence_write(codec, mic_jack_on);
1271 else
1272 snd_hda_sequence_write(codec, mic_jack_off);
1273}
1274
1275/* unsolicited event for HP jack sensing */
1276static void ad1981_hp_unsol_event(struct hda_codec *codec,
1277 unsigned int res)
1278{
1279 res >>= 26;
1280 switch (res) {
1281 case AD1981_HP_EVENT:
1282 ad1981_hp_automute(codec);
1283 break;
1284 case AD1981_MIC_EVENT:
1285 ad1981_hp_automic(codec);
1286 break;
1287 }
1288}
1289
1290static struct hda_input_mux ad1981_hp_capture_source = {
1291 .num_items = 3,
1292 .items = {
1293 { "Mic", 0x0 },
1294 { "Docking-Station", 0x1 },
1295 { "Mix", 0x2 },
1296 },
1297};
1298
1299static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1300 {
1301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1302 .name = "Master Playback Volume",
1303 .info = snd_hda_mixer_amp_volume_info,
1304 .get = snd_hda_mixer_amp_volume_get,
1305 .put = ad1981_hp_master_vol_put,
1306 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1307 },
1308 {
1309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1310 .name = "Master Playback Switch",
1311 .info = ad198x_eapd_info,
1312 .get = ad198x_eapd_get,
1313 .put = ad1981_hp_master_sw_put,
1314 .private_value = 0x05,
1315 },
1316 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1317 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1318#if 0
1319 /* FIXME: analog mic/line loopback doesn't work with my tests...
1320 * (although recording is OK)
1321 */
1322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1324 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1325 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1326 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1327 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1328 /* FIXME: does this laptop have analog CD connection? */
1329 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1330 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1331#endif
1332 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1333 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1334 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1335 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1336 {
1337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1338 .name = "Capture Source",
1339 .info = ad198x_mux_enum_info,
1340 .get = ad198x_mux_enum_get,
1341 .put = ad198x_mux_enum_put,
1342 },
1343 { } /* end */
1344};
1345
1346/* initialize jack-sensing, too */
1347static int ad1981_hp_init(struct hda_codec *codec)
1348{
1349 ad198x_init(codec);
1350 ad1981_hp_automute(codec);
1351 ad1981_hp_automic(codec);
1352 return 0;
1353}
1354
Takashi Iwai01686c52006-04-18 12:54:11 +02001355/* configuration for Lenovo Thinkpad T60 */
1356static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1357 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1361 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1364 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1365 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1366 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1367 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1368 {
1369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1370 .name = "Capture Source",
1371 .info = ad198x_mux_enum_info,
1372 .get = ad198x_mux_enum_get,
1373 .put = ad198x_mux_enum_put,
1374 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001375 /* identical with AD1983 */
1376 {
1377 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1378 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1379 .info = ad1983_spdif_route_info,
1380 .get = ad1983_spdif_route_get,
1381 .put = ad1983_spdif_route_put,
1382 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001383 { } /* end */
1384};
1385
1386static struct hda_input_mux ad1981_thinkpad_capture_source = {
1387 .num_items = 3,
1388 .items = {
1389 { "Mic", 0x0 },
1390 { "Mix", 0x2 },
1391 { "CD", 0x4 },
1392 },
1393};
1394
Takashi Iwai18a815d2006-03-01 19:54:39 +01001395/* models */
Takashi Iwai01686c52006-04-18 12:54:11 +02001396enum { AD1981_BASIC, AD1981_HP, AD1981_THINKPAD };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001397
1398static struct hda_board_config ad1981_cfg_tbl[] = {
1399 { .modelname = "hp", .config = AD1981_HP },
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001400 /* All HP models */
1401 { .pci_subvendor = 0x103c, .config = AD1981_HP },
Takashi Iwaif8e9f342006-06-01 21:08:53 +02001402 { .pci_subvendor = 0x30b0, .pci_subdevice = 0x103c,
1403 .config = AD1981_HP }, /* HP nx6320 (reversed SSID, H/W bug) */
Takashi Iwai01686c52006-04-18 12:54:11 +02001404 { .modelname = "thinkpad", .config = AD1981_THINKPAD },
1405 /* Lenovo Thinkpad T60/X60/Z6xx */
1406 { .pci_subvendor = 0x17aa, .config = AD1981_THINKPAD },
Takashi Iwai887709b2006-04-18 13:27:31 +02001407 { .pci_subvendor = 0x1014, .pci_subdevice = 0x0597,
Takashi Iwai01686c52006-04-18 12:54:11 +02001408 .config = AD1981_THINKPAD }, /* Z60m/t */
Takashi Iwai18a815d2006-03-01 19:54:39 +01001409 { .modelname = "basic", .config = AD1981_BASIC },
1410 {}
1411};
1412
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001413static int patch_ad1981(struct hda_codec *codec)
1414{
1415 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001416 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001417
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001418 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001419 if (spec == NULL)
1420 return -ENOMEM;
1421
Ingo Molnar62932df2006-01-16 16:34:20 +01001422 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001423 codec->spec = spec;
1424
1425 spec->multiout.max_channels = 2;
1426 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1427 spec->multiout.dac_nids = ad1981_dac_nids;
1428 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001429 spec->num_adc_nids = 1;
1430 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001431 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001432 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001433 spec->num_mixers = 1;
1434 spec->mixers[0] = ad1981_mixers;
1435 spec->num_init_verbs = 1;
1436 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001437 spec->spdif_route = 0;
1438
1439 codec->patch_ops = ad198x_patch_ops;
1440
Takashi Iwai18a815d2006-03-01 19:54:39 +01001441 /* override some parameters */
1442 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1443 switch (board_config) {
1444 case AD1981_HP:
1445 spec->mixers[0] = ad1981_hp_mixers;
1446 spec->num_init_verbs = 2;
1447 spec->init_verbs[1] = ad1981_hp_init_verbs;
1448 spec->multiout.dig_out_nid = 0;
1449 spec->input_mux = &ad1981_hp_capture_source;
1450
1451 codec->patch_ops.init = ad1981_hp_init;
1452 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1453 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001454 case AD1981_THINKPAD:
1455 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001456 spec->input_mux = &ad1981_thinkpad_capture_source;
1457 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001458 }
1459
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001460 return 0;
1461}
1462
1463
1464/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001465 * AD1988
1466 *
1467 * Output pins and routes
1468 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001469 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001470 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1471 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1472 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1473 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1474 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1475 * port-F 0x16 (mute) <- 0x2a <- 06
1476 * port-G 0x24 (mute) <- 0x27 <- 05
1477 * port-H 0x25 (mute) <- 0x28 <- 0a
1478 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1479 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001480 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1481 * (*) 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 +01001482 *
1483 * Input pins and routes
1484 *
1485 * pin boost mix input # / adc input #
1486 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1487 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1488 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1489 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1490 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1491 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1492 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1493 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1494 *
1495 *
1496 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001497 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001498 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001499 *
1500 * Inputs of Analog Mix (0x20)
1501 * 0:Port-B (front mic)
1502 * 1:Port-C/G/H (line-in)
1503 * 2:Port-A
1504 * 3:Port-D (line-in/2)
1505 * 4:Port-E/G/H (mic-in)
1506 * 5:Port-F (mic2-in)
1507 * 6:CD
1508 * 7:Beep
1509 *
1510 * ADC selection
1511 * 0:Port-A
1512 * 1:Port-B (front mic-in)
1513 * 2:Port-C (line-in)
1514 * 3:Port-F (mic2-in)
1515 * 4:Port-E (mic-in)
1516 * 5:CD
1517 * 6:Port-G
1518 * 7:Port-H
1519 * 8:Port-D (line-in/2)
1520 * 9:Mix
1521 *
1522 * Proposed pin assignments by the datasheet
1523 *
1524 * 6-stack
1525 * Port-A front headphone
1526 * B front mic-in
1527 * C rear line-in
1528 * D rear front-out
1529 * E rear mic-in
1530 * F rear surround
1531 * G rear CLFE
1532 * H rear side
1533 *
1534 * 3-stack
1535 * Port-A front headphone
1536 * B front mic
1537 * C rear line-in/surround
1538 * D rear front-out
1539 * E rear mic-in/CLFE
1540 *
1541 * laptop
1542 * Port-A headphone
1543 * B mic-in
1544 * C docking station
1545 * D internal speaker (with EAPD)
1546 * E/F quad mic array
1547 */
1548
1549
1550/* models */
1551enum {
1552 AD1988_6STACK,
1553 AD1988_6STACK_DIG,
1554 AD1988_3STACK,
1555 AD1988_3STACK_DIG,
1556 AD1988_LAPTOP,
1557 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001558 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001559 AD1988_MODEL_LAST,
1560};
1561
Takashi Iwaid32410b12005-11-24 16:06:23 +01001562/* reivision id to check workarounds */
1563#define AD1988A_REV2 0x100200
1564
Takashi Iwai1a806f42006-07-03 15:58:16 +02001565#define is_rev2(codec) \
1566 ((codec)->vendor_id == 0x11d41988 && \
1567 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001568
1569/*
1570 * mixers
1571 */
1572
Takashi Iwaid32410b12005-11-24 16:06:23 +01001573static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001574 0x04, 0x06, 0x05, 0x0a
1575};
1576
Takashi Iwaid32410b12005-11-24 16:06:23 +01001577static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001578 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001579};
1580
1581/* for AD1988A revision-2, DAC2-4 are swapped */
1582static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1583 0x04, 0x05, 0x0a, 0x06
1584};
1585
1586static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001587 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001588};
1589
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001590static hda_nid_t ad1988_adc_nids[3] = {
1591 0x08, 0x09, 0x0f
1592};
1593
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001594static hda_nid_t ad1988_capsrc_nids[3] = {
1595 0x0c, 0x0d, 0x0e
1596};
1597
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001598#define AD1988_SPDIF_OUT 0x02
1599#define AD1988_SPDIF_IN 0x07
1600
1601static struct hda_input_mux ad1988_6stack_capture_source = {
1602 .num_items = 5,
1603 .items = {
1604 { "Front Mic", 0x0 },
1605 { "Line", 0x1 },
1606 { "Mic", 0x4 },
1607 { "CD", 0x5 },
1608 { "Mix", 0x9 },
1609 },
1610};
1611
1612static struct hda_input_mux ad1988_laptop_capture_source = {
1613 .num_items = 3,
1614 .items = {
1615 { "Mic/Line", 0x0 },
1616 { "CD", 0x5 },
1617 { "Mix", 0x9 },
1618 },
1619};
1620
1621/*
1622 */
1623static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_info *uinfo)
1625{
1626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1627 struct ad198x_spec *spec = codec->spec;
1628 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1629 spec->num_channel_mode);
1630}
1631
1632static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1633 struct snd_ctl_elem_value *ucontrol)
1634{
1635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1636 struct ad198x_spec *spec = codec->spec;
1637 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1638 spec->num_channel_mode, spec->multiout.max_channels);
1639}
1640
1641static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1642 struct snd_ctl_elem_value *ucontrol)
1643{
1644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1645 struct ad198x_spec *spec = codec->spec;
Takashi Iwai2125cad2006-03-27 12:52:22 +02001646 if (spec->need_dac_fix)
1647 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001648 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1649 spec->num_channel_mode, &spec->multiout.max_channels);
1650}
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);
2480 pin = spec->autocfg.hp_pin;
2481 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 Iwai82bc9552006-03-21 11:24:42 +01002532 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pin,
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};