blob: 1362c8ba4d1ff7988ea9f53b4bbee1ef04dcadf7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02002 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Takashi Iwai2bac6472007-05-18 18:21:41 +02005 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010030#include "hda_beep.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwai498f5b12011-05-02 11:33:15 +020033 const struct snd_kcontrol_new *mixers[6];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010035 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Raymond Yau28220842011-02-08 19:58:25 +080036 const struct hda_verb *init_verbs[6]; /* 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
Takashi Iwai498f5b12011-05-02 11:33:15 +020049 const hda_nid_t *alt_dac_nid;
50 const struct hda_pcm_stream *stream_analog_alt_playback;
Raymond Yauc66ddf32011-01-17 11:19:03 +010051
Takashi Iwai985be542005-11-02 18:26:49 +010052 /* capture */
53 unsigned int num_adc_nids;
Takashi Iwai498f5b12011-05-02 11:33:15 +020054 const hda_nid_t *adc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010055 hda_nid_t dig_in_nid; /* digital-in NID; optional */
56
57 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020058 const struct hda_input_mux *input_mux;
Takashi Iwai498f5b12011-05-02 11:33:15 +020059 const hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010060 unsigned int cur_mux[3];
61
62 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010063 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010064 int num_channel_mode;
65
66 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020067 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010068
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020069 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010070
71 /* dynamic controls, init_verbs and input_mux */
72 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +020073 struct snd_array kctls;
Takashi Iwaid32410b12005-11-24 16:06:23 +010074 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020075 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +020076
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +010077 unsigned int jack_present: 1;
78 unsigned int inv_jack_detect: 1;/* inverted jack-detection */
79 unsigned int inv_eapd: 1; /* inverted EAPD implementation */
80 unsigned int analog_beep: 1; /* analog beep input present */
Takashi Iwai8ab78c72007-09-06 14:29:53 +020081
Takashi Iwaicb53c622007-08-10 17:21:45 +020082#ifdef CONFIG_SND_HDA_POWER_SAVE
83 struct hda_loopback_check loopback;
84#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010085 /* for virtual master */
86 hda_nid_t vmaster_nid;
Takashi Iwaiea734962011-01-17 11:29:34 +010087 const char * const *slave_vols;
88 const char * const *slave_sws;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020091/*
92 * input MUX handling (common part)
93 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010094static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020095{
96 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
97 struct ad198x_spec *spec = codec->spec;
98
99 return snd_hda_input_mux_info(spec->input_mux, uinfo);
100}
101
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100102static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103{
104 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
105 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100106 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200107
Takashi Iwai985be542005-11-02 18:26:49 +0100108 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200109 return 0;
110}
111
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100112static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200113{
114 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
115 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100116 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200117
118 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100119 spec->capsrc_nids[adc_idx],
120 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200121}
122
123/*
124 * initialization (common callbacks)
125 */
126static int ad198x_init(struct hda_codec *codec)
127{
128 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100129 int i;
130
131 for (i = 0; i < spec->num_init_verbs; i++)
132 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200133 return 0;
134}
135
Takashi Iwaiea734962011-01-17 11:29:34 +0100136static const char * const ad_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +0100137 "Front Playback Volume",
138 "Surround Playback Volume",
139 "Center Playback Volume",
140 "LFE Playback Volume",
141 "Side Playback Volume",
142 "Headphone Playback Volume",
143 "Mono Playback Volume",
Takashi Iwai628ed132008-01-25 11:56:57 +0100144 "Speaker Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100145 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100146 NULL
147};
148
Takashi Iwaiea734962011-01-17 11:29:34 +0100149static const char * const ad_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +0100150 "Front Playback Switch",
151 "Surround Playback Switch",
152 "Center Playback Switch",
153 "LFE Playback Switch",
154 "Side Playback Switch",
155 "Headphone Playback Switch",
156 "Mono Playback Switch",
Takashi Iwai628ed132008-01-25 11:56:57 +0100157 "Speaker Playback Switch",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100158 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100159 NULL
160};
161
Takashi Iwaiea734962011-01-17 11:29:34 +0100162static const char * const ad1988_6stack_fp_slave_vols[] = {
Raymond Yauc66ddf32011-01-17 11:19:03 +0100163 "Front Playback Volume",
164 "Surround Playback Volume",
165 "Center Playback Volume",
166 "LFE Playback Volume",
167 "Side Playback Volume",
168 "IEC958 Playback Volume",
169 NULL
170};
171
Takashi Iwaiea734962011-01-17 11:29:34 +0100172static const char * const ad1988_6stack_fp_slave_sws[] = {
Raymond Yauc66ddf32011-01-17 11:19:03 +0100173 "Front Playback Switch",
174 "Surround Playback Switch",
175 "Center Playback Switch",
176 "LFE Playback Switch",
177 "Side Playback Switch",
178 "IEC958 Playback Switch",
179 NULL
180};
Takashi Iwai603c4012008-07-30 15:01:44 +0200181static void ad198x_free_kctls(struct hda_codec *codec);
182
Takashi Iwai67d634c2009-11-16 15:35:59 +0100183#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100184/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200185static const struct snd_kcontrol_new ad_beep_mixer[] = {
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100186 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +0200187 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100188 { } /* end */
189};
190
Takashi Iwai498f5b12011-05-02 11:33:15 +0200191static const struct snd_kcontrol_new ad_beep2_mixer[] = {
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +0100192 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
193 HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
194 { } /* end */
195};
196
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100197#define set_beep_amp(spec, nid, idx, dir) \
198 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100199#else
200#define set_beep_amp(spec, nid, idx, dir) /* NOP */
201#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100202
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200203static int ad198x_build_controls(struct hda_codec *codec)
204{
205 struct ad198x_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100206 struct snd_kcontrol *kctl;
Takashi Iwai985be542005-11-02 18:26:49 +0100207 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200208 int err;
209
Takashi Iwai985be542005-11-02 18:26:49 +0100210 for (i = 0; i < spec->num_mixers; i++) {
211 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
212 if (err < 0)
213 return err;
214 }
215 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -0600216 err = snd_hda_create_spdif_out_ctls(codec,
217 spec->multiout.dig_out_nid,
218 spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100219 if (err < 0)
220 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100221 err = snd_hda_create_spdif_share_sw(codec,
222 &spec->multiout);
223 if (err < 0)
224 return err;
225 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100226 }
227 if (spec->dig_in_nid) {
228 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
229 if (err < 0)
230 return err;
231 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100232
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100233 /* create beep controls if needed */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100234#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100235 if (spec->beep_amp) {
Takashi Iwai498f5b12011-05-02 11:33:15 +0200236 const struct snd_kcontrol_new *knew;
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +0100237 knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
238 for ( ; knew->name; knew++) {
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100239 struct snd_kcontrol *kctl;
240 kctl = snd_ctl_new1(knew, codec);
241 if (!kctl)
242 return -ENOMEM;
243 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100244 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100245 if (err < 0)
246 return err;
247 }
248 }
Takashi Iwai67d634c2009-11-16 15:35:59 +0100249#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100250
Takashi Iwai2134ea42008-01-10 16:53:55 +0100251 /* if we have no master control, let's create it */
252 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100253 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100254 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100255 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100256 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100257 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100258 (spec->slave_vols ?
259 spec->slave_vols : ad_slave_vols));
260 if (err < 0)
261 return err;
262 }
263 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
264 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
265 NULL,
266 (spec->slave_sws ?
267 spec->slave_sws : ad_slave_sws));
268 if (err < 0)
269 return err;
270 }
271
Takashi Iwai603c4012008-07-30 15:01:44 +0200272 ad198x_free_kctls(codec); /* no longer needed */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100273
274 /* assign Capture Source enums to NID */
275 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
276 if (!kctl)
277 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
278 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +0100279 err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100280 if (err < 0)
281 return err;
282 }
283
284 /* assign IEC958 enums to NID */
285 kctl = snd_hda_find_mixer_ctl(codec,
286 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
287 if (kctl) {
288 err = snd_hda_add_nid(codec, kctl, 0,
289 spec->multiout.dig_out_nid);
290 if (err < 0)
291 return err;
292 }
293
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200294 return 0;
295}
296
Takashi Iwaicb53c622007-08-10 17:21:45 +0200297#ifdef CONFIG_SND_HDA_POWER_SAVE
298static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
299{
300 struct ad198x_spec *spec = codec->spec;
301 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
302}
303#endif
304
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200305/*
306 * Analog playback callbacks
307 */
308static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
309 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100310 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200311{
312 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100313 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
314 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200315}
316
317static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 unsigned int stream_tag,
320 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100321 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200322{
323 struct ad198x_spec *spec = codec->spec;
324 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
325 format, substream);
326}
327
328static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
329 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100330 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200331{
332 struct ad198x_spec *spec = codec->spec;
333 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
334}
335
Takashi Iwai498f5b12011-05-02 11:33:15 +0200336static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
Raymond Yauc66ddf32011-01-17 11:19:03 +0100337 .substreams = 1,
338 .channels_min = 2,
339 .channels_max = 2,
340 /* NID is set in ad198x_build_pcms */
Raymond Yauc66ddf32011-01-17 11:19:03 +0100341};
342
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200343/*
344 * Digital out
345 */
346static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
347 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100348 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200349{
350 struct ad198x_spec *spec = codec->spec;
351 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
352}
353
354static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
355 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100356 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200357{
358 struct ad198x_spec *spec = codec->spec;
359 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
360}
361
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200362static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
363 struct hda_codec *codec,
364 unsigned int stream_tag,
365 unsigned int format,
366 struct snd_pcm_substream *substream)
367{
368 struct ad198x_spec *spec = codec->spec;
369 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
370 format, substream);
371}
372
Takashi Iwai9411e212009-02-13 11:32:28 +0100373static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
374 struct hda_codec *codec,
375 struct snd_pcm_substream *substream)
376{
377 struct ad198x_spec *spec = codec->spec;
378 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
379}
380
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200381/*
382 * Analog capture
383 */
384static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
385 struct hda_codec *codec,
386 unsigned int stream_tag,
387 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100388 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200389{
390 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100391 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
392 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200393 return 0;
394}
395
396static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
397 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100398 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200399{
400 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100401 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200402 return 0;
403}
404
405
406/*
407 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200408static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200409 .substreams = 1,
410 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100411 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200412 .nid = 0, /* fill later */
413 .ops = {
414 .open = ad198x_playback_pcm_open,
415 .prepare = ad198x_playback_pcm_prepare,
416 .cleanup = ad198x_playback_pcm_cleanup
417 },
418};
419
Takashi Iwai498f5b12011-05-02 11:33:15 +0200420static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100421 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200422 .channels_min = 2,
423 .channels_max = 2,
424 .nid = 0, /* fill later */
425 .ops = {
426 .prepare = ad198x_capture_pcm_prepare,
427 .cleanup = ad198x_capture_pcm_cleanup
428 },
429};
430
Takashi Iwai498f5b12011-05-02 11:33:15 +0200431static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200432 .substreams = 1,
433 .channels_min = 2,
434 .channels_max = 2,
435 .nid = 0, /* fill later */
436 .ops = {
437 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200438 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100439 .prepare = ad198x_dig_playback_pcm_prepare,
440 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200441 },
442};
443
Takashi Iwai498f5b12011-05-02 11:33:15 +0200444static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100445 .substreams = 1,
446 .channels_min = 2,
447 .channels_max = 2,
448 /* NID is set in alc_build_pcms */
449};
450
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200451static int ad198x_build_pcms(struct hda_codec *codec)
452{
453 struct ad198x_spec *spec = codec->spec;
454 struct hda_pcm *info = spec->pcm_rec;
455
456 codec->num_pcms = 1;
457 codec->pcm_info = info;
458
459 info->name = "AD198x Analog";
460 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
461 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
462 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
463 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100464 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
465 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200466
467 if (spec->multiout.dig_out_nid) {
468 info++;
469 codec->num_pcms++;
470 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100471 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200472 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
473 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100474 if (spec->dig_in_nid) {
475 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
476 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
477 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200478 }
479
Raymond Yauc66ddf32011-01-17 11:19:03 +0100480 if (spec->alt_dac_nid && spec->stream_analog_alt_playback) {
481 codec->num_pcms++;
482 info = spec->pcm_rec + 2;
483 info->name = "AD198x Headphone";
484 info->pcm_type = HDA_PCM_TYPE_AUDIO;
485 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
486 *spec->stream_analog_alt_playback;
487 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
488 spec->alt_dac_nid[0];
489 }
490
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200491 return 0;
492}
493
Takashi Iwai603c4012008-07-30 15:01:44 +0200494static void ad198x_free_kctls(struct hda_codec *codec)
495{
496 struct ad198x_spec *spec = codec->spec;
497
498 if (spec->kctls.list) {
499 struct snd_kcontrol_new *kctl = spec->kctls.list;
500 int i;
501 for (i = 0; i < spec->kctls.used; i++)
502 kfree(kctl[i].name);
503 }
504 snd_array_free(&spec->kctls);
505}
506
Daniel T Chenea52bf22009-12-27 18:48:29 -0500507static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
508 hda_nid_t hp)
509{
510 struct ad198x_spec *spec = codec->spec;
Raymond Yaua01ef052011-06-01 15:09:48 +0800511 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
512 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500513 !spec->inv_eapd ? 0x00 : 0x02);
Raymond Yaua01ef052011-06-01 15:09:48 +0800514 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
515 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500516 !spec->inv_eapd ? 0x00 : 0x02);
517}
518
519static void ad198x_power_eapd(struct hda_codec *codec)
520{
521 /* We currently only handle front, HP */
522 switch (codec->vendor_id) {
523 case 0x11d41882:
524 case 0x11d4882a:
525 case 0x11d41884:
526 case 0x11d41984:
527 case 0x11d41883:
528 case 0x11d4184a:
529 case 0x11d4194a:
530 case 0x11d4194b:
Takashi Iwai4dffbe02011-06-03 10:05:02 +0200531 case 0x11d41988:
532 case 0x11d4198b:
533 case 0x11d4989a:
534 case 0x11d4989b:
Daniel T Chenea52bf22009-12-27 18:48:29 -0500535 ad198x_power_eapd_write(codec, 0x12, 0x11);
536 break;
537 case 0x11d41981:
538 case 0x11d41983:
539 ad198x_power_eapd_write(codec, 0x05, 0x06);
540 break;
541 case 0x11d41986:
542 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
543 break;
Daniel T Chenea52bf22009-12-27 18:48:29 -0500544 }
545}
546
Takashi Iwai0da26922011-04-26 15:18:33 +0200547static void ad198x_shutup(struct hda_codec *codec)
548{
549 snd_hda_shutup_pins(codec);
550 ad198x_power_eapd(codec);
551}
552
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200553static void ad198x_free(struct hda_codec *codec)
554{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100555 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100556
Takashi Iwai603c4012008-07-30 15:01:44 +0200557 if (!spec)
558 return;
559
Daniel T Chenea52bf22009-12-27 18:48:29 -0500560 ad198x_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +0200561 ad198x_free_kctls(codec);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100562 kfree(spec);
563 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200564}
565
Daniel T Chenea52bf22009-12-27 18:48:29 -0500566#ifdef SND_HDA_NEEDS_RESUME
567static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
568{
569 ad198x_shutup(codec);
Daniel T Chenea52bf22009-12-27 18:48:29 -0500570 return 0;
571}
Daniel T Chenea52bf22009-12-27 18:48:29 -0500572#endif
573
Takashi Iwai498f5b12011-05-02 11:33:15 +0200574static const struct hda_codec_ops ad198x_patch_ops = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200575 .build_controls = ad198x_build_controls,
576 .build_pcms = ad198x_build_pcms,
577 .init = ad198x_init,
578 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200579#ifdef CONFIG_SND_HDA_POWER_SAVE
580 .check_power_status = ad198x_check_power_status,
581#endif
Daniel T Chenea52bf22009-12-27 18:48:29 -0500582#ifdef SND_HDA_NEEDS_RESUME
583 .suspend = ad198x_suspend,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500584#endif
585 .reboot_notify = ad198x_shutup,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200586};
587
588
589/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100590 * EAPD control
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100591 * the private value = nid
Takashi Iwai18a815d2006-03-01 19:54:39 +0100592 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200593#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100594
595static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_value *ucontrol)
597{
598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
599 struct ad198x_spec *spec = codec->spec;
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100600 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100601 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
602 else
603 ucontrol->value.integer.value[0] = spec->cur_eapd;
604 return 0;
605}
606
607static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct ad198x_spec *spec = codec->spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100612 hda_nid_t nid = kcontrol->private_value & 0xff;
613 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100614 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100615 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100616 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200617 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100618 return 0;
619 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200620 snd_hda_codec_write_cache(codec, nid,
621 0, AC_VERB_SET_EAPD_BTLENABLE,
622 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100623 return 1;
624}
625
Takashi Iwai9230d212006-03-13 13:49:49 +0100626static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_info *uinfo);
628static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
629 struct snd_ctl_elem_value *ucontrol);
630static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_value *ucontrol);
632
633
Takashi Iwai18a815d2006-03-01 19:54:39 +0100634/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200635 * AD1986A specific
636 */
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#define AD1986A_SPDIF_OUT 0x02
639#define AD1986A_FRONT_DAC 0x03
640#define AD1986A_SURR_DAC 0x04
641#define AD1986A_CLFE_DAC 0x05
642#define AD1986A_ADC 0x06
643
Takashi Iwai498f5b12011-05-02 11:33:15 +0200644static const hda_nid_t ad1986a_dac_nids[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
646};
Takashi Iwai498f5b12011-05-02 11:33:15 +0200647static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
648static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Takashi Iwai498f5b12011-05-02 11:33:15 +0200650static const struct hda_input_mux ad1986a_capture_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 .num_items = 7,
652 .items = {
653 { "Mic", 0x0 },
654 { "CD", 0x1 },
655 { "Aux", 0x3 },
656 { "Line", 0x4 },
657 { "Mix", 0x5 },
658 { "Mono", 0x6 },
659 { "Phone", 0x7 },
660 },
661};
662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Takashi Iwai498f5b12011-05-02 11:33:15 +0200664static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200665 .ops = &snd_hda_bind_vol,
666 .values = {
667 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
668 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
669 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
670 0
671 },
672};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Takashi Iwai498f5b12011-05-02 11:33:15 +0200674static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200675 .ops = &snd_hda_bind_sw,
676 .values = {
677 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
678 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
679 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
680 0
681 },
682};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
684/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 * mixers
686 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200687static const struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200688 /*
689 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
690 */
691 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
692 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
694 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
695 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
696 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
697 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
698 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
699 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
700 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
701 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
702 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
703 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
704 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
705 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
706 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
707 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
708 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
709 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
710 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100711 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
713 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
714 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
715 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
716 {
717 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
718 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200719 .info = ad198x_mux_enum_info,
720 .get = ad198x_mux_enum_get,
721 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 },
723 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
724 { } /* end */
725};
726
Takashi Iwai9230d212006-03-13 13:49:49 +0100727/* additional mixers for 3stack mode */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200728static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +0100729 {
730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
731 .name = "Channel Mode",
732 .info = ad198x_ch_mode_info,
733 .get = ad198x_ch_mode_get,
734 .put = ad198x_ch_mode_put,
735 },
736 { } /* end */
737};
738
739/* laptop model - 2ch only */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200740static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
Takashi Iwai9230d212006-03-13 13:49:49 +0100741
Takashi Iwai20a45e82007-08-15 22:20:45 +0200742/* master controls both pins 0x1a and 0x1b */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200743static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
Takashi Iwai20a45e82007-08-15 22:20:45 +0200744 .ops = &snd_hda_bind_vol,
745 .values = {
746 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
747 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
748 0,
749 },
750};
751
Takashi Iwai498f5b12011-05-02 11:33:15 +0200752static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
Takashi Iwai20a45e82007-08-15 22:20:45 +0200753 .ops = &snd_hda_bind_sw,
754 .values = {
755 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
756 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
757 0,
758 },
759};
760
Takashi Iwai498f5b12011-05-02 11:33:15 +0200761static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +0100762 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
763 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200764 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
765 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100766 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
767 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
768 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
769 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
770 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
771 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
772 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
773 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100774 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100775 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100776 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
777 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
778 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
779 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
780 {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Capture Source",
783 .info = ad198x_mux_enum_info,
784 .get = ad198x_mux_enum_get,
785 .put = ad198x_mux_enum_put,
786 },
787 { } /* end */
788};
789
Takashi Iwai825aa972006-03-17 10:50:49 +0100790/* laptop-eapd model - 2ch only */
791
Takashi Iwai498f5b12011-05-02 11:33:15 +0200792static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100793 .num_items = 3,
794 .items = {
795 { "Mic", 0x0 },
796 { "Internal Mic", 0x4 },
797 { "Mix", 0x5 },
798 },
799};
800
Takashi Iwai498f5b12011-05-02 11:33:15 +0200801static const struct hda_input_mux ad1986a_automic_capture_source = {
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100802 .num_items = 2,
803 .items = {
804 { "Mic", 0x0 },
805 { "Mix", 0x5 },
806 },
807};
808
Takashi Iwai498f5b12011-05-02 11:33:15 +0200809static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200810 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
811 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200812 { } /* end */
813};
814
Takashi Iwai498f5b12011-05-02 11:33:15 +0200815static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100816 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
817 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100818 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
819 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100820 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100821 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
822 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
823 {
824 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
825 .name = "Capture Source",
826 .info = ad198x_mux_enum_info,
827 .get = ad198x_mux_enum_get,
828 .put = ad198x_mux_enum_put,
829 },
830 {
831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
832 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100833 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwai1725b822008-11-21 02:25:48 +0100834 .info = ad198x_eapd_info,
835 .get = ad198x_eapd_get,
836 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100837 .private_value = 0x1b, /* port-D */
Takashi Iwai1725b822008-11-21 02:25:48 +0100838 },
839 { } /* end */
840};
841
Takashi Iwai498f5b12011-05-02 11:33:15 +0200842static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
Takashi Iwai16d11a82009-06-24 14:07:53 +0200843 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
844 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100845 { } /* end */
846};
847
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100848/* re-connect the mic boost input according to the jack sensing */
849static void ad1986a_automic(struct hda_codec *codec)
850{
851 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100852 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100853 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
854 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100855 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100856}
857
858#define AD1986A_MIC_EVENT 0x36
859
860static void ad1986a_automic_unsol_event(struct hda_codec *codec,
861 unsigned int res)
862{
863 if ((res >> 26) != AD1986A_MIC_EVENT)
864 return;
865 ad1986a_automic(codec);
866}
867
868static int ad1986a_automic_init(struct hda_codec *codec)
869{
870 ad198x_init(codec);
871 ad1986a_automic(codec);
872 return 0;
873}
874
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200875/* laptop-automute - 2ch only */
876
877static void ad1986a_update_hp(struct hda_codec *codec)
878{
879 struct ad198x_spec *spec = codec->spec;
880 unsigned int mute;
881
882 if (spec->jack_present)
883 mute = HDA_AMP_MUTE; /* mute internal speaker */
884 else
885 /* unmute internal speaker if necessary */
886 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
887 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
888 HDA_AMP_MUTE, mute);
889}
890
891static void ad1986a_hp_automute(struct hda_codec *codec)
892{
893 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200894
Takashi Iwaid56757a2009-11-18 08:00:14 +0100895 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200896 if (spec->inv_jack_detect)
897 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200898 ad1986a_update_hp(codec);
899}
900
901#define AD1986A_HP_EVENT 0x37
902
903static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
904{
905 if ((res >> 26) != AD1986A_HP_EVENT)
906 return;
907 ad1986a_hp_automute(codec);
908}
909
910static int ad1986a_hp_init(struct hda_codec *codec)
911{
912 ad198x_init(codec);
913 ad1986a_hp_automute(codec);
914 return 0;
915}
916
917/* bind hp and internal speaker mute (with plug check) */
918static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
919 struct snd_ctl_elem_value *ucontrol)
920{
921 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
922 long *valp = ucontrol->value.integer.value;
923 int change;
924
925 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
926 HDA_AMP_MUTE,
927 valp[0] ? 0 : HDA_AMP_MUTE);
928 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
929 HDA_AMP_MUTE,
930 valp[1] ? 0 : HDA_AMP_MUTE);
931 if (change)
932 ad1986a_update_hp(codec);
933 return change;
934}
935
Takashi Iwai498f5b12011-05-02 11:33:15 +0200936static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200937 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
938 {
939 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
940 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100941 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200942 .info = snd_hda_mixer_amp_switch_info,
943 .get = snd_hda_mixer_amp_switch_get,
944 .put = ad1986a_hp_master_sw_put,
945 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
946 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200947 { } /* end */
948};
949
Takashi Iwai16d11a82009-06-24 14:07:53 +0200950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951/*
952 * initialization verbs
953 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200954static const struct hda_verb ad1986a_init_verbs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* Front, Surround, CLFE DAC; mute as default */
956 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
957 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
958 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
959 /* Downmix - off */
960 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
961 /* HP, Line-Out, Surround, CLFE selectors */
962 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
963 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
964 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
965 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
966 /* Mono selector */
967 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
968 /* Mic selector: Mic 1/2 pin */
969 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
970 /* Line-in selector: Line-in */
971 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
972 /* Mic 1/2 swap */
973 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
974 /* Record selector: mic */
975 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
976 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
977 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
978 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
979 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
980 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
981 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
982 /* PC beep */
983 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
984 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
985 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
986 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
987 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
988 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
989 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200990 /* HP Pin */
991 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
992 /* Front, Surround, CLFE Pins */
993 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
994 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
995 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
996 /* Mono Pin */
997 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
998 /* Mic Pin */
999 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1000 /* Line, Aux, CD, Beep-In Pin */
1001 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1002 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1003 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1004 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1005 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 { } /* end */
1007};
1008
Takashi Iwai498f5b12011-05-02 11:33:15 +02001009static const struct hda_verb ad1986a_ch2_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001010 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001011 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1012 /* Line-in selectors */
1013 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001014 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001015 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1016 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
1017 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001018 { } /* end */
1019};
1020
Takashi Iwai498f5b12011-05-02 11:33:15 +02001021static const struct hda_verb ad1986a_ch4_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001022 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001023 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1024 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001025 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001026 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1027 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001028 { } /* end */
1029};
1030
Takashi Iwai498f5b12011-05-02 11:33:15 +02001031static const struct hda_verb ad1986a_ch6_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001032 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001033 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1034 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001035 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001036 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1037 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001038 { } /* end */
1039};
1040
Takashi Iwai498f5b12011-05-02 11:33:15 +02001041static const struct hda_channel_mode ad1986a_modes[3] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001042 { 2, ad1986a_ch2_init },
1043 { 4, ad1986a_ch4_init },
1044 { 6, ad1986a_ch6_init },
1045};
1046
Takashi Iwai825aa972006-03-17 10:50:49 +01001047/* eapd initialization */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001048static const struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +01001049 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +01001050 {}
1051};
1052
Takashi Iwai498f5b12011-05-02 11:33:15 +02001053static const struct hda_verb ad1986a_automic_verbs[] = {
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001054 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1055 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1056 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
1057 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
1058 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
1059 {}
1060};
1061
Tobin Davisf36090f2007-01-08 11:07:12 +01001062/* Ultra initialization */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001063static const struct hda_verb ad1986a_ultra_init[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +01001064 /* eapd initialization */
1065 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
1066 /* CLFE -> Mic in */
1067 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
1068 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1069 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
1070 { } /* end */
1071};
1072
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001073/* pin sensing on HP jack */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001074static const struct hda_verb ad1986a_hp_init_verbs[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001075 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
1076 {}
1077};
1078
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001079static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
1080 unsigned int res)
1081{
1082 switch (res >> 26) {
1083 case AD1986A_HP_EVENT:
1084 ad1986a_hp_automute(codec);
1085 break;
1086 case AD1986A_MIC_EVENT:
1087 ad1986a_automic(codec);
1088 break;
1089 }
1090}
1091
1092static int ad1986a_samsung_p50_init(struct hda_codec *codec)
1093{
1094 ad198x_init(codec);
1095 ad1986a_hp_automute(codec);
1096 ad1986a_automic(codec);
1097 return 0;
1098}
1099
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001100
Takashi Iwai9230d212006-03-13 13:49:49 +01001101/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001102enum {
1103 AD1986A_6STACK,
1104 AD1986A_3STACK,
1105 AD1986A_LAPTOP,
1106 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001107 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +01001108 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +01001109 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001110 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001111 AD1986A_MODELS
1112};
Takashi Iwai9230d212006-03-13 13:49:49 +01001113
Takashi Iwaiea734962011-01-17 11:29:34 +01001114static const char * const ad1986a_models[AD1986A_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001115 [AD1986A_6STACK] = "6stack",
1116 [AD1986A_3STACK] = "3stack",
1117 [AD1986A_LAPTOP] = "laptop",
1118 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001119 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +01001120 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +01001121 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001122 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001123};
1124
Takashi Iwai498f5b12011-05-02 11:33:15 +02001125static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001126 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001127 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001128 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001129 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001130 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1131 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1132 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1133 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001134 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001135 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001136 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1137 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1138 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1139 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1140 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001141 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Daniel T Chenba579eb2010-02-20 11:16:30 -05001142 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001143 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001144 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001145 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001146 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001147 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001148 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001149 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001150 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001151 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001152 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001153 {}
1154};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Takashi Iwaicb53c622007-08-10 17:21:45 +02001156#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02001157static const struct hda_amp_list ad1986a_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02001158 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1159 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1160 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1161 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1162 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1163 { } /* end */
1164};
1165#endif
1166
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001167static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1168{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001169 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001170 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1171}
1172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173static int patch_ad1986a(struct hda_codec *codec)
1174{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001175 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001176 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001178 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (spec == NULL)
1180 return -ENOMEM;
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 codec->spec = spec;
1183
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001184 err = snd_hda_attach_beep_device(codec, 0x19);
1185 if (err < 0) {
1186 ad198x_free(codec);
1187 return err;
1188 }
1189 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 spec->multiout.max_channels = 6;
1192 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1193 spec->multiout.dac_nids = ad1986a_dac_nids;
1194 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001195 spec->num_adc_nids = 1;
1196 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001197 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001198 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001199 spec->num_mixers = 1;
1200 spec->mixers[0] = ad1986a_mixers;
1201 spec->num_init_verbs = 1;
1202 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001203#ifdef CONFIG_SND_HDA_POWER_SAVE
1204 spec->loopback.amplist = ad1986a_loopbacks;
1205#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001206 spec->vmaster_nid = 0x1b;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01001207 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001209 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Takashi Iwai9230d212006-03-13 13:49:49 +01001211 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001212 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1213 ad1986a_models,
1214 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001215 switch (board_config) {
1216 case AD1986A_3STACK:
1217 spec->num_mixers = 2;
1218 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001219 spec->num_init_verbs = 2;
1220 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001221 spec->channel_mode = ad1986a_modes;
1222 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001223 spec->need_dac_fix = 1;
1224 spec->multiout.max_channels = 2;
1225 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001226 break;
1227 case AD1986A_LAPTOP:
1228 spec->mixers[0] = ad1986a_laptop_mixers;
1229 spec->multiout.max_channels = 2;
1230 spec->multiout.num_dacs = 1;
1231 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1232 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001233 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001234 spec->num_mixers = 3;
1235 spec->mixers[0] = ad1986a_laptop_master_mixers;
1236 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1237 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001238 spec->num_init_verbs = 2;
1239 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1240 spec->multiout.max_channels = 2;
1241 spec->multiout.num_dacs = 1;
1242 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1243 if (!is_jack_available(codec, 0x25))
1244 spec->multiout.dig_out_nid = 0;
1245 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1246 break;
1247 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001248 spec->num_mixers = 2;
1249 spec->mixers[0] = ad1986a_laptop_master_mixers;
1250 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001251 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001252 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001253 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001254 spec->multiout.max_channels = 2;
1255 spec->multiout.num_dacs = 1;
1256 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001257 if (!is_jack_available(codec, 0x25))
1258 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001259 spec->input_mux = &ad1986a_automic_capture_source;
1260 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1261 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001262 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001263 case AD1986A_SAMSUNG_P50:
1264 spec->num_mixers = 2;
1265 spec->mixers[0] = ad1986a_automute_master_mixers;
1266 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1267 spec->num_init_verbs = 4;
1268 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1269 spec->init_verbs[2] = ad1986a_automic_verbs;
1270 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1271 spec->multiout.max_channels = 2;
1272 spec->multiout.num_dacs = 1;
1273 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1274 if (!is_jack_available(codec, 0x25))
1275 spec->multiout.dig_out_nid = 0;
1276 spec->input_mux = &ad1986a_automic_capture_source;
1277 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1278 codec->patch_ops.init = ad1986a_samsung_p50_init;
1279 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001280 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001281 spec->num_mixers = 3;
1282 spec->mixers[0] = ad1986a_automute_master_mixers;
1283 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1284 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001285 spec->num_init_verbs = 3;
1286 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1287 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1288 spec->multiout.max_channels = 2;
1289 spec->multiout.num_dacs = 1;
1290 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001291 if (!is_jack_available(codec, 0x25))
1292 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001293 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1294 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1295 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001296 /* Lenovo N100 seems to report the reversed bit
1297 * for HP jack-sensing
1298 */
1299 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001300 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001301 case AD1986A_ULTRA:
1302 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1303 spec->num_init_verbs = 2;
1304 spec->init_verbs[1] = ad1986a_ultra_init;
1305 spec->multiout.max_channels = 2;
1306 spec->multiout.num_dacs = 1;
1307 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1308 spec->multiout.dig_out_nid = 0;
1309 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001310 }
1311
Takashi Iwaid29240c2007-10-26 12:35:56 +02001312 /* AD1986A has a hardware problem that it can't share a stream
1313 * with multiple output pins. The copy of front to surrounds
1314 * causes noisy or silent outputs at a certain timing, e.g.
1315 * changing the volume.
1316 * So, let's disable the shared stream.
1317 */
1318 spec->multiout.no_share_stream = 1;
1319
Takashi Iwai729d55b2009-12-25 22:49:01 +01001320 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001321 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001322
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 return 0;
1324}
1325
1326/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001327 * AD1983 specific
1328 */
1329
1330#define AD1983_SPDIF_OUT 0x02
1331#define AD1983_DAC 0x03
1332#define AD1983_ADC 0x04
1333
Takashi Iwai498f5b12011-05-02 11:33:15 +02001334static const hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
1335static const hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
1336static const hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001337
Takashi Iwai498f5b12011-05-02 11:33:15 +02001338static const struct hda_input_mux ad1983_capture_source = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001339 .num_items = 4,
1340 .items = {
1341 { "Mic", 0x0 },
1342 { "Line", 0x1 },
1343 { "Mix", 0x2 },
1344 { "Mix Mono", 0x3 },
1345 },
1346};
1347
1348/*
1349 * SPDIF playback route
1350 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001351static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001352{
Takashi Iwai498f5b12011-05-02 11:33:15 +02001353 static const char * const texts[] = { "PCM", "ADC" };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001354
1355 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1356 uinfo->count = 1;
1357 uinfo->value.enumerated.items = 2;
1358 if (uinfo->value.enumerated.item > 1)
1359 uinfo->value.enumerated.item = 1;
1360 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1361 return 0;
1362}
1363
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001364static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001365{
1366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1367 struct ad198x_spec *spec = codec->spec;
1368
1369 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1370 return 0;
1371}
1372
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001373static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001374{
1375 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1376 struct ad198x_spec *spec = codec->spec;
1377
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001378 if (ucontrol->value.enumerated.item[0] > 1)
1379 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001380 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1381 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001382 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1383 AC_VERB_SET_CONNECT_SEL,
1384 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001385 return 1;
1386 }
1387 return 0;
1388}
1389
Takashi Iwai498f5b12011-05-02 11:33:15 +02001390static const struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001391 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1392 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1393 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1394 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1395 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1396 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1397 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1398 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1400 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1401 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1402 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001403 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001404 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1405 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1406 {
1407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1408 .name = "Capture Source",
1409 .info = ad198x_mux_enum_info,
1410 .get = ad198x_mux_enum_get,
1411 .put = ad198x_mux_enum_put,
1412 },
1413 {
1414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001415 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001416 .info = ad1983_spdif_route_info,
1417 .get = ad1983_spdif_route_get,
1418 .put = ad1983_spdif_route_put,
1419 },
1420 { } /* end */
1421};
1422
Takashi Iwai498f5b12011-05-02 11:33:15 +02001423static const struct hda_verb ad1983_init_verbs[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001424 /* Front, HP, Mono; mute as default */
1425 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1426 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1427 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1428 /* Beep, PCM, Mic, Line-In: mute */
1429 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1430 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1431 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1432 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1433 /* Front, HP selectors; from Mix */
1434 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1435 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1436 /* Mono selector; from Mix */
1437 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1438 /* Mic selector; Mic */
1439 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1440 /* Line-in selector: Line-in */
1441 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1442 /* Mic boost: 0dB */
1443 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1444 /* Record selector: mic */
1445 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1446 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1447 /* SPDIF route: PCM */
1448 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1449 /* Front Pin */
1450 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1451 /* HP Pin */
1452 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1453 /* Mono Pin */
1454 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1455 /* Mic Pin */
1456 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1457 /* Line Pin */
1458 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1459 { } /* end */
1460};
1461
Takashi Iwaicb53c622007-08-10 17:21:45 +02001462#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02001463static const struct hda_amp_list ad1983_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02001464 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1465 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1466 { } /* end */
1467};
1468#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001469
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001470static int patch_ad1983(struct hda_codec *codec)
1471{
1472 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001473 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001474
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001475 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001476 if (spec == NULL)
1477 return -ENOMEM;
1478
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001479 codec->spec = spec;
1480
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001481 err = snd_hda_attach_beep_device(codec, 0x10);
1482 if (err < 0) {
1483 ad198x_free(codec);
1484 return err;
1485 }
1486 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1487
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001488 spec->multiout.max_channels = 2;
1489 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1490 spec->multiout.dac_nids = ad1983_dac_nids;
1491 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001492 spec->num_adc_nids = 1;
1493 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001494 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001495 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001496 spec->num_mixers = 1;
1497 spec->mixers[0] = ad1983_mixers;
1498 spec->num_init_verbs = 1;
1499 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001500 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001501#ifdef CONFIG_SND_HDA_POWER_SAVE
1502 spec->loopback.amplist = ad1983_loopbacks;
1503#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001504 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001505
1506 codec->patch_ops = ad198x_patch_ops;
1507
Takashi Iwai729d55b2009-12-25 22:49:01 +01001508 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001509 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001510
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001511 return 0;
1512}
1513
1514
1515/*
1516 * AD1981 HD specific
1517 */
1518
1519#define AD1981_SPDIF_OUT 0x02
1520#define AD1981_DAC 0x03
1521#define AD1981_ADC 0x04
1522
Takashi Iwai498f5b12011-05-02 11:33:15 +02001523static const hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1524static const hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1525static const hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001526
1527/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001528static const struct hda_input_mux ad1981_capture_source = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001529 .num_items = 7,
1530 .items = {
1531 { "Front Mic", 0x0 },
1532 { "Line", 0x1 },
1533 { "Mix", 0x2 },
1534 { "Mix Mono", 0x3 },
1535 { "CD", 0x4 },
1536 { "Mic", 0x6 },
1537 { "Aux", 0x7 },
1538 },
1539};
1540
Takashi Iwai498f5b12011-05-02 11:33:15 +02001541static const struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001542 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1543 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1544 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1545 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1546 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1547 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1548 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1549 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1550 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1551 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1552 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1553 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1554 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1555 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1556 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1557 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1558 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1559 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001560 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1561 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001562 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1563 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1564 {
1565 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1566 .name = "Capture Source",
1567 .info = ad198x_mux_enum_info,
1568 .get = ad198x_mux_enum_get,
1569 .put = ad198x_mux_enum_put,
1570 },
1571 /* identical with AD1983 */
1572 {
1573 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001574 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001575 .info = ad1983_spdif_route_info,
1576 .get = ad1983_spdif_route_get,
1577 .put = ad1983_spdif_route_put,
1578 },
1579 { } /* end */
1580};
1581
Takashi Iwai498f5b12011-05-02 11:33:15 +02001582static const struct hda_verb ad1981_init_verbs[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001583 /* Front, HP, Mono; mute as default */
1584 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1585 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1586 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1587 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1588 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1589 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1590 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1591 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1592 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1593 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1594 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1595 /* Front, HP selectors; from Mix */
1596 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1597 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1598 /* Mono selector; from Mix */
1599 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1600 /* Mic Mixer; select Front Mic */
1601 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1602 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1603 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001604 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1605 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001606 /* Record selector: Front mic */
1607 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1608 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1609 /* SPDIF route: PCM */
1610 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1611 /* Front Pin */
1612 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1613 /* HP Pin */
1614 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1615 /* Mono Pin */
1616 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1617 /* Front & Rear Mic Pins */
1618 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1619 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1620 /* Line Pin */
1621 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1622 /* Digital Beep */
1623 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1624 /* Line-Out as Input: disabled */
1625 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1626 { } /* end */
1627};
1628
Takashi Iwaicb53c622007-08-10 17:21:45 +02001629#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02001630static const struct hda_amp_list ad1981_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02001631 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1632 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1633 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1634 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1635 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1636 { } /* end */
1637};
1638#endif
1639
Takashi Iwai18a815d2006-03-01 19:54:39 +01001640/*
1641 * Patch for HP nx6320
1642 *
Tobin Davis18768992007-03-12 22:20:51 +01001643 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001644 * speaker output enabled _and_ mute-LED off.
1645 */
1646
1647#define AD1981_HP_EVENT 0x37
1648#define AD1981_MIC_EVENT 0x38
1649
Takashi Iwai498f5b12011-05-02 11:33:15 +02001650static const struct hda_verb ad1981_hp_init_verbs[] = {
Takashi Iwai18a815d2006-03-01 19:54:39 +01001651 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1652 /* pin sensing on HP and Mic jacks */
1653 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1654 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1655 {}
1656};
1657
1658/* turn on/off EAPD (+ mute HP) as a master switch */
1659static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol)
1661{
1662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1663 struct ad198x_spec *spec = codec->spec;
1664
1665 if (! ad198x_eapd_put(kcontrol, ucontrol))
1666 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001667 /* change speaker pin appropriately */
1668 snd_hda_codec_write(codec, 0x05, 0,
1669 AC_VERB_SET_PIN_WIDGET_CONTROL,
1670 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001671 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001672 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1673 HDA_AMP_MUTE,
1674 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001675 return 1;
1676}
1677
1678/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001679static const struct hda_bind_ctls ad1981_hp_bind_master_vol = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001680 .ops = &snd_hda_bind_vol,
1681 .values = {
1682 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1683 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1684 0
1685 },
1686};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001687
1688/* mute internal speaker if HP is plugged */
1689static void ad1981_hp_automute(struct hda_codec *codec)
1690{
1691 unsigned int present;
1692
Takashi Iwaid56757a2009-11-18 08:00:14 +01001693 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001694 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1695 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001696}
1697
1698/* toggle input of built-in and mic jack appropriately */
1699static void ad1981_hp_automic(struct hda_codec *codec)
1700{
Takashi Iwai498f5b12011-05-02 11:33:15 +02001701 static const struct hda_verb mic_jack_on[] = {
Takashi Iwai18a815d2006-03-01 19:54:39 +01001702 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1703 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1704 {}
1705 };
Takashi Iwai498f5b12011-05-02 11:33:15 +02001706 static const struct hda_verb mic_jack_off[] = {
Takashi Iwai18a815d2006-03-01 19:54:39 +01001707 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1708 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1709 {}
1710 };
1711 unsigned int present;
1712
Takashi Iwaid56757a2009-11-18 08:00:14 +01001713 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001714 if (present)
1715 snd_hda_sequence_write(codec, mic_jack_on);
1716 else
1717 snd_hda_sequence_write(codec, mic_jack_off);
1718}
1719
1720/* unsolicited event for HP jack sensing */
1721static void ad1981_hp_unsol_event(struct hda_codec *codec,
1722 unsigned int res)
1723{
1724 res >>= 26;
1725 switch (res) {
1726 case AD1981_HP_EVENT:
1727 ad1981_hp_automute(codec);
1728 break;
1729 case AD1981_MIC_EVENT:
1730 ad1981_hp_automic(codec);
1731 break;
1732 }
1733}
1734
Takashi Iwai498f5b12011-05-02 11:33:15 +02001735static const struct hda_input_mux ad1981_hp_capture_source = {
Takashi Iwai18a815d2006-03-01 19:54:39 +01001736 .num_items = 3,
1737 .items = {
1738 { "Mic", 0x0 },
1739 { "Docking-Station", 0x1 },
1740 { "Mix", 0x2 },
1741 },
1742};
1743
Takashi Iwai498f5b12011-05-02 11:33:15 +02001744static const struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001745 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001746 {
1747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001748 .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
Takashi Iwai18a815d2006-03-01 19:54:39 +01001749 .name = "Master Playback Switch",
1750 .info = ad198x_eapd_info,
1751 .get = ad198x_eapd_get,
1752 .put = ad1981_hp_master_sw_put,
1753 .private_value = 0x05,
1754 },
1755 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1756 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1757#if 0
1758 /* FIXME: analog mic/line loopback doesn't work with my tests...
1759 * (although recording is OK)
1760 */
1761 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1762 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1763 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1764 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1765 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1766 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1767 /* FIXME: does this laptop have analog CD connection? */
1768 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1769 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1770#endif
David Henningsson5f99f862011-01-04 15:24:24 +01001771 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1772 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001773 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1774 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1775 {
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = "Capture Source",
1778 .info = ad198x_mux_enum_info,
1779 .get = ad198x_mux_enum_get,
1780 .put = ad198x_mux_enum_put,
1781 },
1782 { } /* end */
1783};
1784
1785/* initialize jack-sensing, too */
1786static int ad1981_hp_init(struct hda_codec *codec)
1787{
1788 ad198x_init(codec);
1789 ad1981_hp_automute(codec);
1790 ad1981_hp_automic(codec);
1791 return 0;
1792}
1793
Tobin Davis18768992007-03-12 22:20:51 +01001794/* configuration for Toshiba Laptops */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001795static const struct hda_verb ad1981_toshiba_init_verbs[] = {
Tobin Davis18768992007-03-12 22:20:51 +01001796 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1797 /* pin sensing on HP and Mic jacks */
1798 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1799 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1800 {}
1801};
1802
Takashi Iwai498f5b12011-05-02 11:33:15 +02001803static const struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
Tobin Davis18768992007-03-12 22:20:51 +01001804 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1805 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1806 { }
1807};
1808
Takashi Iwai01686c52006-04-18 12:54:11 +02001809/* configuration for Lenovo Thinkpad T60 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001810static const struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
Takashi Iwai01686c52006-04-18 12:54:11 +02001811 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1812 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1813 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1814 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1815 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1816 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1817 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1818 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001819 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
Takashi Iwai01686c52006-04-18 12:54:11 +02001820 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1821 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1822 {
1823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1824 .name = "Capture Source",
1825 .info = ad198x_mux_enum_info,
1826 .get = ad198x_mux_enum_get,
1827 .put = ad198x_mux_enum_put,
1828 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001829 /* identical with AD1983 */
1830 {
1831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1832 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1833 .info = ad1983_spdif_route_info,
1834 .get = ad1983_spdif_route_get,
1835 .put = ad1983_spdif_route_put,
1836 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001837 { } /* end */
1838};
1839
Takashi Iwai498f5b12011-05-02 11:33:15 +02001840static const struct hda_input_mux ad1981_thinkpad_capture_source = {
Takashi Iwai01686c52006-04-18 12:54:11 +02001841 .num_items = 3,
1842 .items = {
1843 { "Mic", 0x0 },
1844 { "Mix", 0x2 },
1845 { "CD", 0x4 },
1846 },
1847};
1848
Takashi Iwai18a815d2006-03-01 19:54:39 +01001849/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001850enum {
1851 AD1981_BASIC,
1852 AD1981_HP,
1853 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001854 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001855 AD1981_MODELS
1856};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001857
Takashi Iwaiea734962011-01-17 11:29:34 +01001858static const char * const ad1981_models[AD1981_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001859 [AD1981_HP] = "hp",
1860 [AD1981_THINKPAD] = "thinkpad",
1861 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001862 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001863};
1864
Takashi Iwai498f5b12011-05-02 11:33:15 +02001865static const struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001866 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001867 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001868 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001869 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001870 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c52006-04-18 12:54:11 +02001871 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001872 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001873 /* HP nx6320 (reversed SSID, H/W bug) */
1874 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001875 {}
1876};
1877
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001878static int patch_ad1981(struct hda_codec *codec)
1879{
1880 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001881 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001882
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001883 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001884 if (spec == NULL)
1885 return -ENOMEM;
1886
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001887 codec->spec = spec;
1888
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001889 err = snd_hda_attach_beep_device(codec, 0x10);
1890 if (err < 0) {
1891 ad198x_free(codec);
1892 return err;
1893 }
1894 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1895
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001896 spec->multiout.max_channels = 2;
1897 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1898 spec->multiout.dac_nids = ad1981_dac_nids;
1899 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001900 spec->num_adc_nids = 1;
1901 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001902 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001903 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001904 spec->num_mixers = 1;
1905 spec->mixers[0] = ad1981_mixers;
1906 spec->num_init_verbs = 1;
1907 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001908 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001909#ifdef CONFIG_SND_HDA_POWER_SAVE
1910 spec->loopback.amplist = ad1981_loopbacks;
1911#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001912 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001913
1914 codec->patch_ops = ad198x_patch_ops;
1915
Takashi Iwai18a815d2006-03-01 19:54:39 +01001916 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001917 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1918 ad1981_models,
1919 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001920 switch (board_config) {
1921 case AD1981_HP:
1922 spec->mixers[0] = ad1981_hp_mixers;
1923 spec->num_init_verbs = 2;
1924 spec->init_verbs[1] = ad1981_hp_init_verbs;
Takashi Iwai695cd4a2011-06-10 14:37:04 +02001925 if (!is_jack_available(codec, 0x0a))
1926 spec->multiout.dig_out_nid = 0;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001927 spec->input_mux = &ad1981_hp_capture_source;
1928
1929 codec->patch_ops.init = ad1981_hp_init;
1930 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
Daniel T Chen01f59662009-12-13 16:22:58 -05001931 /* set the upper-limit for mixer amp to 0dB for avoiding the
1932 * possible damage by overloading
1933 */
1934 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1935 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1936 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1937 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1938 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai18a815d2006-03-01 19:54:39 +01001939 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001940 case AD1981_THINKPAD:
1941 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001942 spec->input_mux = &ad1981_thinkpad_capture_source;
Daniel T Chenb8e80cf2010-03-30 13:29:28 -04001943 /* set the upper-limit for mixer amp to 0dB for avoiding the
1944 * possible damage by overloading
1945 */
1946 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1947 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1948 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1949 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1950 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai01686c52006-04-18 12:54:11 +02001951 break;
Tobin Davis18768992007-03-12 22:20:51 +01001952 case AD1981_TOSHIBA:
1953 spec->mixers[0] = ad1981_hp_mixers;
1954 spec->mixers[1] = ad1981_toshiba_mixers;
1955 spec->num_init_verbs = 2;
1956 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1957 spec->multiout.dig_out_nid = 0;
1958 spec->input_mux = &ad1981_hp_capture_source;
1959 codec->patch_ops.init = ad1981_hp_init;
1960 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1961 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001962 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01001963
1964 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001965 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001966
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001967 return 0;
1968}
1969
1970
1971/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001972 * AD1988
1973 *
1974 * Output pins and routes
1975 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001976 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001977 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1978 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1979 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1980 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1981 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1982 * port-F 0x16 (mute) <- 0x2a <- 06
1983 * port-G 0x24 (mute) <- 0x27 <- 05
1984 * port-H 0x25 (mute) <- 0x28 <- 0a
1985 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1986 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001987 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1988 * (*) 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 +01001989 *
1990 * Input pins and routes
1991 *
1992 * pin boost mix input # / adc input #
1993 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1994 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1995 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1996 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1997 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1998 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1999 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
2000 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
2001 *
2002 *
2003 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01002004 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002005 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002006 *
2007 * Inputs of Analog Mix (0x20)
2008 * 0:Port-B (front mic)
2009 * 1:Port-C/G/H (line-in)
2010 * 2:Port-A
2011 * 3:Port-D (line-in/2)
2012 * 4:Port-E/G/H (mic-in)
2013 * 5:Port-F (mic2-in)
2014 * 6:CD
2015 * 7:Beep
2016 *
2017 * ADC selection
2018 * 0:Port-A
2019 * 1:Port-B (front mic-in)
2020 * 2:Port-C (line-in)
2021 * 3:Port-F (mic2-in)
2022 * 4:Port-E (mic-in)
2023 * 5:CD
2024 * 6:Port-G
2025 * 7:Port-H
2026 * 8:Port-D (line-in/2)
2027 * 9:Mix
2028 *
2029 * Proposed pin assignments by the datasheet
2030 *
2031 * 6-stack
2032 * Port-A front headphone
2033 * B front mic-in
2034 * C rear line-in
2035 * D rear front-out
2036 * E rear mic-in
2037 * F rear surround
2038 * G rear CLFE
2039 * H rear side
2040 *
2041 * 3-stack
2042 * Port-A front headphone
2043 * B front mic
2044 * C rear line-in/surround
2045 * D rear front-out
2046 * E rear mic-in/CLFE
2047 *
2048 * laptop
2049 * Port-A headphone
2050 * B mic-in
2051 * C docking station
2052 * D internal speaker (with EAPD)
2053 * E/F quad mic array
2054 */
2055
2056
2057/* models */
2058enum {
2059 AD1988_6STACK,
2060 AD1988_6STACK_DIG,
Raymond Yauc66ddf32011-01-17 11:19:03 +01002061 AD1988_6STACK_DIG_FP,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002062 AD1988_3STACK,
2063 AD1988_3STACK_DIG,
2064 AD1988_LAPTOP,
2065 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01002066 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002067 AD1988_MODEL_LAST,
2068};
2069
Takashi Iwaid32410b12005-11-24 16:06:23 +01002070/* reivision id to check workarounds */
2071#define AD1988A_REV2 0x100200
2072
Takashi Iwai1a806f42006-07-03 15:58:16 +02002073#define is_rev2(codec) \
2074 ((codec)->vendor_id == 0x11d41988 && \
2075 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002076
2077/*
2078 * mixers
2079 */
2080
Takashi Iwai498f5b12011-05-02 11:33:15 +02002081static const hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002082 0x04, 0x06, 0x05, 0x0a
2083};
2084
Takashi Iwai498f5b12011-05-02 11:33:15 +02002085static const hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002086 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002087};
2088
2089/* for AD1988A revision-2, DAC2-4 are swapped */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002090static const hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002091 0x04, 0x05, 0x0a, 0x06
2092};
2093
Takashi Iwai498f5b12011-05-02 11:33:15 +02002094static const hda_nid_t ad1988_alt_dac_nid[1] = {
Raymond Yauc66ddf32011-01-17 11:19:03 +01002095 0x03
2096};
2097
Takashi Iwai498f5b12011-05-02 11:33:15 +02002098static const hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002099 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002100};
2101
Takashi Iwai498f5b12011-05-02 11:33:15 +02002102static const hda_nid_t ad1988_adc_nids[3] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002103 0x08, 0x09, 0x0f
2104};
2105
Takashi Iwai498f5b12011-05-02 11:33:15 +02002106static const hda_nid_t ad1988_capsrc_nids[3] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002107 0x0c, 0x0d, 0x0e
2108};
2109
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002110#define AD1988_SPDIF_OUT 0x02
2111#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002112#define AD1988_SPDIF_IN 0x07
2113
Takashi Iwai498f5b12011-05-02 11:33:15 +02002114static const hda_nid_t ad1989b_slave_dig_outs[] = {
Takashi Iwai3a08e302009-02-13 11:37:08 +01002115 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002116};
2117
Takashi Iwai498f5b12011-05-02 11:33:15 +02002118static const struct hda_input_mux ad1988_6stack_capture_source = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002119 .num_items = 5,
2120 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002121 { "Front Mic", 0x1 }, /* port-B */
2122 { "Line", 0x2 }, /* port-C */
2123 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002124 { "CD", 0x5 },
2125 { "Mix", 0x9 },
2126 },
2127};
2128
Takashi Iwai498f5b12011-05-02 11:33:15 +02002129static const struct hda_input_mux ad1988_laptop_capture_source = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002130 .num_items = 3,
2131 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002132 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002133 { "CD", 0x5 },
2134 { "Mix", 0x9 },
2135 },
2136};
2137
2138/*
2139 */
2140static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
2141 struct snd_ctl_elem_info *uinfo)
2142{
2143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2144 struct ad198x_spec *spec = codec->spec;
2145 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
2146 spec->num_channel_mode);
2147}
2148
2149static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
2150 struct snd_ctl_elem_value *ucontrol)
2151{
2152 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2153 struct ad198x_spec *spec = codec->spec;
2154 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
2155 spec->num_channel_mode, spec->multiout.max_channels);
2156}
2157
2158static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2159 struct snd_ctl_elem_value *ucontrol)
2160{
2161 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2162 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002163 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2164 spec->num_channel_mode,
2165 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002166 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002167 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002168 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002169}
2170
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002171/* 6-stack mode */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002172static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002173 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2174 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2175 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2176 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2177 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002178 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002179};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002180
Takashi Iwai498f5b12011-05-02 11:33:15 +02002181static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002182 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2183 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2184 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2185 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2186 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002187 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002188};
2189
Takashi Iwai498f5b12011-05-02 11:33:15 +02002190static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002191 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2192 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2193 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2194 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2195 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2196 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2197 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2198
2199 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2200 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2201 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2202 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2203 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2204 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2205 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2206 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2207
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002208 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002209 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2210
David Henningsson5f99f862011-01-04 15:24:24 +01002211 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2212 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002213
2214 { } /* end */
2215};
2216
Takashi Iwai498f5b12011-05-02 11:33:15 +02002217static const struct snd_kcontrol_new ad1988_6stack_fp_mixers[] = {
Raymond Yauc66ddf32011-01-17 11:19:03 +01002218 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2219
Raymond Yauc66ddf32011-01-17 11:19:03 +01002220 { } /* end */
2221};
2222
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002223/* 3-stack mode */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002224static const struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002225 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002226 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002227 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2228 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002229 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002230};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002231
Takashi Iwai498f5b12011-05-02 11:33:15 +02002232static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002233 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002234 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2235 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2236 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002237 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002238};
2239
Takashi Iwai498f5b12011-05-02 11:33:15 +02002240static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002241 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002242 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2243 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2244 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002245 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2246 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2247
2248 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2249 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2250 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2251 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2252 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2253 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2254 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2255 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2256
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002257 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002258 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2259
David Henningsson5f99f862011-01-04 15:24:24 +01002260 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2261 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002262 {
2263 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2264 .name = "Channel Mode",
2265 .info = ad198x_ch_mode_info,
2266 .get = ad198x_ch_mode_get,
2267 .put = ad198x_ch_mode_put,
2268 },
2269
2270 { } /* end */
2271};
2272
2273/* laptop mode */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002274static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002275 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2276 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2277 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2278
2279 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2280 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2281 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2282 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2283 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2284 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2285
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002286 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002287 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2288
David Henningsson5f99f862011-01-04 15:24:24 +01002289 HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002290
2291 {
2292 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2293 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002294 .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
Takashi Iwai18a815d2006-03-01 19:54:39 +01002295 .info = ad198x_eapd_info,
2296 .get = ad198x_eapd_get,
2297 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +01002298 .private_value = 0x12, /* port-D */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002299 },
2300
2301 { } /* end */
2302};
2303
2304/* capture */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002305static const struct snd_kcontrol_new ad1988_capture_mixers[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002306 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2307 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2308 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2309 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2310 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2311 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2312 {
2313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2314 /* The multiple "Capture Source" controls confuse alsamixer
2315 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002316 */
2317 /* .name = "Capture Source", */
2318 .name = "Input Source",
2319 .count = 3,
2320 .info = ad198x_mux_enum_info,
2321 .get = ad198x_mux_enum_get,
2322 .put = ad198x_mux_enum_put,
2323 },
2324 { } /* end */
2325};
2326
2327static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2328 struct snd_ctl_elem_info *uinfo)
2329{
Takashi Iwai498f5b12011-05-02 11:33:15 +02002330 static const char * const texts[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002331 "PCM", "ADC1", "ADC2", "ADC3"
2332 };
2333 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2334 uinfo->count = 1;
2335 uinfo->value.enumerated.items = 4;
2336 if (uinfo->value.enumerated.item >= 4)
2337 uinfo->value.enumerated.item = 3;
2338 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2339 return 0;
2340}
2341
2342static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2343 struct snd_ctl_elem_value *ucontrol)
2344{
2345 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2346 unsigned int sel;
2347
Takashi Iwaibddcf542007-07-24 18:04:05 +02002348 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2349 AC_AMP_GET_INPUT);
2350 if (!(sel & 0x80))
2351 ucontrol->value.enumerated.item[0] = 0;
2352 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002353 sel = snd_hda_codec_read(codec, 0x0b, 0,
2354 AC_VERB_GET_CONNECT_SEL, 0);
2355 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002356 sel++;
2357 else
2358 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002359 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002360 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002361 return 0;
2362}
2363
2364static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2365 struct snd_ctl_elem_value *ucontrol)
2366{
2367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002368 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002369 int change;
2370
Takashi Iwai35b26722007-05-05 12:17:17 +02002371 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002372 if (val > 3)
2373 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002374 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002375 sel = snd_hda_codec_read(codec, 0x1d, 0,
2376 AC_VERB_GET_AMP_GAIN_MUTE,
2377 AC_AMP_GET_INPUT);
2378 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002379 if (change) {
2380 snd_hda_codec_write_cache(codec, 0x1d, 0,
2381 AC_VERB_SET_AMP_GAIN_MUTE,
2382 AMP_IN_UNMUTE(0));
2383 snd_hda_codec_write_cache(codec, 0x1d, 0,
2384 AC_VERB_SET_AMP_GAIN_MUTE,
2385 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002386 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002387 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002388 sel = snd_hda_codec_read(codec, 0x1d, 0,
2389 AC_VERB_GET_AMP_GAIN_MUTE,
2390 AC_AMP_GET_INPUT | 0x01);
2391 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002392 if (change) {
2393 snd_hda_codec_write_cache(codec, 0x1d, 0,
2394 AC_VERB_SET_AMP_GAIN_MUTE,
2395 AMP_IN_MUTE(0));
2396 snd_hda_codec_write_cache(codec, 0x1d, 0,
2397 AC_VERB_SET_AMP_GAIN_MUTE,
2398 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002399 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002400 sel = snd_hda_codec_read(codec, 0x0b, 0,
2401 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2402 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002403 if (change)
2404 snd_hda_codec_write_cache(codec, 0x0b, 0,
2405 AC_VERB_SET_CONNECT_SEL,
2406 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002407 }
2408 return change;
2409}
2410
Takashi Iwai498f5b12011-05-02 11:33:15 +02002411static const struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002412 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2413 {
2414 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2415 .name = "IEC958 Playback Source",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002416 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002417 .info = ad1988_spdif_playback_source_info,
2418 .get = ad1988_spdif_playback_source_get,
2419 .put = ad1988_spdif_playback_source_put,
2420 },
2421 { } /* end */
2422};
2423
Takashi Iwai498f5b12011-05-02 11:33:15 +02002424static const struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002425 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2426 { } /* end */
2427};
2428
Takashi Iwai498f5b12011-05-02 11:33:15 +02002429static const struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002430 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002431 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002432 { } /* end */
2433};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002434
2435/*
2436 * initialization verbs
2437 */
2438
2439/*
2440 * for 6-stack (+dig)
2441 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002442static const struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002443 /* Front, Surround, CLFE, side DAC; unmute as default */
2444 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2445 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2446 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002448 /* Port-A front headphon path */
2449 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2450 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2451 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2452 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2453 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2454 /* Port-D line-out path */
2455 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2456 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2457 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2458 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2459 /* Port-F surround path */
2460 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2461 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2462 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2463 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2464 /* Port-G CLFE path */
2465 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2466 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2467 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469 /* Port-H side path */
2470 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2471 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2472 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2473 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2474 /* Mono out path */
2475 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2476 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2477 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2478 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2479 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2480 /* Port-B front mic-in path */
2481 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2482 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2483 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2484 /* Port-C line-in path */
2485 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2486 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2487 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2488 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2489 /* Port-E mic-in path */
2490 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2491 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2492 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2493 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002494 /* Analog CD Input */
2495 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002496 /* Analog Mix output amp */
2497 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002498
2499 { }
2500};
2501
Takashi Iwai498f5b12011-05-02 11:33:15 +02002502static const struct hda_verb ad1988_6stack_fp_init_verbs[] = {
Raymond Yauc66ddf32011-01-17 11:19:03 +01002503 /* Headphone; unmute as default */
2504 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2505 /* Port-A front headphon path */
2506 {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
2507 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2508 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2509 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2510 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
Raymond Yauc66ddf32011-01-17 11:19:03 +01002511
2512 { }
2513};
2514
Takashi Iwai498f5b12011-05-02 11:33:15 +02002515static const struct hda_verb ad1988_capture_init_verbs[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002516 /* mute analog mix */
2517 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2518 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2519 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2520 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2521 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2522 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2523 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2524 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2525 /* select ADCs - front-mic */
2526 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2527 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2528 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002529
2530 { }
2531};
2532
Takashi Iwai498f5b12011-05-02 11:33:15 +02002533static const struct hda_verb ad1988_spdif_init_verbs[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002534 /* SPDIF out sel */
2535 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2536 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2537 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002538 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002539 /* SPDIF out pin */
2540 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002541
2542 { }
2543};
2544
Takashi Iwai498f5b12011-05-02 11:33:15 +02002545static const struct hda_verb ad1988_spdif_in_init_verbs[] = {
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01002546 /* unmute SPDIF input pin */
2547 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2548 { }
2549};
2550
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002551/* AD1989 has no ADC -> SPDIF route */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002552static const struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002553 /* SPDIF-1 out pin */
2554 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002555 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002556 /* SPDIF-2/HDMI out pin */
2557 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2558 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002559 { }
2560};
2561
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002562/*
2563 * verbs for 3stack (+dig)
2564 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002565static const struct hda_verb ad1988_3stack_ch2_init[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002566 /* set port-C to line-in */
2567 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2568 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2569 /* set port-E to mic-in */
2570 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2571 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2572 { } /* end */
2573};
2574
Takashi Iwai498f5b12011-05-02 11:33:15 +02002575static const struct hda_verb ad1988_3stack_ch6_init[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002576 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002577 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002578 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002579 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002580 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002581 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002582 { } /* end */
2583};
2584
Takashi Iwai498f5b12011-05-02 11:33:15 +02002585static const struct hda_channel_mode ad1988_3stack_modes[2] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002586 { 2, ad1988_3stack_ch2_init },
2587 { 6, ad1988_3stack_ch6_init },
2588};
2589
Takashi Iwai498f5b12011-05-02 11:33:15 +02002590static const struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002591 /* Front, Surround, CLFE, side DAC; unmute as default */
2592 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2593 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2594 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2595 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002596 /* Port-A front headphon path */
2597 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2598 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2599 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2600 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2601 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2602 /* Port-D line-out path */
2603 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2604 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2605 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2606 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2607 /* Mono out path */
2608 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2609 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2610 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2611 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2612 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2613 /* Port-B front mic-in path */
2614 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2615 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2616 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002617 /* Port-C line-in/surround path - 6ch mode as default */
2618 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2619 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002620 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002621 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002622 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002623 /* Port-E mic-in/CLFE path - 6ch mode as default */
2624 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2625 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002626 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002627 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002628 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2629 /* mute analog mix */
2630 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2631 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2632 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2633 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2634 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2635 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2636 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2637 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2638 /* select ADCs - front-mic */
2639 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2640 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2641 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002642 /* Analog Mix output amp */
2643 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002644 { }
2645};
2646
2647/*
2648 * verbs for laptop mode (+dig)
2649 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002650static const struct hda_verb ad1988_laptop_hp_on[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002651 /* unmute port-A and mute port-D */
2652 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2653 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2654 { } /* end */
2655};
Takashi Iwai498f5b12011-05-02 11:33:15 +02002656static const struct hda_verb ad1988_laptop_hp_off[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002657 /* mute port-A and unmute port-D */
2658 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2659 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2660 { } /* end */
2661};
2662
2663#define AD1988_HP_EVENT 0x01
2664
Takashi Iwai498f5b12011-05-02 11:33:15 +02002665static const struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002666 /* Front, Surround, CLFE, side DAC; unmute as default */
2667 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2668 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2669 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2670 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002671 /* Port-A front headphon path */
2672 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2673 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2674 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2675 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2676 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2677 /* unsolicited event for pin-sense */
2678 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2679 /* Port-D line-out path + EAPD */
2680 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2681 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2682 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2683 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2684 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2685 /* Mono out path */
2686 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2687 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2688 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2689 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2690 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2691 /* Port-B mic-in path */
2692 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2694 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2695 /* Port-C docking station - try to output */
2696 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2697 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2698 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2699 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2700 /* mute analog mix */
2701 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2702 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2703 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2704 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2705 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2706 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2707 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2708 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2709 /* select ADCs - mic */
2710 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2711 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2712 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002713 /* Analog Mix output amp */
2714 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002715 { }
2716};
2717
2718static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2719{
2720 if ((res >> 26) != AD1988_HP_EVENT)
2721 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002722 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002723 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2724 else
2725 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2726}
2727
Takashi Iwaicb53c622007-08-10 17:21:45 +02002728#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02002729static const struct hda_amp_list ad1988_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02002730 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2731 { 0x20, HDA_INPUT, 1 }, /* Line */
2732 { 0x20, HDA_INPUT, 4 }, /* Mic */
2733 { 0x20, HDA_INPUT, 6 }, /* CD */
2734 { } /* end */
2735};
2736#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002737
2738/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002739 * Automatic parse of I/O pins from the BIOS configuration
2740 */
2741
Takashi Iwaid32410b12005-11-24 16:06:23 +01002742enum {
2743 AD_CTL_WIDGET_VOL,
2744 AD_CTL_WIDGET_MUTE,
2745 AD_CTL_BIND_MUTE,
2746};
Takashi Iwai498f5b12011-05-02 11:33:15 +02002747static const struct snd_kcontrol_new ad1988_control_templates[] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002748 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2749 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2750 HDA_BIND_MUTE(NULL, 0, 0, 0),
2751};
2752
2753/* add dynamic controls */
2754static int add_control(struct ad198x_spec *spec, int type, const char *name,
2755 unsigned long val)
2756{
2757 struct snd_kcontrol_new *knew;
2758
Takashi Iwai603c4012008-07-30 15:01:44 +02002759 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2760 knew = snd_array_new(&spec->kctls);
2761 if (!knew)
2762 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002763 *knew = ad1988_control_templates[type];
2764 knew->name = kstrdup(name, GFP_KERNEL);
2765 if (! knew->name)
2766 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002767 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002768 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002769 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002770 return 0;
2771}
2772
2773#define AD1988_PIN_CD_NID 0x18
2774#define AD1988_PIN_BEEP_NID 0x10
2775
Takashi Iwai498f5b12011-05-02 11:33:15 +02002776static const hda_nid_t ad1988_mixer_nids[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002777 /* A B C D E F G H */
2778 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2779};
2780
2781static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2782{
Takashi Iwai498f5b12011-05-02 11:33:15 +02002783 static const hda_nid_t idx_to_dac[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002784 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002785 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002786 };
Takashi Iwai498f5b12011-05-02 11:33:15 +02002787 static const hda_nid_t idx_to_dac_rev2[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002788 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002789 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002790 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002791 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002792 return idx_to_dac_rev2[idx];
2793 else
2794 return idx_to_dac[idx];
2795}
2796
Takashi Iwai498f5b12011-05-02 11:33:15 +02002797static const hda_nid_t ad1988_boost_nids[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002798 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2799};
2800
2801static int ad1988_pin_idx(hda_nid_t nid)
2802{
Takashi Iwai498f5b12011-05-02 11:33:15 +02002803 static const hda_nid_t ad1988_io_pins[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002804 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2805 };
2806 int i;
2807 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2808 if (ad1988_io_pins[i] == nid)
2809 return i;
2810 return 0; /* should be -1 */
2811}
2812
2813static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2814{
Takashi Iwai498f5b12011-05-02 11:33:15 +02002815 static const int loopback_idx[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002816 2, 0, 1, 3, 4, 5, 1, 4
2817 };
2818 switch (nid) {
2819 case AD1988_PIN_CD_NID:
2820 return 6;
2821 default:
2822 return loopback_idx[ad1988_pin_idx(nid)];
2823 }
2824}
2825
2826static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2827{
Takashi Iwai498f5b12011-05-02 11:33:15 +02002828 static const int adc_idx[8] = {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002829 0, 1, 2, 8, 4, 3, 6, 7
2830 };
2831 switch (nid) {
2832 case AD1988_PIN_CD_NID:
2833 return 5;
2834 default:
2835 return adc_idx[ad1988_pin_idx(nid)];
2836 }
2837}
2838
2839/* fill in the dac_nids table from the parsed pin configuration */
2840static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2841 const struct auto_pin_cfg *cfg)
2842{
2843 struct ad198x_spec *spec = codec->spec;
2844 int i, idx;
2845
2846 spec->multiout.dac_nids = spec->private_dac_nids;
2847
2848 /* check the pins hardwired to audio widget */
2849 for (i = 0; i < cfg->line_outs; i++) {
2850 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
Takashi Iwaidda14412011-05-02 11:29:30 +02002851 spec->private_dac_nids[i] = ad1988_idx_to_dac(codec, idx);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002852 }
2853 spec->multiout.num_dacs = cfg->line_outs;
2854 return 0;
2855}
2856
2857/* add playback controls from the parsed DAC table */
2858static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2859 const struct auto_pin_cfg *cfg)
2860{
2861 char name[32];
Takashi Iwaiea734962011-01-17 11:29:34 +01002862 static const char * const chname[4] = {
2863 "Front", "Surround", NULL /*CLFE*/, "Side"
2864 };
Takashi Iwaid32410b12005-11-24 16:06:23 +01002865 hda_nid_t nid;
2866 int i, err;
2867
2868 for (i = 0; i < cfg->line_outs; i++) {
2869 hda_nid_t dac = spec->multiout.dac_nids[i];
2870 if (! dac)
2871 continue;
2872 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2873 if (i == 2) {
2874 /* Center/LFE */
2875 err = add_control(spec, AD_CTL_WIDGET_VOL,
2876 "Center Playback Volume",
2877 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2878 if (err < 0)
2879 return err;
2880 err = add_control(spec, AD_CTL_WIDGET_VOL,
2881 "LFE Playback Volume",
2882 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2883 if (err < 0)
2884 return err;
2885 err = add_control(spec, AD_CTL_BIND_MUTE,
2886 "Center Playback Switch",
2887 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2888 if (err < 0)
2889 return err;
2890 err = add_control(spec, AD_CTL_BIND_MUTE,
2891 "LFE Playback Switch",
2892 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2893 if (err < 0)
2894 return err;
2895 } else {
2896 sprintf(name, "%s Playback Volume", chname[i]);
2897 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2898 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2899 if (err < 0)
2900 return err;
2901 sprintf(name, "%s Playback Switch", chname[i]);
2902 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2903 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2904 if (err < 0)
2905 return err;
2906 }
2907 }
2908 return 0;
2909}
2910
2911/* add playback controls for speaker and HP outputs */
2912static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2913 const char *pfx)
2914{
2915 struct ad198x_spec *spec = codec->spec;
2916 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002917 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002918 char name[32];
2919
2920 if (! pin)
2921 return 0;
2922
2923 idx = ad1988_pin_idx(pin);
2924 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002925 /* check whether the corresponding DAC was already taken */
2926 for (i = 0; i < spec->autocfg.line_outs; i++) {
2927 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2928 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2929 if (dac == nid)
2930 break;
2931 }
2932 if (i >= spec->autocfg.line_outs) {
2933 /* specify the DAC as the extra output */
2934 if (!spec->multiout.hp_nid)
2935 spec->multiout.hp_nid = nid;
2936 else
2937 spec->multiout.extra_out_nid[0] = nid;
2938 /* control HP volume/switch on the output mixer amp */
2939 sprintf(name, "%s Playback Volume", pfx);
2940 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2941 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2942 if (err < 0)
2943 return err;
2944 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002945 nid = ad1988_mixer_nids[idx];
2946 sprintf(name, "%s Playback Switch", pfx);
2947 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2948 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2949 return err;
2950 return 0;
2951}
2952
2953/* create input playback/capture controls for the given pin */
2954static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
Takashi Iwai9e042e72010-08-30 13:04:44 +02002955 const char *ctlname, int ctlidx, int boost)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002956{
2957 char name[32];
2958 int err, idx;
2959
2960 sprintf(name, "%s Playback Volume", ctlname);
2961 idx = ad1988_pin_to_loopback_idx(pin);
2962 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2963 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2964 return err;
2965 sprintf(name, "%s Playback Switch", ctlname);
2966 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2967 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2968 return err;
2969 if (boost) {
2970 hda_nid_t bnid;
2971 idx = ad1988_pin_idx(pin);
2972 bnid = ad1988_boost_nids[idx];
2973 if (bnid) {
David Henningsson5f99f862011-01-04 15:24:24 +01002974 sprintf(name, "%s Boost Volume", ctlname);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002975 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2976 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2977
2978 }
2979 }
2980 return 0;
2981}
2982
2983/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02002984static int ad1988_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaid32410b12005-11-24 16:06:23 +01002985 const struct auto_pin_cfg *cfg)
2986{
Takashi Iwai10a20af2010-09-09 16:28:02 +02002987 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002988 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002989 int i, err, type, type_idx;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002990
Takashi Iwai9e042e72010-08-30 13:04:44 +02002991 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002992 const char *label;
Takashi Iwai9e042e72010-08-30 13:04:44 +02002993 type = cfg->inputs[i].type;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002994 label = hda_get_autocfg_input_label(codec, cfg, i);
2995 snd_hda_add_imux_item(imux, label,
2996 ad1988_pin_to_adc_idx(cfg->inputs[i].pin),
2997 &type_idx);
Takashi Iwai9e042e72010-08-30 13:04:44 +02002998 err = new_analog_input(spec, cfg->inputs[i].pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002999 label, type_idx,
Takashi Iwai86e29592010-09-09 14:50:17 +02003000 type == AUTO_PIN_MIC);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003001 if (err < 0)
3002 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003003 }
Takashi Iwai10a20af2010-09-09 16:28:02 +02003004 snd_hda_add_imux_item(imux, "Mix", 9, NULL);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003005
3006 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
3007 "Analog Mix Playback Volume",
3008 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
3009 return err;
3010 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
3011 "Analog Mix Playback Switch",
3012 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
3013 return err;
3014
3015 return 0;
3016}
3017
3018static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
3019 hda_nid_t nid, int pin_type,
3020 int dac_idx)
3021{
3022 /* set as output */
3023 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
3024 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3025 switch (nid) {
3026 case 0x11: /* port-A - DAC 04 */
3027 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3028 break;
3029 case 0x14: /* port-B - DAC 06 */
3030 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
3031 break;
3032 case 0x15: /* port-C - DAC 05 */
3033 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
3034 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003035 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01003036 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3037 break;
3038 case 0x13: /* mono - DAC 04 */
3039 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3040 break;
3041 }
3042}
3043
3044static void ad1988_auto_init_multi_out(struct hda_codec *codec)
3045{
3046 struct ad198x_spec *spec = codec->spec;
3047 int i;
3048
3049 for (i = 0; i < spec->autocfg.line_outs; i++) {
3050 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3051 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
3052 }
3053}
3054
3055static void ad1988_auto_init_extra_out(struct hda_codec *codec)
3056{
3057 struct ad198x_spec *spec = codec->spec;
3058 hda_nid_t pin;
3059
Takashi Iwai82bc9552006-03-21 11:24:42 +01003060 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01003061 if (pin) /* connect to front */
3062 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003063 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01003064 if (pin) /* connect to front */
3065 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3066}
3067
3068static void ad1988_auto_init_analog_input(struct hda_codec *codec)
3069{
3070 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9e042e72010-08-30 13:04:44 +02003071 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003072 int i, idx;
3073
Takashi Iwai9e042e72010-08-30 13:04:44 +02003074 for (i = 0; i < cfg->num_inputs; i++) {
3075 hda_nid_t nid = cfg->inputs[i].pin;
Adrian Wilkins5a2d2272011-05-19 21:52:38 +01003076 int type = cfg->inputs[i].type;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003077 switch (nid) {
3078 case 0x15: /* port-C */
3079 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3080 break;
3081 case 0x17: /* port-E */
3082 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3083 break;
3084 }
3085 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
Adrian Wilkins5a2d2272011-05-19 21:52:38 +01003086 type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003087 if (nid != AD1988_PIN_CD_NID)
3088 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3089 AMP_OUT_MUTE);
3090 idx = ad1988_pin_idx(nid);
3091 if (ad1988_boost_nids[idx])
3092 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
3093 AC_VERB_SET_AMP_GAIN_MUTE,
3094 AMP_OUT_ZERO);
3095 }
3096}
3097
3098/* parse the BIOS configuration and set up the alc_spec */
3099/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
3100static int ad1988_parse_auto_config(struct hda_codec *codec)
3101{
3102 struct ad198x_spec *spec = codec->spec;
3103 int err;
3104
Kailang Yangdf694da2005-12-05 19:42:22 +01003105 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003106 return err;
3107 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3108 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003109 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003110 return 0; /* can't find valid BIOS pin config */
3111 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01003112 (err = ad1988_auto_create_extra_out(codec,
3113 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003114 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003115 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003116 "Headphone")) < 0 ||
Takashi Iwai10a20af2010-09-09 16:28:02 +02003117 (err = ad1988_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003118 return err;
3119
3120 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3121
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003122 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003123 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3124 if (spec->autocfg.dig_in_pin)
3125 spec->dig_in_nid = AD1988_SPDIF_IN;
3126
Takashi Iwai603c4012008-07-30 15:01:44 +02003127 if (spec->kctls.list)
3128 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003129
3130 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
3131
3132 spec->input_mux = &spec->private_imux;
3133
3134 return 1;
3135}
3136
3137/* init callback for auto-configuration model -- overriding the default init */
3138static int ad1988_auto_init(struct hda_codec *codec)
3139{
3140 ad198x_init(codec);
3141 ad1988_auto_init_multi_out(codec);
3142 ad1988_auto_init_extra_out(codec);
3143 ad1988_auto_init_analog_input(codec);
3144 return 0;
3145}
3146
Takashi Iwaid32410b12005-11-24 16:06:23 +01003147/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003148 */
3149
Takashi Iwaiea734962011-01-17 11:29:34 +01003150static const char * const ad1988_models[AD1988_MODEL_LAST] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003151 [AD1988_6STACK] = "6stack",
3152 [AD1988_6STACK_DIG] = "6stack-dig",
Raymond Yauc66ddf32011-01-17 11:19:03 +01003153 [AD1988_6STACK_DIG_FP] = "6stack-dig-fp",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003154 [AD1988_3STACK] = "3stack",
3155 [AD1988_3STACK_DIG] = "3stack-dig",
3156 [AD1988_LAPTOP] = "laptop",
3157 [AD1988_LAPTOP_DIG] = "laptop-dig",
3158 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003159};
3160
Takashi Iwai498f5b12011-05-02 11:33:15 +02003161static const struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01003162 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01003163 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02003164 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Tony Vroon4e60b4f2011-05-24 22:16:15 +01003165 SND_PCI_QUIRK(0x1043, 0x82c0, "Asus M3N-HT Deluxe", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07003166 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003167 {}
3168};
3169
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003170static int patch_ad1988(struct hda_codec *codec)
3171{
3172 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003173 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003174
3175 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3176 if (spec == NULL)
3177 return -ENOMEM;
3178
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003179 codec->spec = spec;
3180
Takashi Iwai1a806f42006-07-03 15:58:16 +02003181 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003182 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3183
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003184 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003185 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003186 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02003187 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3188 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003189 board_config = AD1988_AUTO;
3190 }
3191
3192 if (board_config == AD1988_AUTO) {
3193 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003194 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003195 if (err < 0) {
3196 ad198x_free(codec);
3197 return err;
3198 } else if (! err) {
3199 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3200 board_config = AD1988_6STACK;
3201 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003202 }
3203
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003204 err = snd_hda_attach_beep_device(codec, 0x10);
3205 if (err < 0) {
3206 ad198x_free(codec);
3207 return err;
3208 }
3209 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3210
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003211 switch (board_config) {
3212 case AD1988_6STACK:
3213 case AD1988_6STACK_DIG:
Raymond Yauc66ddf32011-01-17 11:19:03 +01003214 case AD1988_6STACK_DIG_FP:
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003215 spec->multiout.max_channels = 8;
3216 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003217 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003218 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3219 else
3220 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003221 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003222 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003223 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003224 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3225 else
3226 spec->mixers[0] = ad1988_6stack_mixers1;
Raymond Yau28220842011-02-08 19:58:25 +08003227 spec->mixers[1] = ad1988_6stack_mixers2;
3228 spec->num_init_verbs = 1;
3229 spec->init_verbs[0] = ad1988_6stack_init_verbs;
Raymond Yauc66ddf32011-01-17 11:19:03 +01003230 if (board_config == AD1988_6STACK_DIG_FP) {
Raymond Yau28220842011-02-08 19:58:25 +08003231 spec->num_mixers++;
3232 spec->mixers[2] = ad1988_6stack_fp_mixers;
3233 spec->num_init_verbs++;
3234 spec->init_verbs[1] = ad1988_6stack_fp_init_verbs;
Raymond Yauc66ddf32011-01-17 11:19:03 +01003235 spec->slave_vols = ad1988_6stack_fp_slave_vols;
3236 spec->slave_sws = ad1988_6stack_fp_slave_sws;
3237 spec->alt_dac_nid = ad1988_alt_dac_nid;
3238 spec->stream_analog_alt_playback =
3239 &ad198x_pcm_analog_alt_playback;
Raymond Yau28220842011-02-08 19:58:25 +08003240 }
Raymond Yauc66ddf32011-01-17 11:19:03 +01003241 if ((board_config == AD1988_6STACK_DIG) ||
3242 (board_config == AD1988_6STACK_DIG_FP)) {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003243 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3244 spec->dig_in_nid = AD1988_SPDIF_IN;
3245 }
3246 break;
3247 case AD1988_3STACK:
3248 case AD1988_3STACK_DIG:
3249 spec->multiout.max_channels = 6;
3250 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003251 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003252 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3253 else
3254 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003255 spec->input_mux = &ad1988_6stack_capture_source;
3256 spec->channel_mode = ad1988_3stack_modes;
3257 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003258 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003259 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003260 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3261 else
3262 spec->mixers[0] = ad1988_3stack_mixers1;
3263 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003264 spec->num_init_verbs = 1;
3265 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3266 if (board_config == AD1988_3STACK_DIG)
3267 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3268 break;
3269 case AD1988_LAPTOP:
3270 case AD1988_LAPTOP_DIG:
3271 spec->multiout.max_channels = 2;
3272 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003273 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003274 spec->input_mux = &ad1988_laptop_capture_source;
3275 spec->num_mixers = 1;
3276 spec->mixers[0] = ad1988_laptop_mixers;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01003277 spec->inv_eapd = 1; /* inverted EAPD */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003278 spec->num_init_verbs = 1;
3279 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3280 if (board_config == AD1988_LAPTOP_DIG)
3281 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3282 break;
3283 }
3284
Takashi Iwaid32410b12005-11-24 16:06:23 +01003285 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3286 spec->adc_nids = ad1988_adc_nids;
3287 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003288 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3289 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3290 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003291 if (codec->vendor_id >= 0x11d4989a) {
3292 spec->mixers[spec->num_mixers++] =
3293 ad1989_spdif_out_mixers;
3294 spec->init_verbs[spec->num_init_verbs++] =
3295 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003296 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003297 } else {
3298 spec->mixers[spec->num_mixers++] =
3299 ad1988_spdif_out_mixers;
3300 spec->init_verbs[spec->num_init_verbs++] =
3301 ad1988_spdif_init_verbs;
3302 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003303 }
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003304 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003305 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003306 spec->init_verbs[spec->num_init_verbs++] =
3307 ad1988_spdif_in_init_verbs;
3308 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003309
3310 codec->patch_ops = ad198x_patch_ops;
3311 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003312 case AD1988_AUTO:
3313 codec->patch_ops.init = ad1988_auto_init;
3314 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003315 case AD1988_LAPTOP:
3316 case AD1988_LAPTOP_DIG:
3317 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3318 break;
3319 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003320#ifdef CONFIG_SND_HDA_POWER_SAVE
3321 spec->loopback.amplist = ad1988_loopbacks;
3322#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003323 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003324
Takashi Iwai729d55b2009-12-25 22:49:01 +01003325 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02003326 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01003327
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003328 return 0;
3329}
3330
3331
3332/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003333 * AD1884 / AD1984
3334 *
3335 * port-B - front line/mic-in
3336 * port-E - aux in/out
3337 * port-F - aux in/out
3338 * port-C - rear line/mic-in
3339 * port-D - rear line/hp-out
3340 * port-A - front line/hp-out
3341 *
3342 * AD1984 = AD1884 + two digital mic-ins
3343 *
3344 * FIXME:
3345 * For simplicity, we share the single DAC for both HP and line-outs
3346 * right now. The inidividual playbacks could be easily implemented,
3347 * but no build-up framework is given, so far.
3348 */
3349
Takashi Iwai498f5b12011-05-02 11:33:15 +02003350static const hda_nid_t ad1884_dac_nids[1] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003351 0x04,
3352};
3353
Takashi Iwai498f5b12011-05-02 11:33:15 +02003354static const hda_nid_t ad1884_adc_nids[2] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003355 0x08, 0x09,
3356};
3357
Takashi Iwai498f5b12011-05-02 11:33:15 +02003358static const hda_nid_t ad1884_capsrc_nids[2] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003359 0x0c, 0x0d,
3360};
3361
3362#define AD1884_SPDIF_OUT 0x02
3363
Takashi Iwai498f5b12011-05-02 11:33:15 +02003364static const struct hda_input_mux ad1884_capture_source = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003365 .num_items = 4,
3366 .items = {
3367 { "Front Mic", 0x0 },
3368 { "Mic", 0x1 },
3369 { "CD", 0x2 },
3370 { "Mix", 0x3 },
3371 },
3372};
3373
Takashi Iwai498f5b12011-05-02 11:33:15 +02003374static const struct snd_kcontrol_new ad1884_base_mixers[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003375 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3376 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3377 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3378 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3379 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3380 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3381 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3382 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3383 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3384 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3385 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3386 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003387 HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3388 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003389 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3390 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3391 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3392 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3393 {
3394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3395 /* The multiple "Capture Source" controls confuse alsamixer
3396 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003397 */
3398 /* .name = "Capture Source", */
3399 .name = "Input Source",
3400 .count = 2,
3401 .info = ad198x_mux_enum_info,
3402 .get = ad198x_mux_enum_get,
3403 .put = ad198x_mux_enum_put,
3404 },
3405 /* SPDIF controls */
3406 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3407 {
3408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3409 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3410 /* identical with ad1983 */
3411 .info = ad1983_spdif_route_info,
3412 .get = ad1983_spdif_route_get,
3413 .put = ad1983_spdif_route_put,
3414 },
3415 { } /* end */
3416};
3417
Takashi Iwai498f5b12011-05-02 11:33:15 +02003418static const struct snd_kcontrol_new ad1984_dmic_mixers[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003419 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3420 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3421 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003422 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003423 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003424 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003425 { } /* end */
3426};
3427
3428/*
3429 * initialization verbs
3430 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003431static const struct hda_verb ad1884_init_verbs[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003432 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003433 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3434 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003435 /* Port-A (HP) mixer */
3436 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3437 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3438 /* Port-A pin */
3439 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3440 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3441 /* HP selector - select DAC2 */
3442 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3443 /* Port-D (Line-out) mixer */
3444 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3445 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3446 /* Port-D pin */
3447 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3448 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3449 /* Mono-out mixer */
3450 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3451 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3452 /* Mono-out pin */
3453 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3455 /* Mono selector */
3456 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3457 /* Port-B (front mic) pin */
3458 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003459 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003460 /* Port-C (rear mic) pin */
3461 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003462 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003463 /* Analog mixer; mute as default */
3464 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3465 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3466 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3467 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3468 /* Analog Mix output amp */
3469 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3470 /* SPDIF output selector */
3471 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3472 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3473 { } /* end */
3474};
3475
Takashi Iwaicb53c622007-08-10 17:21:45 +02003476#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02003477static const struct hda_amp_list ad1884_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02003478 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3479 { 0x20, HDA_INPUT, 1 }, /* Mic */
3480 { 0x20, HDA_INPUT, 2 }, /* CD */
3481 { 0x20, HDA_INPUT, 4 }, /* Docking */
3482 { } /* end */
3483};
3484#endif
3485
Takashi Iwaiea734962011-01-17 11:29:34 +01003486static const char * const ad1884_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01003487 "PCM Playback Volume",
3488 "Mic Playback Volume",
3489 "Mono Playback Volume",
3490 "Front Mic Playback Volume",
3491 "Mic Playback Volume",
3492 "CD Playback Volume",
3493 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003494 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003495 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003496 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003497 NULL
3498};
3499
Takashi Iwai2bac6472007-05-18 18:21:41 +02003500static int patch_ad1884(struct hda_codec *codec)
3501{
3502 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003503 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003504
3505 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3506 if (spec == NULL)
3507 return -ENOMEM;
3508
Takashi Iwai2bac6472007-05-18 18:21:41 +02003509 codec->spec = spec;
3510
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003511 err = snd_hda_attach_beep_device(codec, 0x10);
3512 if (err < 0) {
3513 ad198x_free(codec);
3514 return err;
3515 }
3516 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3517
Takashi Iwai2bac6472007-05-18 18:21:41 +02003518 spec->multiout.max_channels = 2;
3519 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3520 spec->multiout.dac_nids = ad1884_dac_nids;
3521 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3522 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3523 spec->adc_nids = ad1884_adc_nids;
3524 spec->capsrc_nids = ad1884_capsrc_nids;
3525 spec->input_mux = &ad1884_capture_source;
3526 spec->num_mixers = 1;
3527 spec->mixers[0] = ad1884_base_mixers;
3528 spec->num_init_verbs = 1;
3529 spec->init_verbs[0] = ad1884_init_verbs;
3530 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003531#ifdef CONFIG_SND_HDA_POWER_SAVE
3532 spec->loopback.amplist = ad1884_loopbacks;
3533#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003534 spec->vmaster_nid = 0x04;
3535 /* we need to cover all playback volumes */
3536 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003537
3538 codec->patch_ops = ad198x_patch_ops;
3539
Takashi Iwai729d55b2009-12-25 22:49:01 +01003540 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02003541 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01003542
Takashi Iwai2bac6472007-05-18 18:21:41 +02003543 return 0;
3544}
3545
3546/*
3547 * Lenovo Thinkpad T61/X61
3548 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003549static const struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003550 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003551 .items = {
3552 { "Mic", 0x0 },
3553 { "Internal Mic", 0x1 },
3554 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003555 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003556 },
3557};
3558
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003559
3560/*
3561 * Dell Precision T3400
3562 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003563static const struct hda_input_mux ad1984_dell_desktop_capture_source = {
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003564 .num_items = 3,
3565 .items = {
3566 { "Front Mic", 0x0 },
3567 { "Line-In", 0x1 },
3568 { "Mix", 0x3 },
3569 },
3570};
3571
3572
Takashi Iwai498f5b12011-05-02 11:33:15 +02003573static const struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003574 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3575 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3576 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3577 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3578 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3579 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3580 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3581 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003582 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3583 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003584 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3585 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003586 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3587 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3588 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003589 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3590 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3591 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3592 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3593 {
3594 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3595 /* The multiple "Capture Source" controls confuse alsamixer
3596 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003597 */
3598 /* .name = "Capture Source", */
3599 .name = "Input Source",
3600 .count = 2,
3601 .info = ad198x_mux_enum_info,
3602 .get = ad198x_mux_enum_get,
3603 .put = ad198x_mux_enum_put,
3604 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003605 /* SPDIF controls */
3606 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3607 {
3608 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3609 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3610 /* identical with ad1983 */
3611 .info = ad1983_spdif_route_info,
3612 .get = ad1983_spdif_route_get,
3613 .put = ad1983_spdif_route_put,
3614 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003615 { } /* end */
3616};
3617
3618/* additional verbs */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003619static const struct hda_verb ad1984_thinkpad_init_verbs[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003620 /* Port-E (docking station mic) pin */
3621 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3622 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3623 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003624 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003625 /* Analog PC Beeper - allow firmware/ACPI beeps */
3626 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003627 /* Analog mixer - docking mic; mute as default */
3628 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003629 /* enable EAPD bit */
3630 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003631 { } /* end */
3632};
3633
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003634/*
3635 * Dell Precision T3400
3636 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003637static const struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003638 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3639 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3640 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3641 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3642 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3643 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3644 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3645 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3646 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003647 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
3648 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003649 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3650 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3651 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3652 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3653 {
3654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3655 /* The multiple "Capture Source" controls confuse alsamixer
3656 * So call somewhat different..
3657 */
3658 /* .name = "Capture Source", */
3659 .name = "Input Source",
3660 .count = 2,
3661 .info = ad198x_mux_enum_info,
3662 .get = ad198x_mux_enum_get,
3663 .put = ad198x_mux_enum_put,
3664 },
3665 { } /* end */
3666};
3667
Takashi Iwai2bac6472007-05-18 18:21:41 +02003668/* Digial MIC ADC NID 0x05 + 0x06 */
3669static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3670 struct hda_codec *codec,
3671 unsigned int stream_tag,
3672 unsigned int format,
3673 struct snd_pcm_substream *substream)
3674{
3675 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3676 stream_tag, 0, format);
3677 return 0;
3678}
3679
3680static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3681 struct hda_codec *codec,
3682 struct snd_pcm_substream *substream)
3683{
Takashi Iwai888afa12008-03-18 09:57:50 +01003684 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003685 return 0;
3686}
3687
Takashi Iwai498f5b12011-05-02 11:33:15 +02003688static const struct hda_pcm_stream ad1984_pcm_dmic_capture = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003689 .substreams = 2,
3690 .channels_min = 2,
3691 .channels_max = 2,
3692 .nid = 0x05,
3693 .ops = {
3694 .prepare = ad1984_pcm_dmic_prepare,
3695 .cleanup = ad1984_pcm_dmic_cleanup
3696 },
3697};
3698
3699static int ad1984_build_pcms(struct hda_codec *codec)
3700{
3701 struct ad198x_spec *spec = codec->spec;
3702 struct hda_pcm *info;
3703 int err;
3704
3705 err = ad198x_build_pcms(codec);
3706 if (err < 0)
3707 return err;
3708
3709 info = spec->pcm_rec + codec->num_pcms;
3710 codec->num_pcms++;
3711 info->name = "AD1984 Digital Mic";
3712 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3713 return 0;
3714}
3715
3716/* models */
3717enum {
3718 AD1984_BASIC,
3719 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003720 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003721 AD1984_MODELS
3722};
3723
Takashi Iwaiea734962011-01-17 11:29:34 +01003724static const char * const ad1984_models[AD1984_MODELS] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003725 [AD1984_BASIC] = "basic",
3726 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003727 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003728};
3729
Takashi Iwai498f5b12011-05-02 11:33:15 +02003730static const struct snd_pci_quirk ad1984_cfg_tbl[] = {
Takashi Iwai2bac6472007-05-18 18:21:41 +02003731 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003732 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003733 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Luke Yelavich0f9f1ee92010-09-21 17:05:46 +10003734 SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003735 {}
3736};
3737
3738static int patch_ad1984(struct hda_codec *codec)
3739{
3740 struct ad198x_spec *spec;
3741 int board_config, err;
3742
3743 err = patch_ad1884(codec);
3744 if (err < 0)
3745 return err;
3746 spec = codec->spec;
3747 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3748 ad1984_models, ad1984_cfg_tbl);
3749 switch (board_config) {
3750 case AD1984_BASIC:
3751 /* additional digital mics */
3752 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3753 codec->patch_ops.build_pcms = ad1984_build_pcms;
3754 break;
3755 case AD1984_THINKPAD:
Jerone Young68c18692010-08-03 01:46:44 -05003756 if (codec->subsystem_id == 0x17aa20fb) {
3757 /* Thinpad X300 does not have the ability to do SPDIF,
3758 or attach to docking station to use SPDIF */
3759 spec->multiout.dig_out_nid = 0;
3760 } else
3761 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003762 spec->input_mux = &ad1984_thinkpad_capture_source;
3763 spec->mixers[0] = ad1984_thinkpad_mixers;
3764 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003765 spec->analog_beep = 1;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003766 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003767 case AD1984_DELL_DESKTOP:
3768 spec->multiout.dig_out_nid = 0;
3769 spec->input_mux = &ad1984_dell_desktop_capture_source;
3770 spec->mixers[0] = ad1984_dell_desktop_mixers;
3771 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003772 }
3773 return 0;
3774}
3775
3776
3777/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003778 * AD1883 / AD1884A / AD1984A / AD1984B
3779 *
3780 * port-B (0x14) - front mic-in
3781 * port-E (0x1c) - rear mic-in
3782 * port-F (0x16) - CD / ext out
3783 * port-C (0x15) - rear line-in
3784 * port-D (0x12) - rear line-out
3785 * port-A (0x11) - front hp-out
3786 *
3787 * AD1984A = AD1884A + digital-mic
3788 * AD1883 = equivalent with AD1984A
3789 * AD1984B = AD1984A + extra SPDIF-out
3790 *
3791 * FIXME:
3792 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3793 */
3794
Takashi Iwai498f5b12011-05-02 11:33:15 +02003795static const hda_nid_t ad1884a_dac_nids[1] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003796 0x03,
3797};
3798
3799#define ad1884a_adc_nids ad1884_adc_nids
3800#define ad1884a_capsrc_nids ad1884_capsrc_nids
3801
3802#define AD1884A_SPDIF_OUT 0x02
3803
Takashi Iwai498f5b12011-05-02 11:33:15 +02003804static const struct hda_input_mux ad1884a_capture_source = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003805 .num_items = 5,
3806 .items = {
3807 { "Front Mic", 0x0 },
3808 { "Mic", 0x4 },
3809 { "Line", 0x1 },
3810 { "CD", 0x2 },
3811 { "Mix", 0x3 },
3812 },
3813};
3814
Takashi Iwai498f5b12011-05-02 11:33:15 +02003815static const struct snd_kcontrol_new ad1884a_base_mixers[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003816 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3817 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3818 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3819 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3820 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3821 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3822 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3823 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3824 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3825 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3826 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3827 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3828 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3829 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3830 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3831 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003832 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3833 HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
3834 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003835 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3836 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3837 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3838 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3839 {
3840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3841 /* The multiple "Capture Source" controls confuse alsamixer
3842 * So call somewhat different..
3843 */
3844 /* .name = "Capture Source", */
3845 .name = "Input Source",
3846 .count = 2,
3847 .info = ad198x_mux_enum_info,
3848 .get = ad198x_mux_enum_get,
3849 .put = ad198x_mux_enum_put,
3850 },
3851 /* SPDIF controls */
3852 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3853 {
3854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3855 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3856 /* identical with ad1983 */
3857 .info = ad1983_spdif_route_info,
3858 .get = ad1983_spdif_route_get,
3859 .put = ad1983_spdif_route_put,
3860 },
3861 { } /* end */
3862};
3863
3864/*
3865 * initialization verbs
3866 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02003867static const struct hda_verb ad1884a_init_verbs[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003868 /* DACs; unmute as default */
3869 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3870 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3871 /* Port-A (HP) mixer - route only from analog mixer */
3872 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3873 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3874 /* Port-A pin */
3875 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3876 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3877 /* Port-D (Line-out) mixer - route only from analog mixer */
3878 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3879 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3880 /* Port-D pin */
3881 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3882 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3883 /* Mono-out mixer - route only from analog mixer */
3884 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3885 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3886 /* Mono-out pin */
3887 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3888 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3889 /* Port-B (front mic) pin */
3890 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003891 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003892 /* Port-C (rear line-in) pin */
3893 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003894 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003895 /* Port-E (rear mic) pin */
3896 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3897 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3898 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3899 /* Port-F (CD) pin */
3900 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3901 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3902 /* Analog mixer; mute as default */
3903 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3904 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3905 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3906 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3907 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3908 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3909 /* Analog Mix output amp */
3910 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3911 /* capture sources */
3912 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3913 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3914 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3915 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3916 /* SPDIF output amp */
3917 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3918 { } /* end */
3919};
3920
3921#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02003922static const struct hda_amp_list ad1884a_loopbacks[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003923 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3924 { 0x20, HDA_INPUT, 1 }, /* Mic */
3925 { 0x20, HDA_INPUT, 2 }, /* CD */
3926 { 0x20, HDA_INPUT, 4 }, /* Docking */
3927 { } /* end */
3928};
3929#endif
3930
3931/*
3932 * Laptop model
3933 *
3934 * Port A: Headphone jack
3935 * Port B: MIC jack
3936 * Port C: Internal MIC
3937 * Port D: Dock Line Out (if enabled)
3938 * Port E: Dock Line In (if enabled)
3939 * Port F: Internal speakers
3940 */
3941
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003942static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3943 struct snd_ctl_elem_value *ucontrol)
3944{
3945 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3946 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3947 int mute = (!ucontrol->value.integer.value[0] &&
3948 !ucontrol->value.integer.value[1]);
3949 /* toggle GPIO1 according to the mute state */
3950 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3951 mute ? 0x02 : 0x0);
3952 return ret;
3953}
Takashi Iwaic5059252008-02-16 09:43:56 +01003954
Takashi Iwai498f5b12011-05-02 11:33:15 +02003955static const struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01003956 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003957 {
3958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3959 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003960 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003961 .info = snd_hda_mixer_amp_switch_info,
3962 .get = snd_hda_mixer_amp_switch_get,
3963 .put = ad1884a_mobile_master_sw_put,
3964 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3965 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003966 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3967 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3968 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3969 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3970 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3971 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3972 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3973 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3974 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003975 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3976 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3977 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003978 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3979 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003980 { } /* end */
3981};
3982
Takashi Iwai498f5b12011-05-02 11:33:15 +02003983static const struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003984 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db172009-07-02 16:10:23 +02003985 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3986 {
3987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3988 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003989 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai099db172009-07-02 16:10:23 +02003990 .info = snd_hda_mixer_amp_switch_info,
3991 .get = snd_hda_mixer_amp_switch_get,
3992 .put = ad1884a_mobile_master_sw_put,
3993 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3994 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003995 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3996 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003997 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3998 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003999 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4000 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004001 { } /* end */
4002};
4003
Takashi Iwaic5059252008-02-16 09:43:56 +01004004/* mute internal speaker if HP is plugged */
4005static void ad1884a_hp_automute(struct hda_codec *codec)
4006{
4007 unsigned int present;
4008
Takashi Iwaid56757a2009-11-18 08:00:14 +01004009 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01004010 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
4011 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4012 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
4013 present ? 0x00 : 0x02);
4014}
4015
Takashi Iwai269ef192008-05-30 15:32:15 +02004016/* switch to external mic if plugged */
4017static void ad1884a_hp_automic(struct hda_codec *codec)
4018{
4019 unsigned int present;
4020
Takashi Iwaid56757a2009-11-18 08:00:14 +01004021 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02004022 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
4023 present ? 0 : 1);
4024}
4025
Takashi Iwaic5059252008-02-16 09:43:56 +01004026#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02004027#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01004028
4029/* unsolicited event for HP jack sensing */
4030static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4031{
Takashi Iwai269ef192008-05-30 15:32:15 +02004032 switch (res >> 26) {
4033 case AD1884A_HP_EVENT:
4034 ad1884a_hp_automute(codec);
4035 break;
4036 case AD1884A_MIC_EVENT:
4037 ad1884a_hp_automic(codec);
4038 break;
4039 }
Takashi Iwaic5059252008-02-16 09:43:56 +01004040}
4041
4042/* initialize jack-sensing, too */
4043static int ad1884a_hp_init(struct hda_codec *codec)
4044{
4045 ad198x_init(codec);
4046 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02004047 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01004048 return 0;
4049}
4050
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004051/* mute internal speaker if HP or docking HP is plugged */
4052static void ad1884a_laptop_automute(struct hda_codec *codec)
4053{
4054 unsigned int present;
4055
Takashi Iwaid56757a2009-11-18 08:00:14 +01004056 present = snd_hda_jack_detect(codec, 0x11);
4057 if (!present)
4058 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004059 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
4060 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4061 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
4062 present ? 0x00 : 0x02);
4063}
4064
4065/* switch to external mic if plugged */
4066static void ad1884a_laptop_automic(struct hda_codec *codec)
4067{
4068 unsigned int idx;
4069
Takashi Iwaid56757a2009-11-18 08:00:14 +01004070 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004071 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01004072 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004073 idx = 4;
4074 else
4075 idx = 1;
4076 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
4077}
4078
4079/* unsolicited event for HP jack sensing */
4080static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
4081 unsigned int res)
4082{
4083 switch (res >> 26) {
4084 case AD1884A_HP_EVENT:
4085 ad1884a_laptop_automute(codec);
4086 break;
4087 case AD1884A_MIC_EVENT:
4088 ad1884a_laptop_automic(codec);
4089 break;
4090 }
4091}
4092
4093/* initialize jack-sensing, too */
4094static int ad1884a_laptop_init(struct hda_codec *codec)
4095{
4096 ad198x_init(codec);
4097 ad1884a_laptop_automute(codec);
4098 ad1884a_laptop_automic(codec);
4099 return 0;
4100}
4101
Takashi Iwaic5059252008-02-16 09:43:56 +01004102/* additional verbs for laptop model */
Takashi Iwai498f5b12011-05-02 11:33:15 +02004103static const struct hda_verb ad1884a_laptop_verbs[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004104 /* Port-A (HP) pin - always unmuted */
4105 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4106 /* Port-F (int speaker) mixer - route only from analog mixer */
4107 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4108 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08004109 /* Port-F (int speaker) pin */
4110 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01004111 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08004112 /* required for compaq 6530s/6531s speaker output */
4113 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004114 /* Port-C pin - internal mic-in */
4115 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4116 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4117 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02004118 /* Port-D (docking line-out) pin - default unmuted */
4119 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01004120 /* analog mix */
4121 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4122 /* unsolicited event for pin-sense */
4123 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004124 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004125 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004126 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02004127 /* allow to touch GPIO1 (for mute control) */
4128 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4129 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4130 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01004131 { } /* end */
4132};
4133
Takashi Iwai498f5b12011-05-02 11:33:15 +02004134static const struct hda_verb ad1884a_mobile_verbs[] = {
Takashi Iwai73156132009-04-23 08:24:48 +02004135 /* DACs; unmute as default */
4136 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4137 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4138 /* Port-A (HP) mixer - route only from analog mixer */
4139 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4140 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4141 /* Port-A pin */
4142 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4143 /* Port-A (HP) pin - always unmuted */
4144 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4145 /* Port-B (mic jack) pin */
4146 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4147 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4148 /* Port-C (int mic) pin */
4149 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4150 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4151 /* Port-F (int speaker) mixer - route only from analog mixer */
4152 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4153 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4154 /* Port-F pin */
4155 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4156 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4157 /* Analog mixer; mute as default */
4158 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4159 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4160 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4161 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4162 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4163 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4164 /* Analog Mix output amp */
4165 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4166 /* capture sources */
4167 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4168 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4169 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4170 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4171 /* unsolicited event for pin-sense */
4172 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4173 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db172009-07-02 16:10:23 +02004174 /* allow to touch GPIO1 (for mute control) */
4175 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4176 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4177 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02004178 { } /* end */
4179};
4180
Takashi Iwaic5059252008-02-16 09:43:56 +01004181/*
Takashi Iwaif0813742008-03-18 12:13:03 +01004182 * Thinkpad X300
4183 * 0x11 - HP
4184 * 0x12 - speaker
4185 * 0x14 - mic-in
4186 * 0x17 - built-in mic
4187 */
4188
Takashi Iwai498f5b12011-05-02 11:33:15 +02004189static const struct hda_verb ad1984a_thinkpad_verbs[] = {
Takashi Iwaif0813742008-03-18 12:13:03 +01004190 /* HP unmute */
4191 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4192 /* analog mix */
4193 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4194 /* turn on EAPD */
4195 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4196 /* unsolicited event for pin-sense */
4197 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4198 /* internal mic - dmic */
4199 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02004200 /* set magic COEFs for dmic */
4201 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4202 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01004203 { } /* end */
4204};
4205
Takashi Iwai498f5b12011-05-02 11:33:15 +02004206static const struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
Takashi Iwaif0813742008-03-18 12:13:03 +01004207 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4208 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
4209 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4210 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4211 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4212 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004213 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
4214 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01004215 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4216 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4217 {
4218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4219 .name = "Capture Source",
4220 .info = ad198x_mux_enum_info,
4221 .get = ad198x_mux_enum_get,
4222 .put = ad198x_mux_enum_put,
4223 },
4224 { } /* end */
4225};
4226
Takashi Iwai498f5b12011-05-02 11:33:15 +02004227static const struct hda_input_mux ad1984a_thinkpad_capture_source = {
Takashi Iwaif0813742008-03-18 12:13:03 +01004228 .num_items = 3,
4229 .items = {
4230 { "Mic", 0x0 },
4231 { "Internal Mic", 0x5 },
4232 { "Mix", 0x3 },
4233 },
4234};
4235
4236/* mute internal speaker if HP is plugged */
4237static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4238{
4239 unsigned int present;
4240
Takashi Iwaid56757a2009-11-18 08:00:14 +01004241 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004242 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4243 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4244}
4245
4246/* unsolicited event for HP jack sensing */
4247static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4248 unsigned int res)
4249{
4250 if ((res >> 26) != AD1884A_HP_EVENT)
4251 return;
4252 ad1984a_thinkpad_automute(codec);
4253}
4254
4255/* initialize jack-sensing, too */
4256static int ad1984a_thinkpad_init(struct hda_codec *codec)
4257{
4258 ad198x_init(codec);
4259 ad1984a_thinkpad_automute(codec);
4260 return 0;
4261}
4262
4263/*
David Henningsson677cd902011-02-07 15:19:34 +01004264 * Precision R5500
4265 * 0x12 - HP/line-out
4266 * 0x13 - speaker (mono)
4267 * 0x15 - mic-in
4268 */
4269
Takashi Iwai498f5b12011-05-02 11:33:15 +02004270static const struct hda_verb ad1984a_precision_verbs[] = {
David Henningsson677cd902011-02-07 15:19:34 +01004271 /* Unmute main output path */
4272 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4273 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x1f}, /* 0dB */
4274 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) + 0x17}, /* 0dB */
4275 /* Analog mixer; mute as default */
4276 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4277 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4278 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4279 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4280 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4281 /* Select mic as input */
4282 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
4283 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x27}, /* 0dB */
4284 /* Configure as mic */
4285 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4286 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4287 /* HP unmute */
4288 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4289 /* turn on EAPD */
4290 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4291 /* unsolicited event for pin-sense */
4292 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4293 { } /* end */
4294};
4295
Takashi Iwai498f5b12011-05-02 11:33:15 +02004296static const struct snd_kcontrol_new ad1984a_precision_mixers[] = {
David Henningsson677cd902011-02-07 15:19:34 +01004297 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4298 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
4299 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4300 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4301 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4302 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4303 HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
4304 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4305 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x13, 0x0, HDA_OUTPUT),
4306 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4307 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4308 { } /* end */
4309};
4310
4311
4312/* mute internal speaker if HP is plugged */
4313static void ad1984a_precision_automute(struct hda_codec *codec)
4314{
4315 unsigned int present;
4316
4317 present = snd_hda_jack_detect(codec, 0x12);
4318 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
4319 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4320}
4321
4322
4323/* unsolicited event for HP jack sensing */
4324static void ad1984a_precision_unsol_event(struct hda_codec *codec,
4325 unsigned int res)
4326{
4327 if ((res >> 26) != AD1884A_HP_EVENT)
4328 return;
4329 ad1984a_precision_automute(codec);
4330}
4331
4332/* initialize jack-sensing, too */
4333static int ad1984a_precision_init(struct hda_codec *codec)
4334{
4335 ad198x_init(codec);
4336 ad1984a_precision_automute(codec);
4337 return 0;
4338}
4339
4340
4341/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004342 * HP Touchsmart
4343 * port-A (0x11) - front hp-out
4344 * port-B (0x14) - unused
4345 * port-C (0x15) - unused
4346 * port-D (0x12) - rear line out
4347 * port-E (0x1c) - front mic-in
4348 * port-F (0x16) - Internal speakers
4349 * digital-mic (0x17) - Internal mic
4350 */
4351
Takashi Iwai498f5b12011-05-02 11:33:15 +02004352static const struct hda_verb ad1984a_touchsmart_verbs[] = {
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004353 /* DACs; unmute as default */
4354 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4355 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4356 /* Port-A (HP) mixer - route only from analog mixer */
4357 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4358 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4359 /* Port-A pin */
4360 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4361 /* Port-A (HP) pin - always unmuted */
4362 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4363 /* Port-E (int speaker) mixer - route only from analog mixer */
4364 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4365 /* Port-E pin */
4366 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4367 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4368 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4369 /* Port-F (int speaker) mixer - route only from analog mixer */
4370 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4371 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4372 /* Port-F pin */
4373 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4374 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4375 /* Analog mixer; mute as default */
4376 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4377 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4378 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4379 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4380 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4381 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4382 /* Analog Mix output amp */
4383 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4384 /* capture sources */
4385 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4386 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4387 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4388 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4389 /* unsolicited event for pin-sense */
4390 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4391 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4392 /* allow to touch GPIO1 (for mute control) */
4393 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4394 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4395 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4396 /* internal mic - dmic */
4397 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4398 /* set magic COEFs for dmic */
4399 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4400 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4401 { } /* end */
4402};
4403
Takashi Iwai498f5b12011-05-02 11:33:15 +02004404static const struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004405 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4406/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4407 {
4408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01004409 .subdevice = HDA_SUBDEV_AMP_FLAG,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004410 .name = "Master Playback Switch",
4411 .info = snd_hda_mixer_amp_switch_info,
4412 .get = snd_hda_mixer_amp_switch_get,
4413 .put = ad1884a_mobile_master_sw_put,
4414 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4415 },
4416 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4417 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4418 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4419 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004420 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
4421 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004422 { } /* end */
4423};
4424
4425/* switch to external mic if plugged */
4426static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4427{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004428 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004429 snd_hda_codec_write(codec, 0x0c, 0,
4430 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004431 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004432 snd_hda_codec_write(codec, 0x0c, 0,
4433 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004434}
4435
4436
4437/* unsolicited event for HP jack sensing */
4438static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4439 unsigned int res)
4440{
4441 switch (res >> 26) {
4442 case AD1884A_HP_EVENT:
4443 ad1884a_hp_automute(codec);
4444 break;
4445 case AD1884A_MIC_EVENT:
4446 ad1984a_touchsmart_automic(codec);
4447 break;
4448 }
4449}
4450
4451/* initialize jack-sensing, too */
4452static int ad1984a_touchsmart_init(struct hda_codec *codec)
4453{
4454 ad198x_init(codec);
4455 ad1884a_hp_automute(codec);
4456 ad1984a_touchsmart_automic(codec);
4457 return 0;
4458}
4459
4460
4461/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004462 */
4463
4464enum {
4465 AD1884A_DESKTOP,
4466 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004467 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004468 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004469 AD1984A_TOUCHSMART,
David Henningsson677cd902011-02-07 15:19:34 +01004470 AD1984A_PRECISION,
Takashi Iwaic5059252008-02-16 09:43:56 +01004471 AD1884A_MODELS
4472};
4473
Takashi Iwaiea734962011-01-17 11:29:34 +01004474static const char * const ad1884a_models[AD1884A_MODELS] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004475 [AD1884A_DESKTOP] = "desktop",
4476 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004477 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004478 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004479 [AD1984A_TOUCHSMART] = "touchsmart",
David Henningsson677cd902011-02-07 15:19:34 +01004480 [AD1984A_PRECISION] = "precision",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004481};
4482
Takashi Iwai498f5b12011-05-02 11:33:15 +02004483static const struct snd_pci_quirk ad1884a_cfg_tbl[] = {
David Henningsson677cd902011-02-07 15:19:34 +01004484 SND_PCI_QUIRK(0x1028, 0x04ac, "Precision R5500", AD1984A_PRECISION),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004485 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004486 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004487 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004488 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004489 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004490 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4491 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004492 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004493 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004494 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004495 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004496};
4497
4498static int patch_ad1884a(struct hda_codec *codec)
4499{
4500 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004501 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004502
4503 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4504 if (spec == NULL)
4505 return -ENOMEM;
4506
Takashi Iwaic5059252008-02-16 09:43:56 +01004507 codec->spec = spec;
4508
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004509 err = snd_hda_attach_beep_device(codec, 0x10);
4510 if (err < 0) {
4511 ad198x_free(codec);
4512 return err;
4513 }
4514 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4515
Takashi Iwaic5059252008-02-16 09:43:56 +01004516 spec->multiout.max_channels = 2;
4517 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4518 spec->multiout.dac_nids = ad1884a_dac_nids;
4519 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4520 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4521 spec->adc_nids = ad1884a_adc_nids;
4522 spec->capsrc_nids = ad1884a_capsrc_nids;
4523 spec->input_mux = &ad1884a_capture_source;
4524 spec->num_mixers = 1;
4525 spec->mixers[0] = ad1884a_base_mixers;
4526 spec->num_init_verbs = 1;
4527 spec->init_verbs[0] = ad1884a_init_verbs;
4528 spec->spdif_route = 0;
4529#ifdef CONFIG_SND_HDA_POWER_SAVE
4530 spec->loopback.amplist = ad1884a_loopbacks;
4531#endif
4532 codec->patch_ops = ad198x_patch_ops;
4533
4534 /* override some parameters */
4535 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004536 ad1884a_models,
4537 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004538 switch (board_config) {
4539 case AD1884A_LAPTOP:
4540 spec->mixers[0] = ad1884a_laptop_mixers;
4541 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4542 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004543 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4544 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004545 /* set the upper-limit for mixer amp to 0dB for avoiding the
4546 * possible damage by overloading
4547 */
4548 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4549 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4550 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4551 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4552 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004553 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004554 case AD1884A_MOBILE:
4555 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004556 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004557 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004558 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4559 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004560 /* set the upper-limit for mixer amp to 0dB for avoiding the
4561 * possible damage by overloading
4562 */
4563 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4564 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4565 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4566 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4567 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004568 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004569 case AD1884A_THINKPAD:
4570 spec->mixers[0] = ad1984a_thinkpad_mixers;
4571 spec->init_verbs[spec->num_init_verbs++] =
4572 ad1984a_thinkpad_verbs;
4573 spec->multiout.dig_out_nid = 0;
4574 spec->input_mux = &ad1984a_thinkpad_capture_source;
4575 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4576 codec->patch_ops.init = ad1984a_thinkpad_init;
4577 break;
David Henningsson677cd902011-02-07 15:19:34 +01004578 case AD1984A_PRECISION:
4579 spec->mixers[0] = ad1984a_precision_mixers;
4580 spec->init_verbs[spec->num_init_verbs++] =
4581 ad1984a_precision_verbs;
4582 spec->multiout.dig_out_nid = 0;
4583 codec->patch_ops.unsol_event = ad1984a_precision_unsol_event;
4584 codec->patch_ops.init = ad1984a_precision_init;
4585 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004586 case AD1984A_TOUCHSMART:
4587 spec->mixers[0] = ad1984a_touchsmart_mixers;
4588 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4589 spec->multiout.dig_out_nid = 0;
4590 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4591 codec->patch_ops.init = ad1984a_touchsmart_init;
4592 /* set the upper-limit for mixer amp to 0dB for avoiding the
4593 * possible damage by overloading
4594 */
4595 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4596 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4597 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4598 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4599 (1 << AC_AMPCAP_MUTE_SHIFT));
4600 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004601 }
4602
Takashi Iwai729d55b2009-12-25 22:49:01 +01004603 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02004604 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01004605
Takashi Iwaic5059252008-02-16 09:43:56 +01004606 return 0;
4607}
4608
4609
4610/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004611 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004612 *
4613 * port-A - front hp-out
4614 * port-B - front mic-in
4615 * port-C - rear line-in, shared surr-out (3stack)
4616 * port-D - rear line-out
4617 * port-E - rear mic-in, shared clfe-out (3stack)
4618 * port-F - rear surr-out (6stack)
4619 * port-G - rear clfe-out (6stack)
4620 */
4621
Takashi Iwai498f5b12011-05-02 11:33:15 +02004622static const hda_nid_t ad1882_dac_nids[3] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004623 0x04, 0x03, 0x05
4624};
4625
Takashi Iwai498f5b12011-05-02 11:33:15 +02004626static const hda_nid_t ad1882_adc_nids[2] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004627 0x08, 0x09,
4628};
4629
Takashi Iwai498f5b12011-05-02 11:33:15 +02004630static const hda_nid_t ad1882_capsrc_nids[2] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004631 0x0c, 0x0d,
4632};
4633
4634#define AD1882_SPDIF_OUT 0x02
4635
4636/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02004637static const struct hda_input_mux ad1882_capture_source = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004638 .num_items = 5,
4639 .items = {
4640 { "Front Mic", 0x1 },
4641 { "Mic", 0x4 },
4642 { "Line", 0x2 },
4643 { "CD", 0x3 },
4644 { "Mix", 0x7 },
4645 },
4646};
4647
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004648/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02004649static const struct hda_input_mux ad1882a_capture_source = {
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004650 .num_items = 5,
4651 .items = {
4652 { "Front Mic", 0x1 },
4653 { "Mic", 0x4},
4654 { "Line", 0x2 },
4655 { "Digital Mic", 0x06 },
4656 { "Mix", 0x7 },
4657 },
4658};
4659
Takashi Iwai498f5b12011-05-02 11:33:15 +02004660static const struct snd_kcontrol_new ad1882_base_mixers[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004661 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4662 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4663 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4664 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4665 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4666 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4667 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4668 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004669
David Henningsson5f99f862011-01-04 15:24:24 +01004670 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
4671 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
4672 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
Takashi Iwai0ac85512007-06-20 15:46:13 +02004673 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4674 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4675 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4676 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4677 {
4678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4679 /* The multiple "Capture Source" controls confuse alsamixer
4680 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004681 */
4682 /* .name = "Capture Source", */
4683 .name = "Input Source",
4684 .count = 2,
4685 .info = ad198x_mux_enum_info,
4686 .get = ad198x_mux_enum_get,
4687 .put = ad198x_mux_enum_put,
4688 },
4689 /* SPDIF controls */
4690 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4691 {
4692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4693 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4694 /* identical with ad1983 */
4695 .info = ad1983_spdif_route_info,
4696 .get = ad1983_spdif_route_get,
4697 .put = ad1983_spdif_route_put,
4698 },
4699 { } /* end */
4700};
4701
Takashi Iwai498f5b12011-05-02 11:33:15 +02004702static const struct snd_kcontrol_new ad1882_loopback_mixers[] = {
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004703 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4704 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4705 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4706 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4707 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4708 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4709 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4710 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004711 { } /* end */
4712};
4713
Takashi Iwai498f5b12011-05-02 11:33:15 +02004714static const struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004715 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4716 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4717 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4718 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4719 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4720 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4721 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4722 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004723 HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004724 { } /* end */
4725};
4726
Takashi Iwai498f5b12011-05-02 11:33:15 +02004727static const struct snd_kcontrol_new ad1882_3stack_mixers[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004728 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4729 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4730 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4731 {
4732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4733 .name = "Channel Mode",
4734 .info = ad198x_ch_mode_info,
4735 .get = ad198x_ch_mode_get,
4736 .put = ad198x_ch_mode_put,
4737 },
4738 { } /* end */
4739};
4740
Takashi Iwai498f5b12011-05-02 11:33:15 +02004741static const struct snd_kcontrol_new ad1882_6stack_mixers[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004742 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4743 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4744 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4745 { } /* end */
4746};
4747
Takashi Iwai498f5b12011-05-02 11:33:15 +02004748static const struct hda_verb ad1882_ch2_init[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004749 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4750 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4751 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4752 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4753 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4754 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4755 { } /* end */
4756};
4757
Takashi Iwai498f5b12011-05-02 11:33:15 +02004758static const struct hda_verb ad1882_ch4_init[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004759 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4760 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4761 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4762 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4763 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4764 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4765 { } /* end */
4766};
4767
Takashi Iwai498f5b12011-05-02 11:33:15 +02004768static const struct hda_verb ad1882_ch6_init[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004769 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4770 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4771 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4772 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4773 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4774 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4775 { } /* end */
4776};
4777
Takashi Iwai498f5b12011-05-02 11:33:15 +02004778static const struct hda_channel_mode ad1882_modes[3] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004779 { 2, ad1882_ch2_init },
4780 { 4, ad1882_ch4_init },
4781 { 6, ad1882_ch6_init },
4782};
4783
4784/*
4785 * initialization verbs
4786 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02004787static const struct hda_verb ad1882_init_verbs[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004788 /* DACs; mute as default */
4789 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4790 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4791 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4792 /* Port-A (HP) mixer */
4793 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4794 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4795 /* Port-A pin */
4796 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4797 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4798 /* HP selector - select DAC2 */
4799 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4800 /* Port-D (Line-out) mixer */
4801 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4802 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4803 /* Port-D pin */
4804 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4805 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4806 /* Mono-out mixer */
4807 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4808 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4809 /* Mono-out pin */
4810 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4811 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4812 /* Port-B (front mic) pin */
4813 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4814 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4815 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4816 /* Port-C (line-in) pin */
4817 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4818 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4819 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4820 /* Port-C mixer - mute as input */
4821 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4822 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4823 /* Port-E (mic-in) pin */
4824 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4825 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4826 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4827 /* Port-E mixer - mute as input */
4828 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4829 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4830 /* Port-F (surround) */
4831 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4832 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4833 /* Port-G (CLFE) */
4834 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4835 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4836 /* Analog mixer; mute as default */
4837 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4838 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4839 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4840 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4841 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4842 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4843 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4844 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4845 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4846 /* Analog Mix output amp */
4847 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4848 /* SPDIF output selector */
4849 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4850 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4851 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4852 { } /* end */
4853};
4854
Takashi Iwaicb53c622007-08-10 17:21:45 +02004855#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai498f5b12011-05-02 11:33:15 +02004856static const struct hda_amp_list ad1882_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02004857 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4858 { 0x20, HDA_INPUT, 1 }, /* Mic */
4859 { 0x20, HDA_INPUT, 4 }, /* Line */
4860 { 0x20, HDA_INPUT, 6 }, /* CD */
4861 { } /* end */
4862};
4863#endif
4864
Takashi Iwai0ac85512007-06-20 15:46:13 +02004865/* models */
4866enum {
4867 AD1882_3STACK,
4868 AD1882_6STACK,
4869 AD1882_MODELS
4870};
4871
Takashi Iwaiea734962011-01-17 11:29:34 +01004872static const char * const ad1882_models[AD1986A_MODELS] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02004873 [AD1882_3STACK] = "3stack",
4874 [AD1882_6STACK] = "6stack",
4875};
4876
4877
4878static int patch_ad1882(struct hda_codec *codec)
4879{
4880 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004881 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004882
4883 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4884 if (spec == NULL)
4885 return -ENOMEM;
4886
Takashi Iwai0ac85512007-06-20 15:46:13 +02004887 codec->spec = spec;
4888
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004889 err = snd_hda_attach_beep_device(codec, 0x10);
4890 if (err < 0) {
4891 ad198x_free(codec);
4892 return err;
4893 }
4894 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4895
Takashi Iwai0ac85512007-06-20 15:46:13 +02004896 spec->multiout.max_channels = 6;
4897 spec->multiout.num_dacs = 3;
4898 spec->multiout.dac_nids = ad1882_dac_nids;
4899 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4900 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4901 spec->adc_nids = ad1882_adc_nids;
4902 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004903 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004904 spec->input_mux = &ad1882_capture_source;
4905 else
4906 spec->input_mux = &ad1882a_capture_source;
4907 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004908 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004909 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004910 spec->mixers[1] = ad1882_loopback_mixers;
4911 else
4912 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004913 spec->num_init_verbs = 1;
4914 spec->init_verbs[0] = ad1882_init_verbs;
4915 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004916#ifdef CONFIG_SND_HDA_POWER_SAVE
4917 spec->loopback.amplist = ad1882_loopbacks;
4918#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004919 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004920
4921 codec->patch_ops = ad198x_patch_ops;
4922
4923 /* override some parameters */
4924 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4925 ad1882_models, NULL);
4926 switch (board_config) {
4927 default:
4928 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004929 spec->num_mixers = 3;
4930 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004931 spec->channel_mode = ad1882_modes;
4932 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4933 spec->need_dac_fix = 1;
4934 spec->multiout.max_channels = 2;
4935 spec->multiout.num_dacs = 1;
4936 break;
4937 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004938 spec->num_mixers = 3;
4939 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004940 break;
4941 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01004942
4943 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02004944 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01004945
Takashi Iwai0ac85512007-06-20 15:46:13 +02004946 return 0;
4947}
4948
4949
4950/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 * patch entries
4952 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02004953static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004954 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004955 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004956 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004957 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004958 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4959 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004960 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4961 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004962 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004964 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004965 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004966 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004967 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4968 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 {} /* terminator */
4970};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004971
4972MODULE_ALIAS("snd-hda-codec-id:11d4*");
4973
4974MODULE_LICENSE("GPL");
4975MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4976
4977static struct hda_codec_preset_list analog_list = {
4978 .preset = snd_hda_preset_analog,
4979 .owner = THIS_MODULE,
4980};
4981
4982static int __init patch_analog_init(void)
4983{
4984 return snd_hda_add_codec_preset(&analog_list);
4985}
4986
4987static void __exit patch_analog_exit(void)
4988{
4989 snd_hda_delete_codec_preset(&analog_list);
4990}
4991
4992module_init(patch_analog_init)
4993module_exit(patch_analog_exit)