blob: 9c241ccf690795ddb44ddcf9fed3329dbb9b24f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002 * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
35
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
64 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
65
Ingo Molnar62932df2006-01-16 16:34:20 +010066 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020067 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010068
69 /* dynamic controls, init_verbs and input_mux */
70 struct auto_pin_cfg autocfg;
71 unsigned int num_kctl_alloc, num_kctl_used;
72 struct snd_kcontrol_new *kctl_alloc;
73 struct hda_input_mux private_imux;
74 hda_nid_t private_dac_nids[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020077/*
78 * input MUX handling (common part)
79 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010080static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020081{
82 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
83 struct ad198x_spec *spec = codec->spec;
84
85 return snd_hda_input_mux_info(spec->input_mux, uinfo);
86}
87
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010088static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020089{
90 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
91 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010092 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020093
Takashi Iwai985be542005-11-02 18:26:49 +010094 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020095 return 0;
96}
97
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010098static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
104 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100105 spec->capsrc_nids[adc_idx],
106 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200107}
108
109/*
110 * initialization (common callbacks)
111 */
112static int ad198x_init(struct hda_codec *codec)
113{
114 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100115 int i;
116
117 for (i = 0; i < spec->num_init_verbs; i++)
118 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200119 return 0;
120}
121
122static int ad198x_build_controls(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200126 int err;
127
Takashi Iwai985be542005-11-02 18:26:49 +0100128 for (i = 0; i < spec->num_mixers; i++) {
129 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
130 if (err < 0)
131 return err;
132 }
133 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200134 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100135 if (err < 0)
136 return err;
137 }
138 if (spec->dig_in_nid) {
139 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
140 if (err < 0)
141 return err;
142 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200143 return 0;
144}
145
146/*
147 * Analog playback callbacks
148 */
149static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100151 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200152{
153 struct ad198x_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
155}
156
157static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 unsigned int stream_tag,
160 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100161 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200162{
163 struct ad198x_spec *spec = codec->spec;
164 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
165 format, substream);
166}
167
168static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100170 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200171{
172 struct ad198x_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
174}
175
176/*
177 * Digital out
178 */
179static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100181 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200182{
183 struct ad198x_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
185}
186
187static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100189 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200190{
191 struct ad198x_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
193}
194
195/*
196 * Analog capture
197 */
198static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
199 struct hda_codec *codec,
200 unsigned int stream_tag,
201 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100202 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200203{
204 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100205 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
206 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200207 return 0;
208}
209
210static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100212 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200213{
214 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100215 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
216 0, 0, 0);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200217 return 0;
218}
219
220
221/*
222 */
223static struct hda_pcm_stream ad198x_pcm_analog_playback = {
224 .substreams = 1,
225 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100226 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200227 .nid = 0, /* fill later */
228 .ops = {
229 .open = ad198x_playback_pcm_open,
230 .prepare = ad198x_playback_pcm_prepare,
231 .cleanup = ad198x_playback_pcm_cleanup
232 },
233};
234
235static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100236 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200237 .channels_min = 2,
238 .channels_max = 2,
239 .nid = 0, /* fill later */
240 .ops = {
241 .prepare = ad198x_capture_pcm_prepare,
242 .cleanup = ad198x_capture_pcm_cleanup
243 },
244};
245
246static struct hda_pcm_stream ad198x_pcm_digital_playback = {
247 .substreams = 1,
248 .channels_min = 2,
249 .channels_max = 2,
250 .nid = 0, /* fill later */
251 .ops = {
252 .open = ad198x_dig_playback_pcm_open,
253 .close = ad198x_dig_playback_pcm_close
254 },
255};
256
Takashi Iwai985be542005-11-02 18:26:49 +0100257static struct hda_pcm_stream ad198x_pcm_digital_capture = {
258 .substreams = 1,
259 .channels_min = 2,
260 .channels_max = 2,
261 /* NID is set in alc_build_pcms */
262};
263
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200264static int ad198x_build_pcms(struct hda_codec *codec)
265{
266 struct ad198x_spec *spec = codec->spec;
267 struct hda_pcm *info = spec->pcm_rec;
268
269 codec->num_pcms = 1;
270 codec->pcm_info = info;
271
272 info->name = "AD198x Analog";
273 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
275 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
276 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100277 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
278 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200279
280 if (spec->multiout.dig_out_nid) {
281 info++;
282 codec->num_pcms++;
283 info->name = "AD198x Digital";
284 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
285 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100286 if (spec->dig_in_nid) {
287 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
288 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
289 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200290 }
291
292 return 0;
293}
294
295static void ad198x_free(struct hda_codec *codec)
296{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100297 struct ad198x_spec *spec = codec->spec;
298 unsigned int i;
299
300 if (spec->kctl_alloc) {
301 for (i = 0; i < spec->num_kctl_used; i++)
302 kfree(spec->kctl_alloc[i].name);
303 kfree(spec->kctl_alloc);
304 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200305 kfree(codec->spec);
306}
307
308#ifdef CONFIG_PM
309static int ad198x_resume(struct hda_codec *codec)
310{
311 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100312 int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200313
Takashi Iwai18a815d2006-03-01 19:54:39 +0100314 codec->patch_ops.init(codec);
Takashi Iwai985be542005-11-02 18:26:49 +0100315 for (i = 0; i < spec->num_mixers; i++)
316 snd_hda_resume_ctls(codec, spec->mixers[i]);
317 if (spec->multiout.dig_out_nid)
318 snd_hda_resume_spdif_out(codec);
319 if (spec->dig_in_nid)
320 snd_hda_resume_spdif_in(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200321 return 0;
322}
323#endif
324
325static struct hda_codec_ops ad198x_patch_ops = {
326 .build_controls = ad198x_build_controls,
327 .build_pcms = ad198x_build_pcms,
328 .init = ad198x_init,
329 .free = ad198x_free,
330#ifdef CONFIG_PM
331 .resume = ad198x_resume,
332#endif
333};
334
335
336/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100337 * EAPD control
338 * the private value = nid | (invert << 8)
339 */
340static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_info *uinfo)
342{
343 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
344 uinfo->count = 1;
345 uinfo->value.integer.min = 0;
346 uinfo->value.integer.max = 1;
347 return 0;
348}
349
350static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
352{
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 struct ad198x_spec *spec = codec->spec;
355 int invert = (kcontrol->private_value >> 8) & 1;
356 if (invert)
357 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
358 else
359 ucontrol->value.integer.value[0] = spec->cur_eapd;
360 return 0;
361}
362
363static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_value *ucontrol)
365{
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367 struct ad198x_spec *spec = codec->spec;
368 int invert = (kcontrol->private_value >> 8) & 1;
369 hda_nid_t nid = kcontrol->private_value & 0xff;
370 unsigned int eapd;
371 eapd = ucontrol->value.integer.value[0];
372 if (invert)
373 eapd = !eapd;
374 if (eapd == spec->cur_eapd && ! codec->in_resume)
375 return 0;
376 spec->cur_eapd = eapd;
377 snd_hda_codec_write(codec, nid,
378 0, AC_VERB_SET_EAPD_BTLENABLE,
379 eapd ? 0x02 : 0x00);
380 return 1;
381}
382
Takashi Iwai9230d212006-03-13 13:49:49 +0100383static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
384 struct snd_ctl_elem_info *uinfo);
385static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_value *ucontrol);
387static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol);
389
390
Takashi Iwai18a815d2006-03-01 19:54:39 +0100391/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200392 * AD1986A specific
393 */
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define AD1986A_SPDIF_OUT 0x02
396#define AD1986A_FRONT_DAC 0x03
397#define AD1986A_SURR_DAC 0x04
398#define AD1986A_CLFE_DAC 0x05
399#define AD1986A_ADC 0x06
400
401static hda_nid_t ad1986a_dac_nids[3] = {
402 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
403};
Takashi Iwai985be542005-11-02 18:26:49 +0100404static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100405static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407static struct hda_input_mux ad1986a_capture_source = {
408 .num_items = 7,
409 .items = {
410 { "Mic", 0x0 },
411 { "CD", 0x1 },
412 { "Aux", 0x3 },
413 { "Line", 0x4 },
414 { "Mix", 0x5 },
415 { "Mono", 0x6 },
416 { "Phone", 0x7 },
417 },
418};
419
420/*
421 * PCM control
422 *
423 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
424 */
425
426#define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info
427
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100428static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200431 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Ingo Molnar62932df2006-01-16 16:34:20 +0100433 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100435 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
437}
438
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100439static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200442 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 int i, change = 0;
444
Ingo Molnar62932df2006-01-16 16:34:20 +0100445 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
447 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
448 change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
449 }
450 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100451 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return change;
453}
454
Takashi Iwaiead9b7c2005-06-08 14:48:19 +0200455#define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100457static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200460 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Ingo Molnar62932df2006-01-16 16:34:20 +0100462 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
Ingo Molnar62932df2006-01-16 16:34:20 +0100464 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return 0;
466}
467
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100468static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200471 struct ad198x_spec *ad = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 int i, change = 0;
473
Ingo Molnar62932df2006-01-16 16:34:20 +0100474 mutex_lock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
476 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
477 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
478 }
479 kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
Ingo Molnar62932df2006-01-16 16:34:20 +0100480 mutex_unlock(&ad->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return change;
482}
483
484/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 * mixers
486 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100487static struct snd_kcontrol_new ad1986a_mixers[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
490 .name = "PCM Playback Volume",
Jaroslav Kysela302e9c52006-07-05 17:39:49 +0200491 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
492 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
493 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .info = ad1986a_pcm_amp_vol_info,
495 .get = ad1986a_pcm_amp_vol_get,
496 .put = ad1986a_pcm_amp_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200497 .tlv = { .c = snd_hda_mixer_amp_tlv },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
499 },
500 {
501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
502 .name = "PCM Playback Switch",
503 .info = ad1986a_pcm_amp_sw_info,
504 .get = ad1986a_pcm_amp_sw_get,
505 .put = ad1986a_pcm_amp_sw_put,
506 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
507 },
508 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
509 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
510 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
511 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
512 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
513 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
514 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
515 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
516 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
517 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100526 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
528 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
533 {
534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
535 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200536 .info = ad198x_mux_enum_info,
537 .get = ad198x_mux_enum_get,
538 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 },
540 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
541 { } /* end */
542};
543
Takashi Iwai9230d212006-03-13 13:49:49 +0100544/* additional mixers for 3stack mode */
545static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
546 {
547 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
548 .name = "Channel Mode",
549 .info = ad198x_ch_mode_info,
550 .get = ad198x_ch_mode_get,
551 .put = ad198x_ch_mode_put,
552 },
553 { } /* end */
554};
555
556/* laptop model - 2ch only */
557static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
558
559static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
560 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
561 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
562 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
563 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
564 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
565 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
566 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
569 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
570 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100574 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai9230d212006-03-13 13:49:49 +0100575 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
576 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
577 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
578 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
579 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
580 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
581 {
582 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
583 .name = "Capture Source",
584 .info = ad198x_mux_enum_info,
585 .get = ad198x_mux_enum_get,
586 .put = ad198x_mux_enum_put,
587 },
588 { } /* end */
589};
590
Takashi Iwai825aa9722006-03-17 10:50:49 +0100591/* laptop-eapd model - 2ch only */
592
593/* master controls both pins 0x1a and 0x1b */
594static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_value *ucontrol)
596{
597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598 long *valp = ucontrol->value.integer.value;
599 int change;
600
601 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
602 0x7f, valp[0] & 0x7f);
603 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
604 0x7f, valp[1] & 0x7f);
605 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
606 0x7f, valp[0] & 0x7f);
607 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
608 0x7f, valp[1] & 0x7f);
609 return change;
610}
611
612static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
614{
615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616 long *valp = ucontrol->value.integer.value;
617 int change;
618
619 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
620 0x80, valp[0] ? 0 : 0x80);
621 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
622 0x80, valp[1] ? 0 : 0x80);
623 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
624 0x80, valp[0] ? 0 : 0x80);
625 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
626 0x80, valp[1] ? 0 : 0x80);
627 return change;
628}
629
630static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
631 .num_items = 3,
632 .items = {
633 { "Mic", 0x0 },
634 { "Internal Mic", 0x4 },
635 { "Mix", 0x5 },
636 },
637};
638
639static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
640 {
641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
642 .name = "Master Playback Volume",
643 .info = snd_hda_mixer_amp_volume_info,
644 .get = snd_hda_mixer_amp_volume_get,
645 .put = ad1986a_laptop_master_vol_put,
Takashi Iwaic2566522006-08-17 18:21:36 +0200646 .tlv = { .c = snd_hda_mixer_amp_tlv },
Takashi Iwai825aa9722006-03-17 10:50:49 +0100647 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
648 },
649 {
650 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
651 .name = "Master Playback Switch",
652 .info = snd_hda_mixer_amp_switch_info,
653 .get = snd_hda_mixer_amp_switch_get,
654 .put = ad1986a_laptop_master_sw_put,
655 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
656 },
657 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
658 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
659 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
660 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
661 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
662 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100663 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai825aa9722006-03-17 10:50:49 +0100664 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
665 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
666 {
667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
668 .name = "Capture Source",
669 .info = ad198x_mux_enum_info,
670 .get = ad198x_mux_enum_get,
671 .put = ad198x_mux_enum_put,
672 },
673 {
674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
675 .name = "External Amplifier",
676 .info = ad198x_eapd_info,
677 .get = ad198x_eapd_get,
678 .put = ad198x_eapd_put,
679 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
680 },
681 { } /* end */
682};
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684/*
685 * initialization verbs
686 */
687static struct hda_verb ad1986a_init_verbs[] = {
688 /* Front, Surround, CLFE DAC; mute as default */
689 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
690 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
691 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
692 /* Downmix - off */
693 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
694 /* HP, Line-Out, Surround, CLFE selectors */
695 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
696 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
697 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
698 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
699 /* Mono selector */
700 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
701 /* Mic selector: Mic 1/2 pin */
702 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
703 /* Line-in selector: Line-in */
704 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
705 /* Mic 1/2 swap */
706 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
707 /* Record selector: mic */
708 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
709 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
710 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
711 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
712 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
713 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
714 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
715 /* PC beep */
716 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
717 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
718 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
719 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
720 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200723 /* HP Pin */
724 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
725 /* Front, Surround, CLFE Pins */
726 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
727 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
728 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
729 /* Mono Pin */
730 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
731 /* Mic Pin */
732 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
733 /* Line, Aux, CD, Beep-In Pin */
734 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
735 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
736 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
737 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
738 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 { } /* end */
740};
741
Takashi Iwai9230d212006-03-13 13:49:49 +0100742/* additional verbs for 3-stack model */
743static struct hda_verb ad1986a_3st_init_verbs[] = {
Andrea Arcangeli1aba2bc2007-03-22 01:02:58 +0100744 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
745 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x4},
746 /* Line-in selectors */
Takashi Iwai9230d212006-03-13 13:49:49 +0100747 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
748 { } /* end */
749};
750
751static struct hda_verb ad1986a_ch2_init[] = {
752 /* Surround out -> Line In */
753 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
754 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
755 /* CLFE -> Mic in */
756 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
757 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
758 { } /* end */
759};
760
761static struct hda_verb ad1986a_ch4_init[] = {
762 /* Surround out -> Surround */
763 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
764 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
765 /* CLFE -> Mic in */
766 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
767 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
768 { } /* end */
769};
770
771static struct hda_verb ad1986a_ch6_init[] = {
772 /* Surround out -> Surround out */
773 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
774 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
775 /* CLFE -> CLFE */
776 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
777 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
778 { } /* end */
779};
780
781static struct hda_channel_mode ad1986a_modes[3] = {
782 { 2, ad1986a_ch2_init },
783 { 4, ad1986a_ch4_init },
784 { 6, ad1986a_ch6_init },
785};
786
Takashi Iwai825aa9722006-03-17 10:50:49 +0100787/* eapd initialization */
788static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100789 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa9722006-03-17 10:50:49 +0100790 {}
791};
792
Tobin Davisf36090f2007-01-08 11:07:12 +0100793/* Ultra initialization */
794static struct hda_verb ad1986a_ultra_init[] = {
795 /* eapd initialization */
796 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
797 /* CLFE -> Mic in */
798 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
799 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
800 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
801 { } /* end */
802};
803
Takashi Iwai9230d212006-03-13 13:49:49 +0100804/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100805enum {
806 AD1986A_6STACK,
807 AD1986A_3STACK,
808 AD1986A_LAPTOP,
809 AD1986A_LAPTOP_EAPD,
Tobin Davisf36090f2007-01-08 11:07:12 +0100810 AD1986A_ULTRA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100811 AD1986A_MODELS
812};
Takashi Iwai9230d212006-03-13 13:49:49 +0100813
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100814static const char *ad1986a_models[AD1986A_MODELS] = {
815 [AD1986A_6STACK] = "6stack",
816 [AD1986A_3STACK] = "3stack",
817 [AD1986A_LAPTOP] = "laptop",
818 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisf36090f2007-01-08 11:07:12 +0100819 [AD1986A_ULTRA] = "ultra",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100820};
821
822static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
823 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
824 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
825 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
826 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
827 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
828 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
829 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
830 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
831 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
832 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
833 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
834 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
835 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
836 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +0100837 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100838 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
839 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
840 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
841 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
Tobin Davisf36090f2007-01-08 11:07:12 +0100842 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
843 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Tobin Davis18768992007-03-12 22:20:51 +0100844 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100845 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
846 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
847 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +0100848 {}
849};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851static int patch_ad1986a(struct hda_codec *codec)
852{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200853 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100854 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200856 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (spec == NULL)
858 return -ENOMEM;
859
Ingo Molnar62932df2006-01-16 16:34:20 +0100860 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 codec->spec = spec;
862
863 spec->multiout.max_channels = 6;
864 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
865 spec->multiout.dac_nids = ad1986a_dac_nids;
866 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100867 spec->num_adc_nids = 1;
868 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100869 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200870 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100871 spec->num_mixers = 1;
872 spec->mixers[0] = ad1986a_mixers;
873 spec->num_init_verbs = 1;
874 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200876 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Takashi Iwai9230d212006-03-13 13:49:49 +0100878 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100879 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
880 ad1986a_models,
881 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +0100882 switch (board_config) {
883 case AD1986A_3STACK:
884 spec->num_mixers = 2;
885 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200886 spec->num_init_verbs = 3;
Takashi Iwai9230d212006-03-13 13:49:49 +0100887 spec->init_verbs[1] = ad1986a_3st_init_verbs;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200888 spec->init_verbs[2] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100889 spec->channel_mode = ad1986a_modes;
890 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200891 spec->need_dac_fix = 1;
892 spec->multiout.max_channels = 2;
893 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100894 break;
895 case AD1986A_LAPTOP:
896 spec->mixers[0] = ad1986a_laptop_mixers;
897 spec->multiout.max_channels = 2;
898 spec->multiout.num_dacs = 1;
899 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
900 break;
Takashi Iwai825aa9722006-03-17 10:50:49 +0100901 case AD1986A_LAPTOP_EAPD:
902 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
903 spec->num_init_verbs = 2;
904 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
905 spec->multiout.max_channels = 2;
906 spec->multiout.num_dacs = 1;
907 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
908 spec->multiout.dig_out_nid = 0;
909 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
910 break;
Tobin Davisf36090f2007-01-08 11:07:12 +0100911 case AD1986A_ULTRA:
912 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
913 spec->num_init_verbs = 2;
914 spec->init_verbs[1] = ad1986a_ultra_init;
915 spec->multiout.max_channels = 2;
916 spec->multiout.num_dacs = 1;
917 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
918 spec->multiout.dig_out_nid = 0;
919 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100920 }
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 return 0;
923}
924
925/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200926 * AD1983 specific
927 */
928
929#define AD1983_SPDIF_OUT 0x02
930#define AD1983_DAC 0x03
931#define AD1983_ADC 0x04
932
933static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100934static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100935static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200936
937static struct hda_input_mux ad1983_capture_source = {
938 .num_items = 4,
939 .items = {
940 { "Mic", 0x0 },
941 { "Line", 0x1 },
942 { "Mix", 0x2 },
943 { "Mix Mono", 0x3 },
944 },
945};
946
947/*
948 * SPDIF playback route
949 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100950static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200951{
952 static char *texts[] = { "PCM", "ADC" };
953
954 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
955 uinfo->count = 1;
956 uinfo->value.enumerated.items = 2;
957 if (uinfo->value.enumerated.item > 1)
958 uinfo->value.enumerated.item = 1;
959 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
960 return 0;
961}
962
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100963static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200964{
965 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
966 struct ad198x_spec *spec = codec->spec;
967
968 ucontrol->value.enumerated.item[0] = spec->spdif_route;
969 return 0;
970}
971
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100972static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200973{
974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
975 struct ad198x_spec *spec = codec->spec;
976
977 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
978 spec->spdif_route = ucontrol->value.enumerated.item[0];
979 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
980 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
981 return 1;
982 }
983 return 0;
984}
985
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100986static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200987 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
988 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
989 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
991 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
992 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
993 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
994 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
995 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
996 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
997 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
998 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
999 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1000 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1001 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1002 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1003 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1004 {
1005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1006 .name = "Capture Source",
1007 .info = ad198x_mux_enum_info,
1008 .get = ad198x_mux_enum_get,
1009 .put = ad198x_mux_enum_put,
1010 },
1011 {
1012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001013 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001014 .info = ad1983_spdif_route_info,
1015 .get = ad1983_spdif_route_get,
1016 .put = ad1983_spdif_route_put,
1017 },
1018 { } /* end */
1019};
1020
1021static struct hda_verb ad1983_init_verbs[] = {
1022 /* Front, HP, Mono; mute as default */
1023 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1024 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1025 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1026 /* Beep, PCM, Mic, Line-In: mute */
1027 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1028 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1029 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1030 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1031 /* Front, HP selectors; from Mix */
1032 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1033 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1034 /* Mono selector; from Mix */
1035 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1036 /* Mic selector; Mic */
1037 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1038 /* Line-in selector: Line-in */
1039 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1040 /* Mic boost: 0dB */
1041 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1042 /* Record selector: mic */
1043 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1044 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1045 /* SPDIF route: PCM */
1046 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1047 /* Front Pin */
1048 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1049 /* HP Pin */
1050 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1051 /* Mono Pin */
1052 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1053 /* Mic Pin */
1054 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1055 /* Line Pin */
1056 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1057 { } /* end */
1058};
1059
Takashi Iwai985be542005-11-02 18:26:49 +01001060
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001061static int patch_ad1983(struct hda_codec *codec)
1062{
1063 struct ad198x_spec *spec;
1064
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001066 if (spec == NULL)
1067 return -ENOMEM;
1068
Ingo Molnar62932df2006-01-16 16:34:20 +01001069 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001070 codec->spec = spec;
1071
1072 spec->multiout.max_channels = 2;
1073 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1074 spec->multiout.dac_nids = ad1983_dac_nids;
1075 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001076 spec->num_adc_nids = 1;
1077 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001078 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001079 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001080 spec->num_mixers = 1;
1081 spec->mixers[0] = ad1983_mixers;
1082 spec->num_init_verbs = 1;
1083 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001084 spec->spdif_route = 0;
1085
1086 codec->patch_ops = ad198x_patch_ops;
1087
1088 return 0;
1089}
1090
1091
1092/*
1093 * AD1981 HD specific
1094 */
1095
1096#define AD1981_SPDIF_OUT 0x02
1097#define AD1981_DAC 0x03
1098#define AD1981_ADC 0x04
1099
1100static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001101static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001102static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001103
1104/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1105static struct hda_input_mux ad1981_capture_source = {
1106 .num_items = 7,
1107 .items = {
1108 { "Front Mic", 0x0 },
1109 { "Line", 0x1 },
1110 { "Mix", 0x2 },
1111 { "Mix Mono", 0x3 },
1112 { "CD", 0x4 },
1113 { "Mic", 0x6 },
1114 { "Aux", 0x7 },
1115 },
1116};
1117
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001118static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001119 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1120 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1121 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1122 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1123 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1124 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1126 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1127 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1128 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1132 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1133 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1134 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1135 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1136 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1137 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1138 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1139 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1140 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1141 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1142 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1143 {
1144 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1145 .name = "Capture Source",
1146 .info = ad198x_mux_enum_info,
1147 .get = ad198x_mux_enum_get,
1148 .put = ad198x_mux_enum_put,
1149 },
1150 /* identical with AD1983 */
1151 {
1152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001153 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001154 .info = ad1983_spdif_route_info,
1155 .get = ad1983_spdif_route_get,
1156 .put = ad1983_spdif_route_put,
1157 },
1158 { } /* end */
1159};
1160
1161static struct hda_verb ad1981_init_verbs[] = {
1162 /* Front, HP, Mono; mute as default */
1163 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1164 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1165 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1166 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1167 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1168 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1169 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1170 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1171 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1172 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1173 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1174 /* Front, HP selectors; from Mix */
1175 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1176 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1177 /* Mono selector; from Mix */
1178 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1179 /* Mic Mixer; select Front Mic */
1180 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1181 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1182 /* Mic boost: 0dB */
1183 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1184 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1185 /* Record selector: Front mic */
1186 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1187 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1188 /* SPDIF route: PCM */
1189 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1190 /* Front Pin */
1191 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1192 /* HP Pin */
1193 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1194 /* Mono Pin */
1195 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1196 /* Front & Rear Mic Pins */
1197 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1198 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1199 /* Line Pin */
1200 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1201 /* Digital Beep */
1202 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1203 /* Line-Out as Input: disabled */
1204 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1205 { } /* end */
1206};
1207
Takashi Iwai18a815d2006-03-01 19:54:39 +01001208/*
1209 * Patch for HP nx6320
1210 *
Tobin Davis18768992007-03-12 22:20:51 +01001211 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001212 * speaker output enabled _and_ mute-LED off.
1213 */
1214
1215#define AD1981_HP_EVENT 0x37
1216#define AD1981_MIC_EVENT 0x38
1217
1218static struct hda_verb ad1981_hp_init_verbs[] = {
1219 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1220 /* pin sensing on HP and Mic jacks */
1221 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1222 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1223 {}
1224};
1225
1226/* turn on/off EAPD (+ mute HP) as a master switch */
1227static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1228 struct snd_ctl_elem_value *ucontrol)
1229{
1230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1231 struct ad198x_spec *spec = codec->spec;
1232
1233 if (! ad198x_eapd_put(kcontrol, ucontrol))
1234 return 0;
1235
1236 /* toggle HP mute appropriately */
1237 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1238 0x80, spec->cur_eapd ? 0 : 0x80);
1239 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1240 0x80, spec->cur_eapd ? 0 : 0x80);
1241 return 1;
1242}
1243
1244/* bind volumes of both NID 0x05 and 0x06 */
1245static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1246 struct snd_ctl_elem_value *ucontrol)
1247{
1248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1249 long *valp = ucontrol->value.integer.value;
1250 int change;
1251
1252 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1253 0x7f, valp[0] & 0x7f);
1254 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1255 0x7f, valp[1] & 0x7f);
1256 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1257 0x7f, valp[0] & 0x7f);
1258 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1259 0x7f, valp[1] & 0x7f);
1260 return change;
1261}
1262
1263/* mute internal speaker if HP is plugged */
1264static void ad1981_hp_automute(struct hda_codec *codec)
1265{
1266 unsigned int present;
1267
1268 present = snd_hda_codec_read(codec, 0x06, 0,
1269 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1270 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1271 0x80, present ? 0x80 : 0);
1272 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1273 0x80, present ? 0x80 : 0);
1274}
1275
1276/* toggle input of built-in and mic jack appropriately */
1277static void ad1981_hp_automic(struct hda_codec *codec)
1278{
1279 static struct hda_verb mic_jack_on[] = {
1280 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1281 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1282 {}
1283 };
1284 static struct hda_verb mic_jack_off[] = {
1285 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1286 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1287 {}
1288 };
1289 unsigned int present;
1290
1291 present = snd_hda_codec_read(codec, 0x08, 0,
1292 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1293 if (present)
1294 snd_hda_sequence_write(codec, mic_jack_on);
1295 else
1296 snd_hda_sequence_write(codec, mic_jack_off);
1297}
1298
1299/* unsolicited event for HP jack sensing */
1300static void ad1981_hp_unsol_event(struct hda_codec *codec,
1301 unsigned int res)
1302{
1303 res >>= 26;
1304 switch (res) {
1305 case AD1981_HP_EVENT:
1306 ad1981_hp_automute(codec);
1307 break;
1308 case AD1981_MIC_EVENT:
1309 ad1981_hp_automic(codec);
1310 break;
1311 }
1312}
1313
1314static struct hda_input_mux ad1981_hp_capture_source = {
1315 .num_items = 3,
1316 .items = {
1317 { "Mic", 0x0 },
1318 { "Docking-Station", 0x1 },
1319 { "Mix", 0x2 },
1320 },
1321};
1322
1323static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1324 {
1325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1326 .name = "Master Playback Volume",
1327 .info = snd_hda_mixer_amp_volume_info,
1328 .get = snd_hda_mixer_amp_volume_get,
1329 .put = ad1981_hp_master_vol_put,
1330 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1331 },
1332 {
1333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1334 .name = "Master Playback Switch",
1335 .info = ad198x_eapd_info,
1336 .get = ad198x_eapd_get,
1337 .put = ad1981_hp_master_sw_put,
1338 .private_value = 0x05,
1339 },
1340 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1341 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1342#if 0
1343 /* FIXME: analog mic/line loopback doesn't work with my tests...
1344 * (although recording is OK)
1345 */
1346 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1347 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1348 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1349 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1350 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1352 /* FIXME: does this laptop have analog CD connection? */
1353 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1355#endif
1356 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1357 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1358 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1360 {
1361 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1362 .name = "Capture Source",
1363 .info = ad198x_mux_enum_info,
1364 .get = ad198x_mux_enum_get,
1365 .put = ad198x_mux_enum_put,
1366 },
1367 { } /* end */
1368};
1369
1370/* initialize jack-sensing, too */
1371static int ad1981_hp_init(struct hda_codec *codec)
1372{
1373 ad198x_init(codec);
1374 ad1981_hp_automute(codec);
1375 ad1981_hp_automic(codec);
1376 return 0;
1377}
1378
Tobin Davis18768992007-03-12 22:20:51 +01001379/* configuration for Toshiba Laptops */
1380static struct hda_verb ad1981_toshiba_init_verbs[] = {
1381 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1382 /* pin sensing on HP and Mic jacks */
1383 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1384 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1385 {}
1386};
1387
1388static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1389 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1390 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1391 { }
1392};
1393
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001394/* configuration for Lenovo Thinkpad T60 */
1395static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1396 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1403 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1404 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1405 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1406 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1407 {
1408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1409 .name = "Capture Source",
1410 .info = ad198x_mux_enum_info,
1411 .get = ad198x_mux_enum_get,
1412 .put = ad198x_mux_enum_put,
1413 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001414 /* identical with AD1983 */
1415 {
1416 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1417 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1418 .info = ad1983_spdif_route_info,
1419 .get = ad1983_spdif_route_get,
1420 .put = ad1983_spdif_route_put,
1421 },
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001422 { } /* end */
1423};
1424
1425static struct hda_input_mux ad1981_thinkpad_capture_source = {
1426 .num_items = 3,
1427 .items = {
1428 { "Mic", 0x0 },
1429 { "Mix", 0x2 },
1430 { "CD", 0x4 },
1431 },
1432};
1433
Takashi Iwai18a815d2006-03-01 19:54:39 +01001434/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001435enum {
1436 AD1981_BASIC,
1437 AD1981_HP,
1438 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001439 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001440 AD1981_MODELS
1441};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001442
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001443static const char *ad1981_models[AD1981_MODELS] = {
1444 [AD1981_HP] = "hp",
1445 [AD1981_THINKPAD] = "thinkpad",
1446 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001447 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001448};
1449
1450static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001451 /* All HP models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001452 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1453 /* HP nx6320 (reversed SSID, H/W bug) */
1454 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001455 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001456 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1457 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Tobin Davis18768992007-03-12 22:20:51 +01001458 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001459 {}
1460};
1461
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001462static int patch_ad1981(struct hda_codec *codec)
1463{
1464 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001465 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001466
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001468 if (spec == NULL)
1469 return -ENOMEM;
1470
Ingo Molnar62932df2006-01-16 16:34:20 +01001471 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001472 codec->spec = spec;
1473
1474 spec->multiout.max_channels = 2;
1475 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1476 spec->multiout.dac_nids = ad1981_dac_nids;
1477 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001478 spec->num_adc_nids = 1;
1479 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001480 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001481 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001482 spec->num_mixers = 1;
1483 spec->mixers[0] = ad1981_mixers;
1484 spec->num_init_verbs = 1;
1485 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001486 spec->spdif_route = 0;
1487
1488 codec->patch_ops = ad198x_patch_ops;
1489
Takashi Iwai18a815d2006-03-01 19:54:39 +01001490 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1492 ad1981_models,
1493 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001494 switch (board_config) {
1495 case AD1981_HP:
1496 spec->mixers[0] = ad1981_hp_mixers;
1497 spec->num_init_verbs = 2;
1498 spec->init_verbs[1] = ad1981_hp_init_verbs;
1499 spec->multiout.dig_out_nid = 0;
1500 spec->input_mux = &ad1981_hp_capture_source;
1501
1502 codec->patch_ops.init = ad1981_hp_init;
1503 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1504 break;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001505 case AD1981_THINKPAD:
1506 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001507 spec->input_mux = &ad1981_thinkpad_capture_source;
1508 break;
Tobin Davis18768992007-03-12 22:20:51 +01001509 case AD1981_TOSHIBA:
1510 spec->mixers[0] = ad1981_hp_mixers;
1511 spec->mixers[1] = ad1981_toshiba_mixers;
1512 spec->num_init_verbs = 2;
1513 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1514 spec->multiout.dig_out_nid = 0;
1515 spec->input_mux = &ad1981_hp_capture_source;
1516 codec->patch_ops.init = ad1981_hp_init;
1517 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1518 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001519 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001520 return 0;
1521}
1522
1523
1524/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001525 * AD1988
1526 *
1527 * Output pins and routes
1528 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001529 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001530 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1531 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1532 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1533 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1534 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1535 * port-F 0x16 (mute) <- 0x2a <- 06
1536 * port-G 0x24 (mute) <- 0x27 <- 05
1537 * port-H 0x25 (mute) <- 0x28 <- 0a
1538 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1539 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001540 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1541 * (*) 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 +01001542 *
1543 * Input pins and routes
1544 *
1545 * pin boost mix input # / adc input #
1546 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1547 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1548 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1549 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1550 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1551 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1552 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1553 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1554 *
1555 *
1556 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001557 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001558 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001559 *
1560 * Inputs of Analog Mix (0x20)
1561 * 0:Port-B (front mic)
1562 * 1:Port-C/G/H (line-in)
1563 * 2:Port-A
1564 * 3:Port-D (line-in/2)
1565 * 4:Port-E/G/H (mic-in)
1566 * 5:Port-F (mic2-in)
1567 * 6:CD
1568 * 7:Beep
1569 *
1570 * ADC selection
1571 * 0:Port-A
1572 * 1:Port-B (front mic-in)
1573 * 2:Port-C (line-in)
1574 * 3:Port-F (mic2-in)
1575 * 4:Port-E (mic-in)
1576 * 5:CD
1577 * 6:Port-G
1578 * 7:Port-H
1579 * 8:Port-D (line-in/2)
1580 * 9:Mix
1581 *
1582 * Proposed pin assignments by the datasheet
1583 *
1584 * 6-stack
1585 * Port-A front headphone
1586 * B front mic-in
1587 * C rear line-in
1588 * D rear front-out
1589 * E rear mic-in
1590 * F rear surround
1591 * G rear CLFE
1592 * H rear side
1593 *
1594 * 3-stack
1595 * Port-A front headphone
1596 * B front mic
1597 * C rear line-in/surround
1598 * D rear front-out
1599 * E rear mic-in/CLFE
1600 *
1601 * laptop
1602 * Port-A headphone
1603 * B mic-in
1604 * C docking station
1605 * D internal speaker (with EAPD)
1606 * E/F quad mic array
1607 */
1608
1609
1610/* models */
1611enum {
1612 AD1988_6STACK,
1613 AD1988_6STACK_DIG,
1614 AD1988_3STACK,
1615 AD1988_3STACK_DIG,
1616 AD1988_LAPTOP,
1617 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001618 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001619 AD1988_MODEL_LAST,
1620};
1621
Takashi Iwaid32410b12005-11-24 16:06:23 +01001622/* reivision id to check workarounds */
1623#define AD1988A_REV2 0x100200
1624
Takashi Iwai1a806f42006-07-03 15:58:16 +02001625#define is_rev2(codec) \
1626 ((codec)->vendor_id == 0x11d41988 && \
1627 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001628
1629/*
1630 * mixers
1631 */
1632
Takashi Iwaid32410b12005-11-24 16:06:23 +01001633static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001634 0x04, 0x06, 0x05, 0x0a
1635};
1636
Takashi Iwaid32410b12005-11-24 16:06:23 +01001637static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001638 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001639};
1640
1641/* for AD1988A revision-2, DAC2-4 are swapped */
1642static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1643 0x04, 0x05, 0x0a, 0x06
1644};
1645
1646static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001647 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001648};
1649
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001650static hda_nid_t ad1988_adc_nids[3] = {
1651 0x08, 0x09, 0x0f
1652};
1653
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001654static hda_nid_t ad1988_capsrc_nids[3] = {
1655 0x0c, 0x0d, 0x0e
1656};
1657
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001658#define AD1988_SPDIF_OUT 0x02
1659#define AD1988_SPDIF_IN 0x07
1660
1661static struct hda_input_mux ad1988_6stack_capture_source = {
1662 .num_items = 5,
1663 .items = {
1664 { "Front Mic", 0x0 },
1665 { "Line", 0x1 },
1666 { "Mic", 0x4 },
1667 { "CD", 0x5 },
1668 { "Mix", 0x9 },
1669 },
1670};
1671
1672static struct hda_input_mux ad1988_laptop_capture_source = {
1673 .num_items = 3,
1674 .items = {
1675 { "Mic/Line", 0x0 },
1676 { "CD", 0x5 },
1677 { "Mix", 0x9 },
1678 },
1679};
1680
1681/*
1682 */
1683static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1684 struct snd_ctl_elem_info *uinfo)
1685{
1686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1687 struct ad198x_spec *spec = codec->spec;
1688 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1689 spec->num_channel_mode);
1690}
1691
1692static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1693 struct snd_ctl_elem_value *ucontrol)
1694{
1695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1696 struct ad198x_spec *spec = codec->spec;
1697 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1698 spec->num_channel_mode, spec->multiout.max_channels);
1699}
1700
1701static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1702 struct snd_ctl_elem_value *ucontrol)
1703{
1704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1705 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001706 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1707 spec->num_channel_mode,
1708 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001709 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001710 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001711 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001712}
1713
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001714/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001715static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001716 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1717 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1718 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1719 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1720 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001721 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001722};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001723
Takashi Iwaid32410b12005-11-24 16:06:23 +01001724static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1725 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1726 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1727 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1728 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1729 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001730 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001731};
1732
1733static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001734 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1735 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1736 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1737 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1738 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1739 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1740 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1741
1742 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1743 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1744 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1745 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1746 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1747 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1748 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1749 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1750
1751 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1752 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1753
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001754 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001755 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1756
1757 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1758 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1759
1760 { } /* end */
1761};
1762
1763/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001764static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001765 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001766 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001767 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1768 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001769 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001770};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001771
Takashi Iwaid32410b12005-11-24 16:06:23 +01001772static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1773 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001774 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1775 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1776 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001777 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001778};
1779
1780static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001781 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001782 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1783 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1784 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001785 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1786 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1787
1788 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1789 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1790 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1791 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1792 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1793 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1794 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1795 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1796
1797 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1798 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1799
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001800 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001801 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1802
1803 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1804 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1805 {
1806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1807 .name = "Channel Mode",
1808 .info = ad198x_ch_mode_info,
1809 .get = ad198x_ch_mode_get,
1810 .put = ad198x_ch_mode_put,
1811 },
1812
1813 { } /* end */
1814};
1815
1816/* laptop mode */
1817static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1818 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1819 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1820 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1821
1822 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1823 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1824 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1825 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1826 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1827 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1828
1829 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1830 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1831
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001832 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001833 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1834
1835 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1836
1837 {
1838 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1839 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001840 .info = ad198x_eapd_info,
1841 .get = ad198x_eapd_get,
1842 .put = ad198x_eapd_put,
1843 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001844 },
1845
1846 { } /* end */
1847};
1848
1849/* capture */
1850static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1851 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1852 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1853 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1854 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1855 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1856 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1857 {
1858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1859 /* The multiple "Capture Source" controls confuse alsamixer
1860 * So call somewhat different..
1861 * FIXME: the controls appear in the "playback" view!
1862 */
1863 /* .name = "Capture Source", */
1864 .name = "Input Source",
1865 .count = 3,
1866 .info = ad198x_mux_enum_info,
1867 .get = ad198x_mux_enum_get,
1868 .put = ad198x_mux_enum_put,
1869 },
1870 { } /* end */
1871};
1872
1873static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1874 struct snd_ctl_elem_info *uinfo)
1875{
1876 static char *texts[] = {
1877 "PCM", "ADC1", "ADC2", "ADC3"
1878 };
1879 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1880 uinfo->count = 1;
1881 uinfo->value.enumerated.items = 4;
1882 if (uinfo->value.enumerated.item >= 4)
1883 uinfo->value.enumerated.item = 3;
1884 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1885 return 0;
1886}
1887
1888static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1889 struct snd_ctl_elem_value *ucontrol)
1890{
1891 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1892 unsigned int sel;
1893
1894 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1895 if (sel > 0) {
1896 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1897 if (sel <= 3)
1898 sel++;
1899 else
1900 sel = 0;
1901 }
1902 ucontrol->value.enumerated.item[0] = sel;
1903 return 0;
1904}
1905
1906static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1907 struct snd_ctl_elem_value *ucontrol)
1908{
1909 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1910 unsigned int sel;
1911 int change;
1912
1913 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1914 if (! ucontrol->value.enumerated.item[0]) {
1915 change = sel != 0;
1916 if (change)
1917 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1918 } else {
1919 change = sel == 0;
1920 if (change)
1921 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1922 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1923 change |= sel == ucontrol->value.enumerated.item[0];
1924 if (change)
1925 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1926 ucontrol->value.enumerated.item[0] - 1);
1927 }
1928 return change;
1929}
1930
1931static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1932 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1933 {
1934 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1935 .name = "IEC958 Playback Source",
1936 .info = ad1988_spdif_playback_source_info,
1937 .get = ad1988_spdif_playback_source_get,
1938 .put = ad1988_spdif_playback_source_put,
1939 },
1940 { } /* end */
1941};
1942
1943static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1944 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1945 { } /* end */
1946};
1947
1948
1949/*
1950 * initialization verbs
1951 */
1952
1953/*
1954 * for 6-stack (+dig)
1955 */
1956static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001957 /* Front, Surround, CLFE, side DAC; unmute as default */
1958 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1959 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1960 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1961 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001962 /* Port-A front headphon path */
1963 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1964 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1965 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1966 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1967 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1968 /* Port-D line-out path */
1969 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1970 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1971 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1972 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1973 /* Port-F surround path */
1974 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1975 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1976 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1977 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1978 /* Port-G CLFE path */
1979 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1980 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1981 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1982 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1983 /* Port-H side path */
1984 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1985 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1986 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1987 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1988 /* Mono out path */
1989 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1990 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1991 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1992 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1993 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1994 /* Port-B front mic-in path */
1995 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1996 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1997 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1998 /* Port-C line-in path */
1999 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2000 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2001 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2002 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2003 /* Port-E mic-in path */
2004 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2005 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2006 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2007 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2008
2009 { }
2010};
2011
2012static struct hda_verb ad1988_capture_init_verbs[] = {
2013 /* mute analog mix */
2014 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2015 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2016 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2017 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2018 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2019 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2020 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2021 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2022 /* select ADCs - front-mic */
2023 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2024 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2025 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2026 /* ADCs; muted */
2027 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2028 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2029 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2030
2031 { }
2032};
2033
2034static struct hda_verb ad1988_spdif_init_verbs[] = {
2035 /* SPDIF out sel */
2036 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2037 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2038 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2039 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2040 /* SPDIF out pin */
2041 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2042 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
2043
2044 { }
2045};
2046
2047/*
2048 * verbs for 3stack (+dig)
2049 */
2050static struct hda_verb ad1988_3stack_ch2_init[] = {
2051 /* set port-C to line-in */
2052 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2053 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2054 /* set port-E to mic-in */
2055 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2056 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2057 { } /* end */
2058};
2059
2060static struct hda_verb ad1988_3stack_ch6_init[] = {
2061 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002062 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002063 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002064 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002065 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002066 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002067 { } /* end */
2068};
2069
2070static struct hda_channel_mode ad1988_3stack_modes[2] = {
2071 { 2, ad1988_3stack_ch2_init },
2072 { 6, ad1988_3stack_ch6_init },
2073};
2074
2075static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002076 /* Front, Surround, CLFE, side DAC; unmute as default */
2077 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2078 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2079 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2080 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002081 /* Port-A front headphon path */
2082 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2083 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2084 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2085 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2086 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2087 /* Port-D line-out path */
2088 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2089 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2090 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2092 /* Mono out path */
2093 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2094 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2095 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2096 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2097 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2098 /* Port-B front mic-in path */
2099 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2100 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2101 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002102 /* Port-C line-in/surround path - 6ch mode as default */
2103 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2104 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002105 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002106 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002107 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002108 /* Port-E mic-in/CLFE path - 6ch mode as default */
2109 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2110 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002111 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002112 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002113 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2114 /* mute analog mix */
2115 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2116 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2117 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2118 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2119 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2120 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2121 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2122 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2123 /* select ADCs - front-mic */
2124 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2125 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2126 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2127 /* ADCs; muted */
2128 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2129 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2130 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2131 { }
2132};
2133
2134/*
2135 * verbs for laptop mode (+dig)
2136 */
2137static struct hda_verb ad1988_laptop_hp_on[] = {
2138 /* unmute port-A and mute port-D */
2139 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2140 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2141 { } /* end */
2142};
2143static struct hda_verb ad1988_laptop_hp_off[] = {
2144 /* mute port-A and unmute port-D */
2145 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2146 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2147 { } /* end */
2148};
2149
2150#define AD1988_HP_EVENT 0x01
2151
2152static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002153 /* Front, Surround, CLFE, side DAC; unmute as default */
2154 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2155 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2156 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2157 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002158 /* Port-A front headphon path */
2159 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2160 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2161 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2162 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2163 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2164 /* unsolicited event for pin-sense */
2165 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2166 /* Port-D line-out path + EAPD */
2167 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2168 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2169 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2170 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2171 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2172 /* Mono out path */
2173 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2174 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2175 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2176 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2177 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2178 /* Port-B mic-in path */
2179 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2180 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2181 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2182 /* Port-C docking station - try to output */
2183 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2184 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2185 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2186 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2187 /* mute analog mix */
2188 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2189 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2190 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2191 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2192 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2193 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2194 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2195 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2196 /* select ADCs - mic */
2197 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2198 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2199 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2200 /* ADCs; muted */
2201 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2202 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2203 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2204 { }
2205};
2206
2207static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2208{
2209 if ((res >> 26) != AD1988_HP_EVENT)
2210 return;
2211 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2212 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2213 else
2214 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2215}
2216
2217
2218/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002219 * Automatic parse of I/O pins from the BIOS configuration
2220 */
2221
2222#define NUM_CONTROL_ALLOC 32
2223#define NUM_VERB_ALLOC 32
2224
2225enum {
2226 AD_CTL_WIDGET_VOL,
2227 AD_CTL_WIDGET_MUTE,
2228 AD_CTL_BIND_MUTE,
2229};
2230static struct snd_kcontrol_new ad1988_control_templates[] = {
2231 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2232 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2233 HDA_BIND_MUTE(NULL, 0, 0, 0),
2234};
2235
2236/* add dynamic controls */
2237static int add_control(struct ad198x_spec *spec, int type, const char *name,
2238 unsigned long val)
2239{
2240 struct snd_kcontrol_new *knew;
2241
2242 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2243 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2244
2245 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2246 if (! knew)
2247 return -ENOMEM;
2248 if (spec->kctl_alloc) {
2249 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2250 kfree(spec->kctl_alloc);
2251 }
2252 spec->kctl_alloc = knew;
2253 spec->num_kctl_alloc = num;
2254 }
2255
2256 knew = &spec->kctl_alloc[spec->num_kctl_used];
2257 *knew = ad1988_control_templates[type];
2258 knew->name = kstrdup(name, GFP_KERNEL);
2259 if (! knew->name)
2260 return -ENOMEM;
2261 knew->private_value = val;
2262 spec->num_kctl_used++;
2263 return 0;
2264}
2265
2266#define AD1988_PIN_CD_NID 0x18
2267#define AD1988_PIN_BEEP_NID 0x10
2268
2269static hda_nid_t ad1988_mixer_nids[8] = {
2270 /* A B C D E F G H */
2271 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2272};
2273
2274static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2275{
2276 static hda_nid_t idx_to_dac[8] = {
2277 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002278 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002279 };
2280 static hda_nid_t idx_to_dac_rev2[8] = {
2281 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002282 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002283 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002284 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002285 return idx_to_dac_rev2[idx];
2286 else
2287 return idx_to_dac[idx];
2288}
2289
2290static hda_nid_t ad1988_boost_nids[8] = {
2291 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2292};
2293
2294static int ad1988_pin_idx(hda_nid_t nid)
2295{
2296 static hda_nid_t ad1988_io_pins[8] = {
2297 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2298 };
2299 int i;
2300 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2301 if (ad1988_io_pins[i] == nid)
2302 return i;
2303 return 0; /* should be -1 */
2304}
2305
2306static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2307{
2308 static int loopback_idx[8] = {
2309 2, 0, 1, 3, 4, 5, 1, 4
2310 };
2311 switch (nid) {
2312 case AD1988_PIN_CD_NID:
2313 return 6;
2314 default:
2315 return loopback_idx[ad1988_pin_idx(nid)];
2316 }
2317}
2318
2319static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2320{
2321 static int adc_idx[8] = {
2322 0, 1, 2, 8, 4, 3, 6, 7
2323 };
2324 switch (nid) {
2325 case AD1988_PIN_CD_NID:
2326 return 5;
2327 default:
2328 return adc_idx[ad1988_pin_idx(nid)];
2329 }
2330}
2331
2332/* fill in the dac_nids table from the parsed pin configuration */
2333static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2334 const struct auto_pin_cfg *cfg)
2335{
2336 struct ad198x_spec *spec = codec->spec;
2337 int i, idx;
2338
2339 spec->multiout.dac_nids = spec->private_dac_nids;
2340
2341 /* check the pins hardwired to audio widget */
2342 for (i = 0; i < cfg->line_outs; i++) {
2343 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2344 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2345 }
2346 spec->multiout.num_dacs = cfg->line_outs;
2347 return 0;
2348}
2349
2350/* add playback controls from the parsed DAC table */
2351static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2352 const struct auto_pin_cfg *cfg)
2353{
2354 char name[32];
2355 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2356 hda_nid_t nid;
2357 int i, err;
2358
2359 for (i = 0; i < cfg->line_outs; i++) {
2360 hda_nid_t dac = spec->multiout.dac_nids[i];
2361 if (! dac)
2362 continue;
2363 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2364 if (i == 2) {
2365 /* Center/LFE */
2366 err = add_control(spec, AD_CTL_WIDGET_VOL,
2367 "Center Playback Volume",
2368 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2369 if (err < 0)
2370 return err;
2371 err = add_control(spec, AD_CTL_WIDGET_VOL,
2372 "LFE Playback Volume",
2373 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2374 if (err < 0)
2375 return err;
2376 err = add_control(spec, AD_CTL_BIND_MUTE,
2377 "Center Playback Switch",
2378 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2379 if (err < 0)
2380 return err;
2381 err = add_control(spec, AD_CTL_BIND_MUTE,
2382 "LFE Playback Switch",
2383 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2384 if (err < 0)
2385 return err;
2386 } else {
2387 sprintf(name, "%s Playback Volume", chname[i]);
2388 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2389 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2390 if (err < 0)
2391 return err;
2392 sprintf(name, "%s Playback Switch", chname[i]);
2393 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2394 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2395 if (err < 0)
2396 return err;
2397 }
2398 }
2399 return 0;
2400}
2401
2402/* add playback controls for speaker and HP outputs */
2403static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2404 const char *pfx)
2405{
2406 struct ad198x_spec *spec = codec->spec;
2407 hda_nid_t nid;
2408 int idx, err;
2409 char name[32];
2410
2411 if (! pin)
2412 return 0;
2413
2414 idx = ad1988_pin_idx(pin);
2415 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002416 /* specify the DAC as the extra output */
2417 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002418 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002419 else
2420 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002421 /* control HP volume/switch on the output mixer amp */
2422 sprintf(name, "%s Playback Volume", pfx);
2423 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2424 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2425 return err;
2426 nid = ad1988_mixer_nids[idx];
2427 sprintf(name, "%s Playback Switch", pfx);
2428 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2429 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2430 return err;
2431 return 0;
2432}
2433
2434/* create input playback/capture controls for the given pin */
2435static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2436 const char *ctlname, int boost)
2437{
2438 char name[32];
2439 int err, idx;
2440
2441 sprintf(name, "%s Playback Volume", ctlname);
2442 idx = ad1988_pin_to_loopback_idx(pin);
2443 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2444 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2445 return err;
2446 sprintf(name, "%s Playback Switch", ctlname);
2447 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2448 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2449 return err;
2450 if (boost) {
2451 hda_nid_t bnid;
2452 idx = ad1988_pin_idx(pin);
2453 bnid = ad1988_boost_nids[idx];
2454 if (bnid) {
2455 sprintf(name, "%s Boost", ctlname);
2456 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2457 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2458
2459 }
2460 }
2461 return 0;
2462}
2463
2464/* create playback/capture controls for input pins */
2465static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2466 const struct auto_pin_cfg *cfg)
2467{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002468 struct hda_input_mux *imux = &spec->private_imux;
2469 int i, err;
2470
2471 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002472 err = new_analog_input(spec, cfg->input_pins[i],
2473 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002474 i <= AUTO_PIN_FRONT_MIC);
2475 if (err < 0)
2476 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002477 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002478 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2479 imux->num_items++;
2480 }
2481 imux->items[imux->num_items].label = "Mix";
2482 imux->items[imux->num_items].index = 9;
2483 imux->num_items++;
2484
2485 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2486 "Analog Mix Playback Volume",
2487 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2488 return err;
2489 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2490 "Analog Mix Playback Switch",
2491 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2492 return err;
2493
2494 return 0;
2495}
2496
2497static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2498 hda_nid_t nid, int pin_type,
2499 int dac_idx)
2500{
2501 /* set as output */
2502 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2503 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2504 switch (nid) {
2505 case 0x11: /* port-A - DAC 04 */
2506 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2507 break;
2508 case 0x14: /* port-B - DAC 06 */
2509 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2510 break;
2511 case 0x15: /* port-C - DAC 05 */
2512 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2513 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002514 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002515 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2516 break;
2517 case 0x13: /* mono - DAC 04 */
2518 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2519 break;
2520 }
2521}
2522
2523static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2524{
2525 struct ad198x_spec *spec = codec->spec;
2526 int i;
2527
2528 for (i = 0; i < spec->autocfg.line_outs; i++) {
2529 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2530 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2531 }
2532}
2533
2534static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2535{
2536 struct ad198x_spec *spec = codec->spec;
2537 hda_nid_t pin;
2538
Takashi Iwai82bc9552006-03-21 11:24:42 +01002539 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002540 if (pin) /* connect to front */
2541 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002542 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002543 if (pin) /* connect to front */
2544 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2545}
2546
2547static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2548{
2549 struct ad198x_spec *spec = codec->spec;
2550 int i, idx;
2551
2552 for (i = 0; i < AUTO_PIN_LAST; i++) {
2553 hda_nid_t nid = spec->autocfg.input_pins[i];
2554 if (! nid)
2555 continue;
2556 switch (nid) {
2557 case 0x15: /* port-C */
2558 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2559 break;
2560 case 0x17: /* port-E */
2561 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2562 break;
2563 }
2564 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2565 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2566 if (nid != AD1988_PIN_CD_NID)
2567 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2568 AMP_OUT_MUTE);
2569 idx = ad1988_pin_idx(nid);
2570 if (ad1988_boost_nids[idx])
2571 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2572 AC_VERB_SET_AMP_GAIN_MUTE,
2573 AMP_OUT_ZERO);
2574 }
2575}
2576
2577/* parse the BIOS configuration and set up the alc_spec */
2578/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2579static int ad1988_parse_auto_config(struct hda_codec *codec)
2580{
2581 struct ad198x_spec *spec = codec->spec;
2582 int err;
2583
Kailang Yangdf694da2005-12-05 19:42:22 +01002584 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002585 return err;
2586 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2587 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002588 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002589 return 0; /* can't find valid BIOS pin config */
2590 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002591 (err = ad1988_auto_create_extra_out(codec,
2592 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002593 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002594 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002595 "Headphone")) < 0 ||
2596 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2597 return err;
2598
2599 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2600
2601 if (spec->autocfg.dig_out_pin)
2602 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2603 if (spec->autocfg.dig_in_pin)
2604 spec->dig_in_nid = AD1988_SPDIF_IN;
2605
2606 if (spec->kctl_alloc)
2607 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2608
2609 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2610
2611 spec->input_mux = &spec->private_imux;
2612
2613 return 1;
2614}
2615
2616/* init callback for auto-configuration model -- overriding the default init */
2617static int ad1988_auto_init(struct hda_codec *codec)
2618{
2619 ad198x_init(codec);
2620 ad1988_auto_init_multi_out(codec);
2621 ad1988_auto_init_extra_out(codec);
2622 ad1988_auto_init_analog_input(codec);
2623 return 0;
2624}
2625
2626
2627/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002628 */
2629
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002630static const char *ad1988_models[AD1988_MODEL_LAST] = {
2631 [AD1988_6STACK] = "6stack",
2632 [AD1988_6STACK_DIG] = "6stack-dig",
2633 [AD1988_3STACK] = "3stack",
2634 [AD1988_3STACK_DIG] = "3stack-dig",
2635 [AD1988_LAPTOP] = "laptop",
2636 [AD1988_LAPTOP_DIG] = "laptop-dig",
2637 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002638};
2639
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002640static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2641 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Tobin Davis18768992007-03-12 22:20:51 +01002642 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002643 {}
2644};
2645
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002646static int patch_ad1988(struct hda_codec *codec)
2647{
2648 struct ad198x_spec *spec;
2649 int board_config;
2650
2651 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2652 if (spec == NULL)
2653 return -ENOMEM;
2654
Ingo Molnar62932df2006-01-16 16:34:20 +01002655 mutex_init(&spec->amp_mutex);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002656 codec->spec = spec;
2657
Takashi Iwai1a806f42006-07-03 15:58:16 +02002658 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002659 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2660
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002661 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002662 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002663 if (board_config < 0) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002664 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2665 board_config = AD1988_AUTO;
2666 }
2667
2668 if (board_config == AD1988_AUTO) {
2669 /* automatic parse from the BIOS config */
2670 int err = ad1988_parse_auto_config(codec);
2671 if (err < 0) {
2672 ad198x_free(codec);
2673 return err;
2674 } else if (! err) {
2675 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2676 board_config = AD1988_6STACK;
2677 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002678 }
2679
2680 switch (board_config) {
2681 case AD1988_6STACK:
2682 case AD1988_6STACK_DIG:
2683 spec->multiout.max_channels = 8;
2684 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002685 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002686 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2687 else
2688 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002689 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002690 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002691 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002692 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2693 else
2694 spec->mixers[0] = ad1988_6stack_mixers1;
2695 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002696 spec->num_init_verbs = 1;
2697 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2698 if (board_config == AD1988_6STACK_DIG) {
2699 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2700 spec->dig_in_nid = AD1988_SPDIF_IN;
2701 }
2702 break;
2703 case AD1988_3STACK:
2704 case AD1988_3STACK_DIG:
2705 spec->multiout.max_channels = 6;
2706 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002707 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002708 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2709 else
2710 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002711 spec->input_mux = &ad1988_6stack_capture_source;
2712 spec->channel_mode = ad1988_3stack_modes;
2713 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002714 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002715 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002716 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2717 else
2718 spec->mixers[0] = ad1988_3stack_mixers1;
2719 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002720 spec->num_init_verbs = 1;
2721 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2722 if (board_config == AD1988_3STACK_DIG)
2723 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2724 break;
2725 case AD1988_LAPTOP:
2726 case AD1988_LAPTOP_DIG:
2727 spec->multiout.max_channels = 2;
2728 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002729 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002730 spec->input_mux = &ad1988_laptop_capture_source;
2731 spec->num_mixers = 1;
2732 spec->mixers[0] = ad1988_laptop_mixers;
2733 spec->num_init_verbs = 1;
2734 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2735 if (board_config == AD1988_LAPTOP_DIG)
2736 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2737 break;
2738 }
2739
Takashi Iwaid32410b12005-11-24 16:06:23 +01002740 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2741 spec->adc_nids = ad1988_adc_nids;
2742 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002743 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2744 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2745 if (spec->multiout.dig_out_nid) {
2746 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2747 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2748 }
2749 if (spec->dig_in_nid)
2750 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2751
2752 codec->patch_ops = ad198x_patch_ops;
2753 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002754 case AD1988_AUTO:
2755 codec->patch_ops.init = ad1988_auto_init;
2756 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002757 case AD1988_LAPTOP:
2758 case AD1988_LAPTOP_DIG:
2759 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2760 break;
2761 }
2762
2763 return 0;
2764}
2765
2766
2767/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 * patch entries
2769 */
2770struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002771 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2772 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002774 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02002775 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 {} /* terminator */
2777};