blob: 9a6015ad61843458909c89d36de3d7188bc1bdec [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002 * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
31
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
35
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
64 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
65
Ingo Molnar62932df2006-01-16 16:34:20 +010066 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020067 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010068
69 /* dynamic controls, init_verbs and input_mux */
70 struct auto_pin_cfg autocfg;
71 unsigned int num_kctl_alloc, num_kctl_used;
72 struct snd_kcontrol_new *kctl_alloc;
73 struct hda_input_mux private_imux;
74 hda_nid_t private_dac_nids[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020077/*
78 * input MUX handling (common part)
79 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010080static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020081{
82 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
83 struct ad198x_spec *spec = codec->spec;
84
85 return snd_hda_input_mux_info(spec->input_mux, uinfo);
86}
87
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010088static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020089{
90 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
91 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010092 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020093
Takashi Iwai985be542005-11-02 18:26:49 +010094 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020095 return 0;
96}
97
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010098static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
104 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100105 spec->capsrc_nids[adc_idx],
106 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200107}
108
109/*
110 * initialization (common callbacks)
111 */
112static int ad198x_init(struct hda_codec *codec)
113{
114 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100115 int i;
116
117 for (i = 0; i < spec->num_init_verbs; i++)
118 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200119 return 0;
120}
121
122static int ad198x_build_controls(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200126 int err;
127
Takashi Iwai985be542005-11-02 18:26:49 +0100128 for (i = 0; i < spec->num_mixers; i++) {
129 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
130 if (err < 0)
131 return err;
132 }
133 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200134 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100135 if (err < 0)
136 return err;
137 }
138 if (spec->dig_in_nid) {
139 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
140 if (err < 0)
141 return err;
142 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200143 return 0;
144}
145
146/*
147 * Analog playback callbacks
148 */
149static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
150 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100151 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200152{
153 struct ad198x_spec *spec = codec->spec;
154 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
155}
156
157static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
158 struct hda_codec *codec,
159 unsigned int stream_tag,
160 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100161 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200162{
163 struct ad198x_spec *spec = codec->spec;
164 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
165 format, substream);
166}
167
168static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
169 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100170 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200171{
172 struct ad198x_spec *spec = codec->spec;
173 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
174}
175
176/*
177 * Digital out
178 */
179static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
180 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100181 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200182{
183 struct ad198x_spec *spec = codec->spec;
184 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
185}
186
187static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
188 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100189 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200190{
191 struct ad198x_spec *spec = codec->spec;
192 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
193}
194
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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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",
491 .info = ad1986a_pcm_amp_vol_info,
492 .get = ad1986a_pcm_amp_vol_get,
493 .put = ad1986a_pcm_amp_vol_put,
494 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
495 },
496 {
497 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
498 .name = "PCM Playback Switch",
499 .info = ad1986a_pcm_amp_sw_info,
500 .get = ad1986a_pcm_amp_sw_get,
501 .put = ad1986a_pcm_amp_sw_put,
502 .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
503 },
504 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
505 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
506 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
507 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
508 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
509 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
510 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
511 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
512 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
513 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
514 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
515 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
516 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
517 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
528 {
529 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
530 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200531 .info = ad198x_mux_enum_info,
532 .get = ad198x_mux_enum_get,
533 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 },
535 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
536 { } /* end */
537};
538
Takashi Iwai9230d212006-03-13 13:49:49 +0100539/* additional mixers for 3stack mode */
540static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
541 {
542 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
543 .name = "Channel Mode",
544 .info = ad198x_ch_mode_info,
545 .get = ad198x_ch_mode_get,
546 .put = ad198x_ch_mode_put,
547 },
548 { } /* end */
549};
550
551/* laptop model - 2ch only */
552static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
553
554static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
555 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
556 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
557 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
558 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
559 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
560 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
561 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
562 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
563 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
564 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
565 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
566 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
567 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
568 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
569 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
570 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
571 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
572 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
573 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
575 {
576 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
577 .name = "Capture Source",
578 .info = ad198x_mux_enum_info,
579 .get = ad198x_mux_enum_get,
580 .put = ad198x_mux_enum_put,
581 },
582 { } /* end */
583};
584
Takashi Iwai825aa972006-03-17 10:50:49 +0100585/* laptop-eapd model - 2ch only */
586
587/* master controls both pins 0x1a and 0x1b */
588static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
589 struct snd_ctl_elem_value *ucontrol)
590{
591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592 long *valp = ucontrol->value.integer.value;
593 int change;
594
595 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
596 0x7f, valp[0] & 0x7f);
597 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
598 0x7f, valp[1] & 0x7f);
599 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
600 0x7f, valp[0] & 0x7f);
601 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
602 0x7f, valp[1] & 0x7f);
603 return change;
604}
605
606static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 long *valp = ucontrol->value.integer.value;
611 int change;
612
613 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
614 0x80, valp[0] ? 0 : 0x80);
615 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
616 0x80, valp[1] ? 0 : 0x80);
617 snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
618 0x80, valp[0] ? 0 : 0x80);
619 snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
620 0x80, valp[1] ? 0 : 0x80);
621 return change;
622}
623
624static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
625 .num_items = 3,
626 .items = {
627 { "Mic", 0x0 },
628 { "Internal Mic", 0x4 },
629 { "Mix", 0x5 },
630 },
631};
632
633static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
634 {
635 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
636 .name = "Master Playback Volume",
637 .info = snd_hda_mixer_amp_volume_info,
638 .get = snd_hda_mixer_amp_volume_get,
639 .put = ad1986a_laptop_master_vol_put,
640 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
641 },
642 {
643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
644 .name = "Master Playback Switch",
645 .info = snd_hda_mixer_amp_switch_info,
646 .get = snd_hda_mixer_amp_switch_get,
647 .put = ad1986a_laptop_master_sw_put,
648 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
649 },
650 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
651 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
652 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
653 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
654 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
655 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
656 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
657 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
658 {
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "Capture Source",
661 .info = ad198x_mux_enum_info,
662 .get = ad198x_mux_enum_get,
663 .put = ad198x_mux_enum_put,
664 },
665 {
666 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
667 .name = "External Amplifier",
668 .info = ad198x_eapd_info,
669 .get = ad198x_eapd_get,
670 .put = ad198x_eapd_put,
671 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
672 },
673 { } /* end */
674};
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*
677 * initialization verbs
678 */
679static struct hda_verb ad1986a_init_verbs[] = {
680 /* Front, Surround, CLFE DAC; mute as default */
681 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
682 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
683 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
684 /* Downmix - off */
685 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
686 /* HP, Line-Out, Surround, CLFE selectors */
687 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
688 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
689 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
690 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
691 /* Mono selector */
692 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
693 /* Mic selector: Mic 1/2 pin */
694 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
695 /* Line-in selector: Line-in */
696 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
697 /* Mic 1/2 swap */
698 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
699 /* Record selector: mic */
700 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
701 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
702 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
703 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
704 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
706 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
707 /* PC beep */
708 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
709 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
710 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
711 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
712 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
713 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
714 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200715 /* HP Pin */
716 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
717 /* Front, Surround, CLFE Pins */
718 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
719 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
720 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
721 /* Mono Pin */
722 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
723 /* Mic Pin */
724 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
725 /* Line, Aux, CD, Beep-In Pin */
726 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
727 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
728 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
729 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
730 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 { } /* end */
732};
733
Takashi Iwai9230d212006-03-13 13:49:49 +0100734/* additional verbs for 3-stack model */
735static struct hda_verb ad1986a_3st_init_verbs[] = {
736 /* Mic and line-in selectors */
737 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
738 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
739 { } /* end */
740};
741
742static struct hda_verb ad1986a_ch2_init[] = {
743 /* Surround out -> Line In */
744 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
745 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
746 /* CLFE -> Mic in */
747 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
748 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
749 { } /* end */
750};
751
752static struct hda_verb ad1986a_ch4_init[] = {
753 /* Surround out -> Surround */
754 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
755 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
756 /* CLFE -> Mic in */
757 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
758 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
759 { } /* end */
760};
761
762static struct hda_verb ad1986a_ch6_init[] = {
763 /* Surround out -> Surround out */
764 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
765 { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
766 /* CLFE -> CLFE */
767 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
768 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
769 { } /* end */
770};
771
772static struct hda_channel_mode ad1986a_modes[3] = {
773 { 2, ad1986a_ch2_init },
774 { 4, ad1986a_ch4_init },
775 { 6, ad1986a_ch6_init },
776};
777
Takashi Iwai825aa972006-03-17 10:50:49 +0100778/* eapd initialization */
779static struct hda_verb ad1986a_eapd_init_verbs[] = {
780 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00},
781 {}
782};
783
Takashi Iwai9230d212006-03-13 13:49:49 +0100784/* models */
Takashi Iwai825aa972006-03-17 10:50:49 +0100785enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP, AD1986A_LAPTOP_EAPD };
Takashi Iwai9230d212006-03-13 13:49:49 +0100786
787static struct hda_board_config ad1986a_cfg_tbl[] = {
788 { .modelname = "6stack", .config = AD1986A_6STACK },
789 { .modelname = "3stack", .config = AD1986A_3STACK },
Takashi Iwai82bc9552006-03-21 11:24:42 +0100790 { .pci_subvendor = 0x10de, .pci_subdevice = 0xcb84,
791 .config = AD1986A_3STACK }, /* ASUS A8N-VM CSM */
Takashi Iwai9230d212006-03-13 13:49:49 +0100792 { .modelname = "laptop", .config = AD1986A_LAPTOP },
793 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
794 .config = AD1986A_LAPTOP }, /* FSC V2060 */
795 { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
796 .config = AD1986A_LAPTOP }, /* Samsung M50 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100797 { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
798 .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
799 { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD },
800 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
801 .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
Takashi Iwai61a74542006-04-20 16:42:34 +0200802 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1153,
803 .config = AD1986A_LAPTOP_EAPD }, /* ASUS M9 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100804 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
805 .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
Takashi Iwaie0922282006-04-10 19:09:01 +0200806 { .pci_subvendor = 0x1043, .pci_subdevice = 0x11f7,
807 .config = AD1986A_LAPTOP_EAPD }, /* ASUS U5A */
Takashi Iwaie0292bd2006-04-26 17:44:18 +0200808 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1297,
809 .config = AD1986A_LAPTOP_EAPD }, /* ASUS Z62F */
Coywolf Qi Huntbe28e7c2006-04-10 10:47:11 +0200810 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30af,
811 .config = AD1986A_LAPTOP_EAPD }, /* HP Compaq Presario B2800 */
Daniel T Chen6dac9a62006-06-21 08:51:07 +0200812 { .pci_subvendor = 0x17aa, .pci_subdevice = 0x2066,
813 .config = AD1986A_LAPTOP_EAPD }, /* Lenovo 3000 N100-07684JU */
Takashi Iwai9230d212006-03-13 13:49:49 +0100814 {}
815};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817static int patch_ad1986a(struct hda_codec *codec)
818{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200819 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100820 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200822 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (spec == NULL)
824 return -ENOMEM;
825
Ingo Molnar62932df2006-01-16 16:34:20 +0100826 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 codec->spec = spec;
828
829 spec->multiout.max_channels = 6;
830 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
831 spec->multiout.dac_nids = ad1986a_dac_nids;
832 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100833 spec->num_adc_nids = 1;
834 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100835 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200836 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100837 spec->num_mixers = 1;
838 spec->mixers[0] = ad1986a_mixers;
839 spec->num_init_verbs = 1;
840 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200842 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Takashi Iwai9230d212006-03-13 13:49:49 +0100844 /* override some parameters */
845 board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
846 switch (board_config) {
847 case AD1986A_3STACK:
848 spec->num_mixers = 2;
849 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200850 spec->num_init_verbs = 3;
Takashi Iwai9230d212006-03-13 13:49:49 +0100851 spec->init_verbs[1] = ad1986a_3st_init_verbs;
Takashi Iwai2125cad2006-03-27 12:52:22 +0200852 spec->init_verbs[2] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100853 spec->channel_mode = ad1986a_modes;
854 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200855 spec->need_dac_fix = 1;
856 spec->multiout.max_channels = 2;
857 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100858 break;
859 case AD1986A_LAPTOP:
860 spec->mixers[0] = ad1986a_laptop_mixers;
861 spec->multiout.max_channels = 2;
862 spec->multiout.num_dacs = 1;
863 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
864 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100865 case AD1986A_LAPTOP_EAPD:
866 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
867 spec->num_init_verbs = 2;
868 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
869 spec->multiout.max_channels = 2;
870 spec->multiout.num_dacs = 1;
871 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
872 spec->multiout.dig_out_nid = 0;
873 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
874 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100875 }
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return 0;
878}
879
880/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200881 * AD1983 specific
882 */
883
884#define AD1983_SPDIF_OUT 0x02
885#define AD1983_DAC 0x03
886#define AD1983_ADC 0x04
887
888static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100889static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100890static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200891
892static struct hda_input_mux ad1983_capture_source = {
893 .num_items = 4,
894 .items = {
895 { "Mic", 0x0 },
896 { "Line", 0x1 },
897 { "Mix", 0x2 },
898 { "Mix Mono", 0x3 },
899 },
900};
901
902/*
903 * SPDIF playback route
904 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100905static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200906{
907 static char *texts[] = { "PCM", "ADC" };
908
909 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
910 uinfo->count = 1;
911 uinfo->value.enumerated.items = 2;
912 if (uinfo->value.enumerated.item > 1)
913 uinfo->value.enumerated.item = 1;
914 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
915 return 0;
916}
917
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100918static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200919{
920 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
921 struct ad198x_spec *spec = codec->spec;
922
923 ucontrol->value.enumerated.item[0] = spec->spdif_route;
924 return 0;
925}
926
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100927static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200928{
929 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
930 struct ad198x_spec *spec = codec->spec;
931
932 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
933 spec->spdif_route = ucontrol->value.enumerated.item[0];
934 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
935 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
936 return 1;
937 }
938 return 0;
939}
940
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100941static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200942 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
943 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
944 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
945 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
946 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
947 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
948 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
949 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
950 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
951 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
952 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
953 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
954 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
955 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
956 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
957 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
958 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
959 {
960 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
961 .name = "Capture Source",
962 .info = ad198x_mux_enum_info,
963 .get = ad198x_mux_enum_get,
964 .put = ad198x_mux_enum_put,
965 },
966 {
967 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +0200968 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200969 .info = ad1983_spdif_route_info,
970 .get = ad1983_spdif_route_get,
971 .put = ad1983_spdif_route_put,
972 },
973 { } /* end */
974};
975
976static struct hda_verb ad1983_init_verbs[] = {
977 /* Front, HP, Mono; mute as default */
978 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
979 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
980 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
981 /* Beep, PCM, Mic, Line-In: mute */
982 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
983 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
984 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
985 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
986 /* Front, HP selectors; from Mix */
987 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
988 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
989 /* Mono selector; from Mix */
990 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
991 /* Mic selector; Mic */
992 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
993 /* Line-in selector: Line-in */
994 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
995 /* Mic boost: 0dB */
996 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
997 /* Record selector: mic */
998 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
999 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1000 /* SPDIF route: PCM */
1001 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1002 /* Front Pin */
1003 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1004 /* HP Pin */
1005 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1006 /* Mono Pin */
1007 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1008 /* Mic Pin */
1009 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1010 /* Line Pin */
1011 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1012 { } /* end */
1013};
1014
Takashi Iwai985be542005-11-02 18:26:49 +01001015
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001016static int patch_ad1983(struct hda_codec *codec)
1017{
1018 struct ad198x_spec *spec;
1019
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001020 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001021 if (spec == NULL)
1022 return -ENOMEM;
1023
Ingo Molnar62932df2006-01-16 16:34:20 +01001024 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001025 codec->spec = spec;
1026
1027 spec->multiout.max_channels = 2;
1028 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1029 spec->multiout.dac_nids = ad1983_dac_nids;
1030 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001031 spec->num_adc_nids = 1;
1032 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001033 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001034 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001035 spec->num_mixers = 1;
1036 spec->mixers[0] = ad1983_mixers;
1037 spec->num_init_verbs = 1;
1038 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001039 spec->spdif_route = 0;
1040
1041 codec->patch_ops = ad198x_patch_ops;
1042
1043 return 0;
1044}
1045
1046
1047/*
1048 * AD1981 HD specific
1049 */
1050
1051#define AD1981_SPDIF_OUT 0x02
1052#define AD1981_DAC 0x03
1053#define AD1981_ADC 0x04
1054
1055static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001056static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001057static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001058
1059/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1060static struct hda_input_mux ad1981_capture_source = {
1061 .num_items = 7,
1062 .items = {
1063 { "Front Mic", 0x0 },
1064 { "Line", 0x1 },
1065 { "Mix", 0x2 },
1066 { "Mix Mono", 0x3 },
1067 { "CD", 0x4 },
1068 { "Mic", 0x6 },
1069 { "Aux", 0x7 },
1070 },
1071};
1072
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001073static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001074 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1075 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1077 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1078 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1079 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1080 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1081 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1082 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1083 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1084 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1085 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1086 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1087 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1088 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1089 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1090 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1091 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1092 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1093 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1094 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1095 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1096 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1097 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1098 {
1099 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1100 .name = "Capture Source",
1101 .info = ad198x_mux_enum_info,
1102 .get = ad198x_mux_enum_get,
1103 .put = ad198x_mux_enum_put,
1104 },
1105 /* identical with AD1983 */
1106 {
1107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001108 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001109 .info = ad1983_spdif_route_info,
1110 .get = ad1983_spdif_route_get,
1111 .put = ad1983_spdif_route_put,
1112 },
1113 { } /* end */
1114};
1115
1116static struct hda_verb ad1981_init_verbs[] = {
1117 /* Front, HP, Mono; mute as default */
1118 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1119 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1120 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1121 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1122 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1123 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1124 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1125 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1126 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1127 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1128 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1129 /* Front, HP selectors; from Mix */
1130 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1131 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1132 /* Mono selector; from Mix */
1133 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1134 /* Mic Mixer; select Front Mic */
1135 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1136 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1137 /* Mic boost: 0dB */
1138 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1139 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1140 /* Record selector: Front mic */
1141 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1142 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1143 /* SPDIF route: PCM */
1144 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1145 /* Front Pin */
1146 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1147 /* HP Pin */
1148 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1149 /* Mono Pin */
1150 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1151 /* Front & Rear Mic Pins */
1152 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1153 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1154 /* Line Pin */
1155 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1156 /* Digital Beep */
1157 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1158 /* Line-Out as Input: disabled */
1159 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1160 { } /* end */
1161};
1162
Takashi Iwai18a815d2006-03-01 19:54:39 +01001163/*
1164 * Patch for HP nx6320
1165 *
1166 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
1167 * speaker output enabled _and_ mute-LED off.
1168 */
1169
1170#define AD1981_HP_EVENT 0x37
1171#define AD1981_MIC_EVENT 0x38
1172
1173static struct hda_verb ad1981_hp_init_verbs[] = {
1174 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1175 /* pin sensing on HP and Mic jacks */
1176 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1177 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1178 {}
1179};
1180
1181/* turn on/off EAPD (+ mute HP) as a master switch */
1182static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1183 struct snd_ctl_elem_value *ucontrol)
1184{
1185 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1186 struct ad198x_spec *spec = codec->spec;
1187
1188 if (! ad198x_eapd_put(kcontrol, ucontrol))
1189 return 0;
1190
1191 /* toggle HP mute appropriately */
1192 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1193 0x80, spec->cur_eapd ? 0 : 0x80);
1194 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1195 0x80, spec->cur_eapd ? 0 : 0x80);
1196 return 1;
1197}
1198
1199/* bind volumes of both NID 0x05 and 0x06 */
1200static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1201 struct snd_ctl_elem_value *ucontrol)
1202{
1203 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1204 long *valp = ucontrol->value.integer.value;
1205 int change;
1206
1207 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1208 0x7f, valp[0] & 0x7f);
1209 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1210 0x7f, valp[1] & 0x7f);
1211 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1212 0x7f, valp[0] & 0x7f);
1213 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1214 0x7f, valp[1] & 0x7f);
1215 return change;
1216}
1217
1218/* mute internal speaker if HP is plugged */
1219static void ad1981_hp_automute(struct hda_codec *codec)
1220{
1221 unsigned int present;
1222
1223 present = snd_hda_codec_read(codec, 0x06, 0,
1224 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1225 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1226 0x80, present ? 0x80 : 0);
1227 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1228 0x80, present ? 0x80 : 0);
1229}
1230
1231/* toggle input of built-in and mic jack appropriately */
1232static void ad1981_hp_automic(struct hda_codec *codec)
1233{
1234 static struct hda_verb mic_jack_on[] = {
1235 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1236 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1237 {}
1238 };
1239 static struct hda_verb mic_jack_off[] = {
1240 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1241 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1242 {}
1243 };
1244 unsigned int present;
1245
1246 present = snd_hda_codec_read(codec, 0x08, 0,
1247 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1248 if (present)
1249 snd_hda_sequence_write(codec, mic_jack_on);
1250 else
1251 snd_hda_sequence_write(codec, mic_jack_off);
1252}
1253
1254/* unsolicited event for HP jack sensing */
1255static void ad1981_hp_unsol_event(struct hda_codec *codec,
1256 unsigned int res)
1257{
1258 res >>= 26;
1259 switch (res) {
1260 case AD1981_HP_EVENT:
1261 ad1981_hp_automute(codec);
1262 break;
1263 case AD1981_MIC_EVENT:
1264 ad1981_hp_automic(codec);
1265 break;
1266 }
1267}
1268
1269static struct hda_input_mux ad1981_hp_capture_source = {
1270 .num_items = 3,
1271 .items = {
1272 { "Mic", 0x0 },
1273 { "Docking-Station", 0x1 },
1274 { "Mix", 0x2 },
1275 },
1276};
1277
1278static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1279 {
1280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1281 .name = "Master Playback Volume",
1282 .info = snd_hda_mixer_amp_volume_info,
1283 .get = snd_hda_mixer_amp_volume_get,
1284 .put = ad1981_hp_master_vol_put,
1285 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1286 },
1287 {
1288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1289 .name = "Master Playback Switch",
1290 .info = ad198x_eapd_info,
1291 .get = ad198x_eapd_get,
1292 .put = ad1981_hp_master_sw_put,
1293 .private_value = 0x05,
1294 },
1295 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1296 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1297#if 0
1298 /* FIXME: analog mic/line loopback doesn't work with my tests...
1299 * (although recording is OK)
1300 */
1301 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1302 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1303 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1304 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1305 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1306 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1307 /* FIXME: does this laptop have analog CD connection? */
1308 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1309 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1310#endif
1311 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1312 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1313 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1314 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1315 {
1316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1317 .name = "Capture Source",
1318 .info = ad198x_mux_enum_info,
1319 .get = ad198x_mux_enum_get,
1320 .put = ad198x_mux_enum_put,
1321 },
1322 { } /* end */
1323};
1324
1325/* initialize jack-sensing, too */
1326static int ad1981_hp_init(struct hda_codec *codec)
1327{
1328 ad198x_init(codec);
1329 ad1981_hp_automute(codec);
1330 ad1981_hp_automic(codec);
1331 return 0;
1332}
1333
Takashi Iwai01686c52006-04-18 12:54:11 +02001334/* configuration for Lenovo Thinkpad T60 */
1335static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1336 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1337 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1338 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1339 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1340 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1341 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1342 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1343 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1344 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1345 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1346 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1347 {
1348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1349 .name = "Capture Source",
1350 .info = ad198x_mux_enum_info,
1351 .get = ad198x_mux_enum_get,
1352 .put = ad198x_mux_enum_put,
1353 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001354 /* identical with AD1983 */
1355 {
1356 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1357 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1358 .info = ad1983_spdif_route_info,
1359 .get = ad1983_spdif_route_get,
1360 .put = ad1983_spdif_route_put,
1361 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001362 { } /* end */
1363};
1364
1365static struct hda_input_mux ad1981_thinkpad_capture_source = {
1366 .num_items = 3,
1367 .items = {
1368 { "Mic", 0x0 },
1369 { "Mix", 0x2 },
1370 { "CD", 0x4 },
1371 },
1372};
1373
Takashi Iwai18a815d2006-03-01 19:54:39 +01001374/* models */
Takashi Iwai01686c52006-04-18 12:54:11 +02001375enum { AD1981_BASIC, AD1981_HP, AD1981_THINKPAD };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001376
1377static struct hda_board_config ad1981_cfg_tbl[] = {
1378 { .modelname = "hp", .config = AD1981_HP },
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001379 /* All HP models */
1380 { .pci_subvendor = 0x103c, .config = AD1981_HP },
Takashi Iwaif8e9f342006-06-01 21:08:53 +02001381 { .pci_subvendor = 0x30b0, .pci_subdevice = 0x103c,
1382 .config = AD1981_HP }, /* HP nx6320 (reversed SSID, H/W bug) */
Takashi Iwai01686c52006-04-18 12:54:11 +02001383 { .modelname = "thinkpad", .config = AD1981_THINKPAD },
1384 /* Lenovo Thinkpad T60/X60/Z6xx */
1385 { .pci_subvendor = 0x17aa, .config = AD1981_THINKPAD },
Takashi Iwai887709b2006-04-18 13:27:31 +02001386 { .pci_subvendor = 0x1014, .pci_subdevice = 0x0597,
Takashi Iwai01686c52006-04-18 12:54:11 +02001387 .config = AD1981_THINKPAD }, /* Z60m/t */
Takashi Iwai18a815d2006-03-01 19:54:39 +01001388 { .modelname = "basic", .config = AD1981_BASIC },
1389 {}
1390};
1391
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001392static int patch_ad1981(struct hda_codec *codec)
1393{
1394 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001395 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001396
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001397 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001398 if (spec == NULL)
1399 return -ENOMEM;
1400
Ingo Molnar62932df2006-01-16 16:34:20 +01001401 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001402 codec->spec = spec;
1403
1404 spec->multiout.max_channels = 2;
1405 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1406 spec->multiout.dac_nids = ad1981_dac_nids;
1407 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001408 spec->num_adc_nids = 1;
1409 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001410 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001411 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001412 spec->num_mixers = 1;
1413 spec->mixers[0] = ad1981_mixers;
1414 spec->num_init_verbs = 1;
1415 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001416 spec->spdif_route = 0;
1417
1418 codec->patch_ops = ad198x_patch_ops;
1419
Takashi Iwai18a815d2006-03-01 19:54:39 +01001420 /* override some parameters */
1421 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1422 switch (board_config) {
1423 case AD1981_HP:
1424 spec->mixers[0] = ad1981_hp_mixers;
1425 spec->num_init_verbs = 2;
1426 spec->init_verbs[1] = ad1981_hp_init_verbs;
1427 spec->multiout.dig_out_nid = 0;
1428 spec->input_mux = &ad1981_hp_capture_source;
1429
1430 codec->patch_ops.init = ad1981_hp_init;
1431 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1432 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001433 case AD1981_THINKPAD:
1434 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001435 spec->input_mux = &ad1981_thinkpad_capture_source;
1436 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001437 }
1438
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001439 return 0;
1440}
1441
1442
1443/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001444 * AD1988
1445 *
1446 * Output pins and routes
1447 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001448 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001449 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1450 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1451 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1452 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1453 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1454 * port-F 0x16 (mute) <- 0x2a <- 06
1455 * port-G 0x24 (mute) <- 0x27 <- 05
1456 * port-H 0x25 (mute) <- 0x28 <- 0a
1457 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1458 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001459 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1460 * (*) 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 +01001461 *
1462 * Input pins and routes
1463 *
1464 * pin boost mix input # / adc input #
1465 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1466 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1467 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1468 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1469 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1470 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1471 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1472 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1473 *
1474 *
1475 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001476 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001477 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001478 *
1479 * Inputs of Analog Mix (0x20)
1480 * 0:Port-B (front mic)
1481 * 1:Port-C/G/H (line-in)
1482 * 2:Port-A
1483 * 3:Port-D (line-in/2)
1484 * 4:Port-E/G/H (mic-in)
1485 * 5:Port-F (mic2-in)
1486 * 6:CD
1487 * 7:Beep
1488 *
1489 * ADC selection
1490 * 0:Port-A
1491 * 1:Port-B (front mic-in)
1492 * 2:Port-C (line-in)
1493 * 3:Port-F (mic2-in)
1494 * 4:Port-E (mic-in)
1495 * 5:CD
1496 * 6:Port-G
1497 * 7:Port-H
1498 * 8:Port-D (line-in/2)
1499 * 9:Mix
1500 *
1501 * Proposed pin assignments by the datasheet
1502 *
1503 * 6-stack
1504 * Port-A front headphone
1505 * B front mic-in
1506 * C rear line-in
1507 * D rear front-out
1508 * E rear mic-in
1509 * F rear surround
1510 * G rear CLFE
1511 * H rear side
1512 *
1513 * 3-stack
1514 * Port-A front headphone
1515 * B front mic
1516 * C rear line-in/surround
1517 * D rear front-out
1518 * E rear mic-in/CLFE
1519 *
1520 * laptop
1521 * Port-A headphone
1522 * B mic-in
1523 * C docking station
1524 * D internal speaker (with EAPD)
1525 * E/F quad mic array
1526 */
1527
1528
1529/* models */
1530enum {
1531 AD1988_6STACK,
1532 AD1988_6STACK_DIG,
1533 AD1988_3STACK,
1534 AD1988_3STACK_DIG,
1535 AD1988_LAPTOP,
1536 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001537 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001538 AD1988_MODEL_LAST,
1539};
1540
Takashi Iwaid32410b12005-11-24 16:06:23 +01001541/* reivision id to check workarounds */
1542#define AD1988A_REV2 0x100200
1543
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001544
1545/*
1546 * mixers
1547 */
1548
Takashi Iwaid32410b12005-11-24 16:06:23 +01001549static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001550 0x04, 0x06, 0x05, 0x0a
1551};
1552
Takashi Iwaid32410b12005-11-24 16:06:23 +01001553static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001554 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001555};
1556
1557/* for AD1988A revision-2, DAC2-4 are swapped */
1558static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1559 0x04, 0x05, 0x0a, 0x06
1560};
1561
1562static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001563 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001564};
1565
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001566static hda_nid_t ad1988_adc_nids[3] = {
1567 0x08, 0x09, 0x0f
1568};
1569
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001570static hda_nid_t ad1988_capsrc_nids[3] = {
1571 0x0c, 0x0d, 0x0e
1572};
1573
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001574#define AD1988_SPDIF_OUT 0x02
1575#define AD1988_SPDIF_IN 0x07
1576
1577static struct hda_input_mux ad1988_6stack_capture_source = {
1578 .num_items = 5,
1579 .items = {
1580 { "Front Mic", 0x0 },
1581 { "Line", 0x1 },
1582 { "Mic", 0x4 },
1583 { "CD", 0x5 },
1584 { "Mix", 0x9 },
1585 },
1586};
1587
1588static struct hda_input_mux ad1988_laptop_capture_source = {
1589 .num_items = 3,
1590 .items = {
1591 { "Mic/Line", 0x0 },
1592 { "CD", 0x5 },
1593 { "Mix", 0x9 },
1594 },
1595};
1596
1597/*
1598 */
1599static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1600 struct snd_ctl_elem_info *uinfo)
1601{
1602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1603 struct ad198x_spec *spec = codec->spec;
1604 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1605 spec->num_channel_mode);
1606}
1607
1608static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1609 struct snd_ctl_elem_value *ucontrol)
1610{
1611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1612 struct ad198x_spec *spec = codec->spec;
1613 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1614 spec->num_channel_mode, spec->multiout.max_channels);
1615}
1616
1617static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1618 struct snd_ctl_elem_value *ucontrol)
1619{
1620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1621 struct ad198x_spec *spec = codec->spec;
Takashi Iwai2125cad2006-03-27 12:52:22 +02001622 if (spec->need_dac_fix)
1623 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001624 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1625 spec->num_channel_mode, &spec->multiout.max_channels);
1626}
1627
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001628/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001629static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001630 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1633 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1634 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001635};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001636
Takashi Iwaid32410b12005-11-24 16:06:23 +01001637static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1638 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1639 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1640 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1641 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1642 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1643};
1644
1645static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001646 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1647 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1648 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1649 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1650 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1651 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1652 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1653
1654 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1655 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1656 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1657 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1658 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1659 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1660 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1661 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1662
1663 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1664 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1665
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001666 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001667 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1668
1669 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1670 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1671
1672 { } /* end */
1673};
1674
1675/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001676static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001677 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001678 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001679 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001681};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001682
Takashi Iwaid32410b12005-11-24 16:06:23 +01001683static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1684 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001685 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1686 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1687 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001688};
1689
1690static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001691 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001692 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1693 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1694 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001695 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1696 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1697
1698 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1699 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1700 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1701 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1702 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1703 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1704 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1705 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1706
1707 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1708 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1709
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001710 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001711 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1712
1713 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1714 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1715 {
1716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1717 .name = "Channel Mode",
1718 .info = ad198x_ch_mode_info,
1719 .get = ad198x_ch_mode_get,
1720 .put = ad198x_ch_mode_put,
1721 },
1722
1723 { } /* end */
1724};
1725
1726/* laptop mode */
1727static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1728 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1729 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1730 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1731
1732 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1733 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1734 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1735 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1736 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1737 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1738
1739 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1740 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1741
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001742 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001743 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1744
1745 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1746
1747 {
1748 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1749 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001750 .info = ad198x_eapd_info,
1751 .get = ad198x_eapd_get,
1752 .put = ad198x_eapd_put,
1753 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001754 },
1755
1756 { } /* end */
1757};
1758
1759/* capture */
1760static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1761 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1762 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1763 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1764 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1765 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1766 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1767 {
1768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1769 /* The multiple "Capture Source" controls confuse alsamixer
1770 * So call somewhat different..
1771 * FIXME: the controls appear in the "playback" view!
1772 */
1773 /* .name = "Capture Source", */
1774 .name = "Input Source",
1775 .count = 3,
1776 .info = ad198x_mux_enum_info,
1777 .get = ad198x_mux_enum_get,
1778 .put = ad198x_mux_enum_put,
1779 },
1780 { } /* end */
1781};
1782
1783static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1784 struct snd_ctl_elem_info *uinfo)
1785{
1786 static char *texts[] = {
1787 "PCM", "ADC1", "ADC2", "ADC3"
1788 };
1789 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1790 uinfo->count = 1;
1791 uinfo->value.enumerated.items = 4;
1792 if (uinfo->value.enumerated.item >= 4)
1793 uinfo->value.enumerated.item = 3;
1794 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1795 return 0;
1796}
1797
1798static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1799 struct snd_ctl_elem_value *ucontrol)
1800{
1801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1802 unsigned int sel;
1803
1804 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1805 if (sel > 0) {
1806 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1807 if (sel <= 3)
1808 sel++;
1809 else
1810 sel = 0;
1811 }
1812 ucontrol->value.enumerated.item[0] = sel;
1813 return 0;
1814}
1815
1816static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1817 struct snd_ctl_elem_value *ucontrol)
1818{
1819 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1820 unsigned int sel;
1821 int change;
1822
1823 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1824 if (! ucontrol->value.enumerated.item[0]) {
1825 change = sel != 0;
1826 if (change)
1827 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1828 } else {
1829 change = sel == 0;
1830 if (change)
1831 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1832 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1833 change |= sel == ucontrol->value.enumerated.item[0];
1834 if (change)
1835 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1836 ucontrol->value.enumerated.item[0] - 1);
1837 }
1838 return change;
1839}
1840
1841static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1842 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1843 {
1844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1845 .name = "IEC958 Playback Source",
1846 .info = ad1988_spdif_playback_source_info,
1847 .get = ad1988_spdif_playback_source_get,
1848 .put = ad1988_spdif_playback_source_put,
1849 },
1850 { } /* end */
1851};
1852
1853static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1854 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1855 { } /* end */
1856};
1857
1858
1859/*
1860 * initialization verbs
1861 */
1862
1863/*
1864 * for 6-stack (+dig)
1865 */
1866static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001867 /* Front, Surround, CLFE, side DAC; unmute as default */
1868 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1869 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1870 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1871 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001872 /* Port-A front headphon path */
1873 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1874 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1875 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1876 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1877 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878 /* Port-D line-out path */
1879 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1880 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1881 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1882 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1883 /* Port-F surround path */
1884 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1885 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1887 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1888 /* Port-G CLFE path */
1889 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1890 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1891 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1892 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1893 /* Port-H side path */
1894 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1895 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1896 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1898 /* Mono out path */
1899 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1900 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1901 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1902 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1903 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1904 /* Port-B front mic-in path */
1905 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1906 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1907 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1908 /* Port-C line-in path */
1909 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1910 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1911 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1912 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1913 /* Port-E mic-in path */
1914 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1915 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1916 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1917 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1918
1919 { }
1920};
1921
1922static struct hda_verb ad1988_capture_init_verbs[] = {
1923 /* mute analog mix */
1924 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1925 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1926 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1927 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1928 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1929 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1930 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1931 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1932 /* select ADCs - front-mic */
1933 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1934 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1935 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1936 /* ADCs; muted */
1937 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1938 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1939 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1940
1941 { }
1942};
1943
1944static struct hda_verb ad1988_spdif_init_verbs[] = {
1945 /* SPDIF out sel */
1946 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1947 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1948 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1949 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1950 /* SPDIF out pin */
1951 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1952 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1953
1954 { }
1955};
1956
1957/*
1958 * verbs for 3stack (+dig)
1959 */
1960static struct hda_verb ad1988_3stack_ch2_init[] = {
1961 /* set port-C to line-in */
1962 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1963 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1964 /* set port-E to mic-in */
1965 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1966 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1967 { } /* end */
1968};
1969
1970static struct hda_verb ad1988_3stack_ch6_init[] = {
1971 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001972 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001973 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001974 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001975 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001976 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001977 { } /* end */
1978};
1979
1980static struct hda_channel_mode ad1988_3stack_modes[2] = {
1981 { 2, ad1988_3stack_ch2_init },
1982 { 6, ad1988_3stack_ch6_init },
1983};
1984
1985static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001986 /* Front, Surround, CLFE, side DAC; unmute as default */
1987 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1988 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1989 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1990 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001991 /* Port-A front headphon path */
1992 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1993 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1994 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1995 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1996 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1997 /* Port-D line-out path */
1998 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1999 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2000 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2001 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2002 /* Mono out path */
2003 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2004 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2005 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2006 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2007 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2008 /* Port-B front mic-in path */
2009 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2010 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2011 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002012 /* Port-C line-in/surround path - 6ch mode as default */
2013 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2014 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002015 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002016 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002017 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002018 /* Port-E mic-in/CLFE path - 6ch mode as default */
2019 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2020 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002021 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002022 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002023 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2024 /* mute analog mix */
2025 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2026 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2027 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2028 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2029 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2030 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2031 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2032 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2033 /* select ADCs - front-mic */
2034 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2035 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2036 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2037 /* ADCs; muted */
2038 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2039 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2040 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2041 { }
2042};
2043
2044/*
2045 * verbs for laptop mode (+dig)
2046 */
2047static struct hda_verb ad1988_laptop_hp_on[] = {
2048 /* unmute port-A and mute port-D */
2049 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2050 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2051 { } /* end */
2052};
2053static struct hda_verb ad1988_laptop_hp_off[] = {
2054 /* mute port-A and unmute port-D */
2055 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2056 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2057 { } /* end */
2058};
2059
2060#define AD1988_HP_EVENT 0x01
2061
2062static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002063 /* Front, Surround, CLFE, side DAC; unmute as default */
2064 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2065 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2066 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2067 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002068 /* Port-A front headphon path */
2069 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2070 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2071 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2072 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2073 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2074 /* unsolicited event for pin-sense */
2075 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2076 /* Port-D line-out path + EAPD */
2077 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2078 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2079 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2080 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2081 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2082 /* Mono out path */
2083 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2084 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2085 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2086 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2087 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2088 /* Port-B mic-in path */
2089 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2090 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2091 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2092 /* Port-C docking station - try to output */
2093 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2094 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2095 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2096 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2097 /* mute analog mix */
2098 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2099 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2100 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2101 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2102 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2103 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2104 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2105 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2106 /* select ADCs - mic */
2107 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2108 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2109 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2110 /* ADCs; muted */
2111 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2112 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2113 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2114 { }
2115};
2116
2117static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2118{
2119 if ((res >> 26) != AD1988_HP_EVENT)
2120 return;
2121 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2122 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2123 else
2124 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2125}
2126
2127
2128/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002129 * Automatic parse of I/O pins from the BIOS configuration
2130 */
2131
2132#define NUM_CONTROL_ALLOC 32
2133#define NUM_VERB_ALLOC 32
2134
2135enum {
2136 AD_CTL_WIDGET_VOL,
2137 AD_CTL_WIDGET_MUTE,
2138 AD_CTL_BIND_MUTE,
2139};
2140static struct snd_kcontrol_new ad1988_control_templates[] = {
2141 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2142 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2143 HDA_BIND_MUTE(NULL, 0, 0, 0),
2144};
2145
2146/* add dynamic controls */
2147static int add_control(struct ad198x_spec *spec, int type, const char *name,
2148 unsigned long val)
2149{
2150 struct snd_kcontrol_new *knew;
2151
2152 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2153 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2154
2155 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2156 if (! knew)
2157 return -ENOMEM;
2158 if (spec->kctl_alloc) {
2159 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2160 kfree(spec->kctl_alloc);
2161 }
2162 spec->kctl_alloc = knew;
2163 spec->num_kctl_alloc = num;
2164 }
2165
2166 knew = &spec->kctl_alloc[spec->num_kctl_used];
2167 *knew = ad1988_control_templates[type];
2168 knew->name = kstrdup(name, GFP_KERNEL);
2169 if (! knew->name)
2170 return -ENOMEM;
2171 knew->private_value = val;
2172 spec->num_kctl_used++;
2173 return 0;
2174}
2175
2176#define AD1988_PIN_CD_NID 0x18
2177#define AD1988_PIN_BEEP_NID 0x10
2178
2179static hda_nid_t ad1988_mixer_nids[8] = {
2180 /* A B C D E F G H */
2181 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2182};
2183
2184static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2185{
2186 static hda_nid_t idx_to_dac[8] = {
2187 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002188 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002189 };
2190 static hda_nid_t idx_to_dac_rev2[8] = {
2191 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002192 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002193 };
2194 if (codec->revision_id == AD1988A_REV2)
2195 return idx_to_dac_rev2[idx];
2196 else
2197 return idx_to_dac[idx];
2198}
2199
2200static hda_nid_t ad1988_boost_nids[8] = {
2201 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2202};
2203
2204static int ad1988_pin_idx(hda_nid_t nid)
2205{
2206 static hda_nid_t ad1988_io_pins[8] = {
2207 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2208 };
2209 int i;
2210 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2211 if (ad1988_io_pins[i] == nid)
2212 return i;
2213 return 0; /* should be -1 */
2214}
2215
2216static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2217{
2218 static int loopback_idx[8] = {
2219 2, 0, 1, 3, 4, 5, 1, 4
2220 };
2221 switch (nid) {
2222 case AD1988_PIN_CD_NID:
2223 return 6;
2224 default:
2225 return loopback_idx[ad1988_pin_idx(nid)];
2226 }
2227}
2228
2229static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2230{
2231 static int adc_idx[8] = {
2232 0, 1, 2, 8, 4, 3, 6, 7
2233 };
2234 switch (nid) {
2235 case AD1988_PIN_CD_NID:
2236 return 5;
2237 default:
2238 return adc_idx[ad1988_pin_idx(nid)];
2239 }
2240}
2241
2242/* fill in the dac_nids table from the parsed pin configuration */
2243static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2244 const struct auto_pin_cfg *cfg)
2245{
2246 struct ad198x_spec *spec = codec->spec;
2247 int i, idx;
2248
2249 spec->multiout.dac_nids = spec->private_dac_nids;
2250
2251 /* check the pins hardwired to audio widget */
2252 for (i = 0; i < cfg->line_outs; i++) {
2253 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2254 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2255 }
2256 spec->multiout.num_dacs = cfg->line_outs;
2257 return 0;
2258}
2259
2260/* add playback controls from the parsed DAC table */
2261static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2262 const struct auto_pin_cfg *cfg)
2263{
2264 char name[32];
2265 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2266 hda_nid_t nid;
2267 int i, err;
2268
2269 for (i = 0; i < cfg->line_outs; i++) {
2270 hda_nid_t dac = spec->multiout.dac_nids[i];
2271 if (! dac)
2272 continue;
2273 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2274 if (i == 2) {
2275 /* Center/LFE */
2276 err = add_control(spec, AD_CTL_WIDGET_VOL,
2277 "Center Playback Volume",
2278 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2279 if (err < 0)
2280 return err;
2281 err = add_control(spec, AD_CTL_WIDGET_VOL,
2282 "LFE Playback Volume",
2283 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2284 if (err < 0)
2285 return err;
2286 err = add_control(spec, AD_CTL_BIND_MUTE,
2287 "Center Playback Switch",
2288 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2289 if (err < 0)
2290 return err;
2291 err = add_control(spec, AD_CTL_BIND_MUTE,
2292 "LFE Playback Switch",
2293 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2294 if (err < 0)
2295 return err;
2296 } else {
2297 sprintf(name, "%s Playback Volume", chname[i]);
2298 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2299 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2300 if (err < 0)
2301 return err;
2302 sprintf(name, "%s Playback Switch", chname[i]);
2303 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2304 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2305 if (err < 0)
2306 return err;
2307 }
2308 }
2309 return 0;
2310}
2311
2312/* add playback controls for speaker and HP outputs */
2313static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2314 const char *pfx)
2315{
2316 struct ad198x_spec *spec = codec->spec;
2317 hda_nid_t nid;
2318 int idx, err;
2319 char name[32];
2320
2321 if (! pin)
2322 return 0;
2323
2324 idx = ad1988_pin_idx(pin);
2325 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002326 /* specify the DAC as the extra output */
2327 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002328 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002329 else
2330 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002331 /* control HP volume/switch on the output mixer amp */
2332 sprintf(name, "%s Playback Volume", pfx);
2333 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2334 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2335 return err;
2336 nid = ad1988_mixer_nids[idx];
2337 sprintf(name, "%s Playback Switch", pfx);
2338 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2339 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2340 return err;
2341 return 0;
2342}
2343
2344/* create input playback/capture controls for the given pin */
2345static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2346 const char *ctlname, int boost)
2347{
2348 char name[32];
2349 int err, idx;
2350
2351 sprintf(name, "%s Playback Volume", ctlname);
2352 idx = ad1988_pin_to_loopback_idx(pin);
2353 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2354 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2355 return err;
2356 sprintf(name, "%s Playback Switch", ctlname);
2357 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2358 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2359 return err;
2360 if (boost) {
2361 hda_nid_t bnid;
2362 idx = ad1988_pin_idx(pin);
2363 bnid = ad1988_boost_nids[idx];
2364 if (bnid) {
2365 sprintf(name, "%s Boost", ctlname);
2366 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2367 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2368
2369 }
2370 }
2371 return 0;
2372}
2373
2374/* create playback/capture controls for input pins */
2375static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2376 const struct auto_pin_cfg *cfg)
2377{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002378 struct hda_input_mux *imux = &spec->private_imux;
2379 int i, err;
2380
2381 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002382 err = new_analog_input(spec, cfg->input_pins[i],
2383 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002384 i <= AUTO_PIN_FRONT_MIC);
2385 if (err < 0)
2386 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002387 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002388 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2389 imux->num_items++;
2390 }
2391 imux->items[imux->num_items].label = "Mix";
2392 imux->items[imux->num_items].index = 9;
2393 imux->num_items++;
2394
2395 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2396 "Analog Mix Playback Volume",
2397 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2398 return err;
2399 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2400 "Analog Mix Playback Switch",
2401 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2402 return err;
2403
2404 return 0;
2405}
2406
2407static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2408 hda_nid_t nid, int pin_type,
2409 int dac_idx)
2410{
2411 /* set as output */
2412 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2413 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2414 switch (nid) {
2415 case 0x11: /* port-A - DAC 04 */
2416 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2417 break;
2418 case 0x14: /* port-B - DAC 06 */
2419 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2420 break;
2421 case 0x15: /* port-C - DAC 05 */
2422 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2423 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002424 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002425 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2426 break;
2427 case 0x13: /* mono - DAC 04 */
2428 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2429 break;
2430 }
2431}
2432
2433static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2434{
2435 struct ad198x_spec *spec = codec->spec;
2436 int i;
2437
2438 for (i = 0; i < spec->autocfg.line_outs; i++) {
2439 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2440 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2441 }
2442}
2443
2444static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2445{
2446 struct ad198x_spec *spec = codec->spec;
2447 hda_nid_t pin;
2448
Takashi Iwai82bc9552006-03-21 11:24:42 +01002449 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002450 if (pin) /* connect to front */
2451 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2452 pin = spec->autocfg.hp_pin;
2453 if (pin) /* connect to front */
2454 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2455}
2456
2457static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2458{
2459 struct ad198x_spec *spec = codec->spec;
2460 int i, idx;
2461
2462 for (i = 0; i < AUTO_PIN_LAST; i++) {
2463 hda_nid_t nid = spec->autocfg.input_pins[i];
2464 if (! nid)
2465 continue;
2466 switch (nid) {
2467 case 0x15: /* port-C */
2468 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2469 break;
2470 case 0x17: /* port-E */
2471 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2472 break;
2473 }
2474 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2475 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2476 if (nid != AD1988_PIN_CD_NID)
2477 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2478 AMP_OUT_MUTE);
2479 idx = ad1988_pin_idx(nid);
2480 if (ad1988_boost_nids[idx])
2481 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2482 AC_VERB_SET_AMP_GAIN_MUTE,
2483 AMP_OUT_ZERO);
2484 }
2485}
2486
2487/* parse the BIOS configuration and set up the alc_spec */
2488/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2489static int ad1988_parse_auto_config(struct hda_codec *codec)
2490{
2491 struct ad198x_spec *spec = codec->spec;
2492 int err;
2493
Kailang Yangdf694da2005-12-05 19:42:22 +01002494 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002495 return err;
2496 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2497 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002498 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002499 return 0; /* can't find valid BIOS pin config */
2500 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002501 (err = ad1988_auto_create_extra_out(codec,
2502 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002503 "Speaker")) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002504 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pin,
Takashi Iwaid32410b12005-11-24 16:06:23 +01002505 "Headphone")) < 0 ||
2506 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2507 return err;
2508
2509 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2510
2511 if (spec->autocfg.dig_out_pin)
2512 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2513 if (spec->autocfg.dig_in_pin)
2514 spec->dig_in_nid = AD1988_SPDIF_IN;
2515
2516 if (spec->kctl_alloc)
2517 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2518
2519 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2520
2521 spec->input_mux = &spec->private_imux;
2522
2523 return 1;
2524}
2525
2526/* init callback for auto-configuration model -- overriding the default init */
2527static int ad1988_auto_init(struct hda_codec *codec)
2528{
2529 ad198x_init(codec);
2530 ad1988_auto_init_multi_out(codec);
2531 ad1988_auto_init_extra_out(codec);
2532 ad1988_auto_init_analog_input(codec);
2533 return 0;
2534}
2535
2536
2537/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002538 */
2539
2540static struct hda_board_config ad1988_cfg_tbl[] = {
2541 { .modelname = "6stack", .config = AD1988_6STACK },
2542 { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
2543 { .modelname = "3stack", .config = AD1988_3STACK },
2544 { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
2545 { .modelname = "laptop", .config = AD1988_LAPTOP },
2546 { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002547 { .modelname = "auto", .config = AD1988_AUTO },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002548 {}
2549};
2550
2551static int patch_ad1988(struct hda_codec *codec)
2552{
2553 struct ad198x_spec *spec;
2554 int board_config;
2555
2556 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2557 if (spec == NULL)
2558 return -ENOMEM;
2559
Ingo Molnar62932df2006-01-16 16:34:20 +01002560 mutex_init(&spec->amp_mutex);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002561 codec->spec = spec;
2562
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002563 if (codec->revision_id == AD1988A_REV2)
2564 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2565
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002566 board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2567 if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002568 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2569 board_config = AD1988_AUTO;
2570 }
2571
2572 if (board_config == AD1988_AUTO) {
2573 /* automatic parse from the BIOS config */
2574 int err = ad1988_parse_auto_config(codec);
2575 if (err < 0) {
2576 ad198x_free(codec);
2577 return err;
2578 } else if (! err) {
2579 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2580 board_config = AD1988_6STACK;
2581 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002582 }
2583
2584 switch (board_config) {
2585 case AD1988_6STACK:
2586 case AD1988_6STACK_DIG:
2587 spec->multiout.max_channels = 8;
2588 spec->multiout.num_dacs = 4;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002589 if (codec->revision_id == AD1988A_REV2)
2590 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2591 else
2592 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002593 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002594 spec->num_mixers = 2;
2595 if (codec->revision_id == AD1988A_REV2)
2596 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2597 else
2598 spec->mixers[0] = ad1988_6stack_mixers1;
2599 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002600 spec->num_init_verbs = 1;
2601 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2602 if (board_config == AD1988_6STACK_DIG) {
2603 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2604 spec->dig_in_nid = AD1988_SPDIF_IN;
2605 }
2606 break;
2607 case AD1988_3STACK:
2608 case AD1988_3STACK_DIG:
2609 spec->multiout.max_channels = 6;
2610 spec->multiout.num_dacs = 3;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002611 if (codec->revision_id == AD1988A_REV2)
2612 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2613 else
2614 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002615 spec->input_mux = &ad1988_6stack_capture_source;
2616 spec->channel_mode = ad1988_3stack_modes;
2617 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002618 spec->num_mixers = 2;
2619 if (codec->revision_id == AD1988A_REV2)
2620 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2621 else
2622 spec->mixers[0] = ad1988_3stack_mixers1;
2623 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002624 spec->num_init_verbs = 1;
2625 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2626 if (board_config == AD1988_3STACK_DIG)
2627 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2628 break;
2629 case AD1988_LAPTOP:
2630 case AD1988_LAPTOP_DIG:
2631 spec->multiout.max_channels = 2;
2632 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002633 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002634 spec->input_mux = &ad1988_laptop_capture_source;
2635 spec->num_mixers = 1;
2636 spec->mixers[0] = ad1988_laptop_mixers;
2637 spec->num_init_verbs = 1;
2638 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2639 if (board_config == AD1988_LAPTOP_DIG)
2640 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2641 break;
2642 }
2643
Takashi Iwaid32410b12005-11-24 16:06:23 +01002644 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2645 spec->adc_nids = ad1988_adc_nids;
2646 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002647 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2648 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2649 if (spec->multiout.dig_out_nid) {
2650 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2651 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2652 }
2653 if (spec->dig_in_nid)
2654 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2655
2656 codec->patch_ops = ad198x_patch_ops;
2657 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002658 case AD1988_AUTO:
2659 codec->patch_ops.init = ad1988_auto_init;
2660 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002661 case AD1988_LAPTOP:
2662 case AD1988_LAPTOP_DIG:
2663 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2664 break;
2665 }
2666
2667 return 0;
2668}
2669
2670
2671/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 * patch entries
2673 */
2674struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002675 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2676 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002678 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02002679 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 {} /* terminator */
2681};