blob: 34ee1169f2e05803d1e560fc5d354986db57687a [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 Iwaic8b6bf9b2005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
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() */
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
Raymond Yauc66ddf32011-01-17 11:19:03 +010049 hda_nid_t *alt_dac_nid;
50 struct hda_pcm_stream *stream_analog_alt_playback;
51
Takashi Iwai985be542005-11-02 18:26:49 +010052 /* capture */
53 unsigned int num_adc_nids;
54 hda_nid_t *adc_nids;
55 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 Iwai2e5b9562005-11-21 16:36:15 +010059 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 Iwai2134ea42008-01-10 16:53:55 +010087 const char **slave_vols;
88 const char **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 Iwai2134ea42008-01-10 16:53:55 +0100136static const char *ad_slave_vols[] = {
137 "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
149static const char *ad_slave_sws[] = {
150 "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
Raymond Yauc66ddf32011-01-17 11:19:03 +0100162static const char *ad1988_6stack_fp_slave_vols[] = {
163 "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
172static const char *ad1988_6stack_fp_slave_sws[] = {
173 "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 */
185static struct snd_kcontrol_new ad_beep_mixer[] = {
186 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
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +0100191static struct snd_kcontrol_new ad_beep2_mixer[] = {
192 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) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200216 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100217 if (err < 0)
218 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100219 err = snd_hda_create_spdif_share_sw(codec,
220 &spec->multiout);
221 if (err < 0)
222 return err;
223 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100224 }
225 if (spec->dig_in_nid) {
226 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
227 if (err < 0)
228 return err;
229 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100230
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100231 /* create beep controls if needed */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100232#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100233 if (spec->beep_amp) {
234 struct snd_kcontrol_new *knew;
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +0100235 knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
236 for ( ; knew->name; knew++) {
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100237 struct snd_kcontrol *kctl;
238 kctl = snd_ctl_new1(knew, codec);
239 if (!kctl)
240 return -ENOMEM;
241 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100242 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100243 if (err < 0)
244 return err;
245 }
246 }
Takashi Iwai67d634c2009-11-16 15:35:59 +0100247#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100248
Takashi Iwai2134ea42008-01-10 16:53:55 +0100249 /* if we have no master control, let's create it */
250 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100251 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100252 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100253 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100254 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100255 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100256 (spec->slave_vols ?
257 spec->slave_vols : ad_slave_vols));
258 if (err < 0)
259 return err;
260 }
261 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
262 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
263 NULL,
264 (spec->slave_sws ?
265 spec->slave_sws : ad_slave_sws));
266 if (err < 0)
267 return err;
268 }
269
Takashi Iwai603c4012008-07-30 15:01:44 +0200270 ad198x_free_kctls(codec); /* no longer needed */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100271
272 /* assign Capture Source enums to NID */
273 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
274 if (!kctl)
275 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
276 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +0100277 err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100278 if (err < 0)
279 return err;
280 }
281
282 /* assign IEC958 enums to NID */
283 kctl = snd_hda_find_mixer_ctl(codec,
284 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
285 if (kctl) {
286 err = snd_hda_add_nid(codec, kctl, 0,
287 spec->multiout.dig_out_nid);
288 if (err < 0)
289 return err;
290 }
291
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200292 return 0;
293}
294
Takashi Iwaicb53c622007-08-10 17:21:45 +0200295#ifdef CONFIG_SND_HDA_POWER_SAVE
296static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
297{
298 struct ad198x_spec *spec = codec->spec;
299 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
300}
301#endif
302
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200303/*
304 * Analog playback callbacks
305 */
306static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
307 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100308 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200309{
310 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100311 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
312 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200313}
314
315static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
316 struct hda_codec *codec,
317 unsigned int stream_tag,
318 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100319 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200320{
321 struct ad198x_spec *spec = codec->spec;
322 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
323 format, substream);
324}
325
326static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
327 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100328 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200329{
330 struct ad198x_spec *spec = codec->spec;
331 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
332}
333
Raymond Yauc66ddf32011-01-17 11:19:03 +0100334static int ad198x_alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
335 struct hda_codec *codec,
336 unsigned int stream_tag,
337 unsigned int format,
338 struct snd_pcm_substream *substream)
339{
340 struct ad198x_spec *spec = codec->spec;
341 snd_hda_codec_setup_stream(codec, spec->alt_dac_nid[0], stream_tag,
342 0, format);
343 return 0;
344}
345
346static int ad198x_alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
347 struct hda_codec *codec,
348 struct snd_pcm_substream *substream)
349{
350 struct ad198x_spec *spec = codec->spec;
351 snd_hda_codec_cleanup_stream(codec, spec->alt_dac_nid[0]);
352 return 0;
353}
354
355static struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
356 .substreams = 1,
357 .channels_min = 2,
358 .channels_max = 2,
359 /* NID is set in ad198x_build_pcms */
360 .ops = {
361 .prepare = ad198x_alt_playback_pcm_prepare,
362 .cleanup = ad198x_alt_playback_pcm_cleanup
363 },
364};
365
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200366/*
367 * Digital out
368 */
369static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
370 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100371 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200372{
373 struct ad198x_spec *spec = codec->spec;
374 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
375}
376
377static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
378 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100379 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200380{
381 struct ad198x_spec *spec = codec->spec;
382 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
383}
384
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200385static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
386 struct hda_codec *codec,
387 unsigned int stream_tag,
388 unsigned int format,
389 struct snd_pcm_substream *substream)
390{
391 struct ad198x_spec *spec = codec->spec;
392 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
393 format, substream);
394}
395
Takashi Iwai9411e212009-02-13 11:32:28 +0100396static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
397 struct hda_codec *codec,
398 struct snd_pcm_substream *substream)
399{
400 struct ad198x_spec *spec = codec->spec;
401 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
402}
403
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200404/*
405 * Analog capture
406 */
407static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
408 struct hda_codec *codec,
409 unsigned int stream_tag,
410 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100411 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200412{
413 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100414 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
415 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200416 return 0;
417}
418
419static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
420 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100421 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200422{
423 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100424 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200425 return 0;
426}
427
428
429/*
430 */
431static struct hda_pcm_stream ad198x_pcm_analog_playback = {
432 .substreams = 1,
433 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100434 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200435 .nid = 0, /* fill later */
436 .ops = {
437 .open = ad198x_playback_pcm_open,
438 .prepare = ad198x_playback_pcm_prepare,
439 .cleanup = ad198x_playback_pcm_cleanup
440 },
441};
442
443static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100444 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200445 .channels_min = 2,
446 .channels_max = 2,
447 .nid = 0, /* fill later */
448 .ops = {
449 .prepare = ad198x_capture_pcm_prepare,
450 .cleanup = ad198x_capture_pcm_cleanup
451 },
452};
453
454static struct hda_pcm_stream ad198x_pcm_digital_playback = {
455 .substreams = 1,
456 .channels_min = 2,
457 .channels_max = 2,
458 .nid = 0, /* fill later */
459 .ops = {
460 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200461 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100462 .prepare = ad198x_dig_playback_pcm_prepare,
463 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200464 },
465};
466
Takashi Iwai985be542005-11-02 18:26:49 +0100467static struct hda_pcm_stream ad198x_pcm_digital_capture = {
468 .substreams = 1,
469 .channels_min = 2,
470 .channels_max = 2,
471 /* NID is set in alc_build_pcms */
472};
473
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200474static int ad198x_build_pcms(struct hda_codec *codec)
475{
476 struct ad198x_spec *spec = codec->spec;
477 struct hda_pcm *info = spec->pcm_rec;
478
479 codec->num_pcms = 1;
480 codec->pcm_info = info;
481
482 info->name = "AD198x Analog";
483 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
484 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
485 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
486 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100487 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
488 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200489
490 if (spec->multiout.dig_out_nid) {
491 info++;
492 codec->num_pcms++;
493 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100494 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200495 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
496 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100497 if (spec->dig_in_nid) {
498 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
499 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
500 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200501 }
502
Raymond Yauc66ddf32011-01-17 11:19:03 +0100503 if (spec->alt_dac_nid && spec->stream_analog_alt_playback) {
504 codec->num_pcms++;
505 info = spec->pcm_rec + 2;
506 info->name = "AD198x Headphone";
507 info->pcm_type = HDA_PCM_TYPE_AUDIO;
508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
509 *spec->stream_analog_alt_playback;
510 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
511 spec->alt_dac_nid[0];
512 }
513
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200514 return 0;
515}
516
Daniel T Chenea52bf22009-12-27 18:48:29 -0500517static inline void ad198x_shutup(struct hda_codec *codec)
518{
519 snd_hda_shutup_pins(codec);
520}
521
Takashi Iwai603c4012008-07-30 15:01:44 +0200522static void ad198x_free_kctls(struct hda_codec *codec)
523{
524 struct ad198x_spec *spec = codec->spec;
525
526 if (spec->kctls.list) {
527 struct snd_kcontrol_new *kctl = spec->kctls.list;
528 int i;
529 for (i = 0; i < spec->kctls.used; i++)
530 kfree(kctl[i].name);
531 }
532 snd_array_free(&spec->kctls);
533}
534
Daniel T Chenea52bf22009-12-27 18:48:29 -0500535static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
536 hda_nid_t hp)
537{
538 struct ad198x_spec *spec = codec->spec;
539 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
540 !spec->inv_eapd ? 0x00 : 0x02);
541 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
542 !spec->inv_eapd ? 0x00 : 0x02);
543}
544
545static void ad198x_power_eapd(struct hda_codec *codec)
546{
547 /* We currently only handle front, HP */
548 switch (codec->vendor_id) {
549 case 0x11d41882:
550 case 0x11d4882a:
551 case 0x11d41884:
552 case 0x11d41984:
553 case 0x11d41883:
554 case 0x11d4184a:
555 case 0x11d4194a:
556 case 0x11d4194b:
557 ad198x_power_eapd_write(codec, 0x12, 0x11);
558 break;
559 case 0x11d41981:
560 case 0x11d41983:
561 ad198x_power_eapd_write(codec, 0x05, 0x06);
562 break;
563 case 0x11d41986:
564 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
565 break;
566 case 0x11d41988:
567 case 0x11d4198b:
568 case 0x11d4989a:
569 case 0x11d4989b:
570 ad198x_power_eapd_write(codec, 0x29, 0x22);
571 break;
572 }
573}
574
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200575static void ad198x_free(struct hda_codec *codec)
576{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100577 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100578
Takashi Iwai603c4012008-07-30 15:01:44 +0200579 if (!spec)
580 return;
581
Daniel T Chenea52bf22009-12-27 18:48:29 -0500582 ad198x_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +0200583 ad198x_free_kctls(codec);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100584 kfree(spec);
585 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200586}
587
Daniel T Chenea52bf22009-12-27 18:48:29 -0500588#ifdef SND_HDA_NEEDS_RESUME
589static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
590{
591 ad198x_shutup(codec);
592 ad198x_power_eapd(codec);
593 return 0;
594}
Daniel T Chenea52bf22009-12-27 18:48:29 -0500595#endif
596
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200597static struct hda_codec_ops ad198x_patch_ops = {
598 .build_controls = ad198x_build_controls,
599 .build_pcms = ad198x_build_pcms,
600 .init = ad198x_init,
601 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200602#ifdef CONFIG_SND_HDA_POWER_SAVE
603 .check_power_status = ad198x_check_power_status,
604#endif
Daniel T Chenea52bf22009-12-27 18:48:29 -0500605#ifdef SND_HDA_NEEDS_RESUME
606 .suspend = ad198x_suspend,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500607#endif
608 .reboot_notify = ad198x_shutup,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200609};
610
611
612/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100613 * EAPD control
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100614 * the private value = nid
Takashi Iwai18a815d2006-03-01 19:54:39 +0100615 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200616#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100617
618static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_value *ucontrol)
620{
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct ad198x_spec *spec = codec->spec;
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100623 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100624 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
625 else
626 ucontrol->value.integer.value[0] = spec->cur_eapd;
627 return 0;
628}
629
630static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_value *ucontrol)
632{
633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct ad198x_spec *spec = codec->spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100635 hda_nid_t nid = kcontrol->private_value & 0xff;
636 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100637 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100638 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100639 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200640 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100641 return 0;
642 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200643 snd_hda_codec_write_cache(codec, nid,
644 0, AC_VERB_SET_EAPD_BTLENABLE,
645 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100646 return 1;
647}
648
Takashi Iwai9230d212006-03-13 13:49:49 +0100649static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_info *uinfo);
651static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol);
653static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol);
655
656
Takashi Iwai18a815d2006-03-01 19:54:39 +0100657/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200658 * AD1986A specific
659 */
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define AD1986A_SPDIF_OUT 0x02
662#define AD1986A_FRONT_DAC 0x03
663#define AD1986A_SURR_DAC 0x04
664#define AD1986A_CLFE_DAC 0x05
665#define AD1986A_ADC 0x06
666
667static hda_nid_t ad1986a_dac_nids[3] = {
668 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
669};
Takashi Iwai985be542005-11-02 18:26:49 +0100670static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100671static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673static struct hda_input_mux ad1986a_capture_source = {
674 .num_items = 7,
675 .items = {
676 { "Mic", 0x0 },
677 { "CD", 0x1 },
678 { "Aux", 0x3 },
679 { "Line", 0x4 },
680 { "Mix", 0x5 },
681 { "Mono", 0x6 },
682 { "Phone", 0x7 },
683 },
684};
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Takashi Iwai532d5382007-07-27 19:02:40 +0200687static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
688 .ops = &snd_hda_bind_vol,
689 .values = {
690 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
691 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
692 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
693 0
694 },
695};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Takashi Iwai532d5382007-07-27 19:02:40 +0200697static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
698 .ops = &snd_hda_bind_sw,
699 .values = {
700 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
701 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
702 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
703 0
704 },
705};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 * mixers
709 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100710static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200711 /*
712 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
713 */
714 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
715 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
717 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
718 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
719 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
720 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
721 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
722 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
723 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
724 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
725 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
726 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
727 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
728 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
729 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
730 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
731 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
732 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
733 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100734 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
736 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
737 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
738 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
739 {
740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
741 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200742 .info = ad198x_mux_enum_info,
743 .get = ad198x_mux_enum_get,
744 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 },
746 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
747 { } /* end */
748};
749
Takashi Iwai9230d212006-03-13 13:49:49 +0100750/* additional mixers for 3stack mode */
751static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
752 {
753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
754 .name = "Channel Mode",
755 .info = ad198x_ch_mode_info,
756 .get = ad198x_ch_mode_get,
757 .put = ad198x_ch_mode_put,
758 },
759 { } /* end */
760};
761
762/* laptop model - 2ch only */
763static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
764
Takashi Iwai20a45e82007-08-15 22:20:45 +0200765/* master controls both pins 0x1a and 0x1b */
766static struct hda_bind_ctls ad1986a_laptop_master_vol = {
767 .ops = &snd_hda_bind_vol,
768 .values = {
769 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
770 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
771 0,
772 },
773};
774
775static struct hda_bind_ctls ad1986a_laptop_master_sw = {
776 .ops = &snd_hda_bind_sw,
777 .values = {
778 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
779 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
780 0,
781 },
782};
783
Takashi Iwai9230d212006-03-13 13:49:49 +0100784static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
785 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
786 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200787 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
788 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100789 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
790 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
791 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
792 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
793 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
794 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
795 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
796 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100797 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100798 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100799 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
800 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
801 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
802 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
803 {
804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805 .name = "Capture Source",
806 .info = ad198x_mux_enum_info,
807 .get = ad198x_mux_enum_get,
808 .put = ad198x_mux_enum_put,
809 },
810 { } /* end */
811};
812
Takashi Iwai825aa972006-03-17 10:50:49 +0100813/* laptop-eapd model - 2ch only */
814
Takashi Iwai825aa972006-03-17 10:50:49 +0100815static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
816 .num_items = 3,
817 .items = {
818 { "Mic", 0x0 },
819 { "Internal Mic", 0x4 },
820 { "Mix", 0x5 },
821 },
822};
823
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100824static struct hda_input_mux ad1986a_automic_capture_source = {
825 .num_items = 2,
826 .items = {
827 { "Mic", 0x0 },
828 { "Mix", 0x5 },
829 },
830};
831
Takashi Iwai16d11a82009-06-24 14:07:53 +0200832static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200833 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
834 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200835 { } /* end */
836};
837
838static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100839 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
840 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100841 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
842 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100843 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100844 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
845 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
846 {
847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
848 .name = "Capture Source",
849 .info = ad198x_mux_enum_info,
850 .get = ad198x_mux_enum_get,
851 .put = ad198x_mux_enum_put,
852 },
853 {
854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
855 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100856 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwai1725b822008-11-21 02:25:48 +0100857 .info = ad198x_eapd_info,
858 .get = ad198x_eapd_get,
859 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100860 .private_value = 0x1b, /* port-D */
Takashi Iwai1725b822008-11-21 02:25:48 +0100861 },
862 { } /* end */
863};
864
Takashi Iwai16d11a82009-06-24 14:07:53 +0200865static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
866 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
867 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100868 { } /* end */
869};
870
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100871/* re-connect the mic boost input according to the jack sensing */
872static void ad1986a_automic(struct hda_codec *codec)
873{
874 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100875 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100876 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
877 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100878 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100879}
880
881#define AD1986A_MIC_EVENT 0x36
882
883static void ad1986a_automic_unsol_event(struct hda_codec *codec,
884 unsigned int res)
885{
886 if ((res >> 26) != AD1986A_MIC_EVENT)
887 return;
888 ad1986a_automic(codec);
889}
890
891static int ad1986a_automic_init(struct hda_codec *codec)
892{
893 ad198x_init(codec);
894 ad1986a_automic(codec);
895 return 0;
896}
897
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200898/* laptop-automute - 2ch only */
899
900static void ad1986a_update_hp(struct hda_codec *codec)
901{
902 struct ad198x_spec *spec = codec->spec;
903 unsigned int mute;
904
905 if (spec->jack_present)
906 mute = HDA_AMP_MUTE; /* mute internal speaker */
907 else
908 /* unmute internal speaker if necessary */
909 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
910 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
911 HDA_AMP_MUTE, mute);
912}
913
914static void ad1986a_hp_automute(struct hda_codec *codec)
915{
916 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200917
Takashi Iwaid56757a2009-11-18 08:00:14 +0100918 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200919 if (spec->inv_jack_detect)
920 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200921 ad1986a_update_hp(codec);
922}
923
924#define AD1986A_HP_EVENT 0x37
925
926static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
927{
928 if ((res >> 26) != AD1986A_HP_EVENT)
929 return;
930 ad1986a_hp_automute(codec);
931}
932
933static int ad1986a_hp_init(struct hda_codec *codec)
934{
935 ad198x_init(codec);
936 ad1986a_hp_automute(codec);
937 return 0;
938}
939
940/* bind hp and internal speaker mute (with plug check) */
941static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
942 struct snd_ctl_elem_value *ucontrol)
943{
944 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
945 long *valp = ucontrol->value.integer.value;
946 int change;
947
948 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
949 HDA_AMP_MUTE,
950 valp[0] ? 0 : HDA_AMP_MUTE);
951 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
952 HDA_AMP_MUTE,
953 valp[1] ? 0 : HDA_AMP_MUTE);
954 if (change)
955 ad1986a_update_hp(codec);
956 return change;
957}
958
Takashi Iwai16d11a82009-06-24 14:07:53 +0200959static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200960 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
961 {
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
963 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100964 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200965 .info = snd_hda_mixer_amp_switch_info,
966 .get = snd_hda_mixer_amp_switch_get,
967 .put = ad1986a_hp_master_sw_put,
968 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
969 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200970 { } /* end */
971};
972
Takashi Iwai16d11a82009-06-24 14:07:53 +0200973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974/*
975 * initialization verbs
976 */
977static struct hda_verb ad1986a_init_verbs[] = {
978 /* Front, Surround, CLFE DAC; mute as default */
979 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
980 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
981 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
982 /* Downmix - off */
983 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
984 /* HP, Line-Out, Surround, CLFE selectors */
985 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
986 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
987 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
988 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
989 /* Mono selector */
990 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
991 /* Mic selector: Mic 1/2 pin */
992 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
993 /* Line-in selector: Line-in */
994 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
995 /* Mic 1/2 swap */
996 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
997 /* Record selector: mic */
998 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
999 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
1000 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1001 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1002 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1003 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1004 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1005 /* PC beep */
1006 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
1007 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
1008 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1009 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1010 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1011 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1012 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001013 /* HP Pin */
1014 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1015 /* Front, Surround, CLFE Pins */
1016 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1017 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1018 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1019 /* Mono Pin */
1020 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1021 /* Mic Pin */
1022 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1023 /* Line, Aux, CD, Beep-In Pin */
1024 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1025 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1026 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1027 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1028 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 { } /* end */
1030};
1031
Takashi Iwai9230d212006-03-13 13:49:49 +01001032static struct hda_verb ad1986a_ch2_init[] = {
1033 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001034 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1035 /* Line-in selectors */
1036 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001037 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001038 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1039 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
1040 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001041 { } /* end */
1042};
1043
1044static struct hda_verb ad1986a_ch4_init[] = {
1045 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001046 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1047 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001048 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001049 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1050 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001051 { } /* end */
1052};
1053
1054static struct hda_verb ad1986a_ch6_init[] = {
1055 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001056 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1057 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001058 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001059 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1060 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001061 { } /* end */
1062};
1063
1064static struct hda_channel_mode ad1986a_modes[3] = {
1065 { 2, ad1986a_ch2_init },
1066 { 4, ad1986a_ch4_init },
1067 { 6, ad1986a_ch6_init },
1068};
1069
Takashi Iwai825aa972006-03-17 10:50:49 +01001070/* eapd initialization */
1071static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +01001072 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +01001073 {}
1074};
1075
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001076static struct hda_verb ad1986a_automic_verbs[] = {
1077 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1078 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1079 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
1080 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
1081 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
1082 {}
1083};
1084
Tobin Davisf36090f2007-01-08 11:07:12 +01001085/* Ultra initialization */
1086static struct hda_verb ad1986a_ultra_init[] = {
1087 /* eapd initialization */
1088 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
1089 /* CLFE -> Mic in */
1090 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
1091 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1092 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
1093 { } /* end */
1094};
1095
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001096/* pin sensing on HP jack */
1097static struct hda_verb ad1986a_hp_init_verbs[] = {
1098 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
1099 {}
1100};
1101
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001102static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
1103 unsigned int res)
1104{
1105 switch (res >> 26) {
1106 case AD1986A_HP_EVENT:
1107 ad1986a_hp_automute(codec);
1108 break;
1109 case AD1986A_MIC_EVENT:
1110 ad1986a_automic(codec);
1111 break;
1112 }
1113}
1114
1115static int ad1986a_samsung_p50_init(struct hda_codec *codec)
1116{
1117 ad198x_init(codec);
1118 ad1986a_hp_automute(codec);
1119 ad1986a_automic(codec);
1120 return 0;
1121}
1122
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001123
Takashi Iwai9230d212006-03-13 13:49:49 +01001124/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001125enum {
1126 AD1986A_6STACK,
1127 AD1986A_3STACK,
1128 AD1986A_LAPTOP,
1129 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001130 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +01001131 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +01001132 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001133 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001134 AD1986A_MODELS
1135};
Takashi Iwai9230d212006-03-13 13:49:49 +01001136
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001137static const char *ad1986a_models[AD1986A_MODELS] = {
1138 [AD1986A_6STACK] = "6stack",
1139 [AD1986A_3STACK] = "3stack",
1140 [AD1986A_LAPTOP] = "laptop",
1141 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001142 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +01001143 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +01001144 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001145 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001146};
1147
1148static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1149 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001150 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001151 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001152 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001153 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1154 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1155 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1156 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001157 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001158 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001159 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1160 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1161 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1162 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1163 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001164 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Daniel T Chenba579eb2010-02-20 11:16:30 -05001165 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001166 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001167 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001168 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001169 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001170 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001171 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001172 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001173 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001174 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001175 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001176 {}
1177};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Takashi Iwaicb53c622007-08-10 17:21:45 +02001179#ifdef CONFIG_SND_HDA_POWER_SAVE
1180static struct hda_amp_list ad1986a_loopbacks[] = {
1181 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1182 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1183 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1184 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1185 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1186 { } /* end */
1187};
1188#endif
1189
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001190static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1191{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001192 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001193 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1194}
1195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196static int patch_ad1986a(struct hda_codec *codec)
1197{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001198 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001199 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001201 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 if (spec == NULL)
1203 return -ENOMEM;
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 codec->spec = spec;
1206
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001207 err = snd_hda_attach_beep_device(codec, 0x19);
1208 if (err < 0) {
1209 ad198x_free(codec);
1210 return err;
1211 }
1212 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 spec->multiout.max_channels = 6;
1215 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1216 spec->multiout.dac_nids = ad1986a_dac_nids;
1217 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001218 spec->num_adc_nids = 1;
1219 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001220 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001221 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001222 spec->num_mixers = 1;
1223 spec->mixers[0] = ad1986a_mixers;
1224 spec->num_init_verbs = 1;
1225 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001226#ifdef CONFIG_SND_HDA_POWER_SAVE
1227 spec->loopback.amplist = ad1986a_loopbacks;
1228#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001229 spec->vmaster_nid = 0x1b;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01001230 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001232 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Takashi Iwai9230d212006-03-13 13:49:49 +01001234 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001235 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1236 ad1986a_models,
1237 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001238 switch (board_config) {
1239 case AD1986A_3STACK:
1240 spec->num_mixers = 2;
1241 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001242 spec->num_init_verbs = 2;
1243 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001244 spec->channel_mode = ad1986a_modes;
1245 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001246 spec->need_dac_fix = 1;
1247 spec->multiout.max_channels = 2;
1248 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001249 break;
1250 case AD1986A_LAPTOP:
1251 spec->mixers[0] = ad1986a_laptop_mixers;
1252 spec->multiout.max_channels = 2;
1253 spec->multiout.num_dacs = 1;
1254 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1255 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001256 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001257 spec->num_mixers = 3;
1258 spec->mixers[0] = ad1986a_laptop_master_mixers;
1259 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1260 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001261 spec->num_init_verbs = 2;
1262 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1263 spec->multiout.max_channels = 2;
1264 spec->multiout.num_dacs = 1;
1265 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1266 if (!is_jack_available(codec, 0x25))
1267 spec->multiout.dig_out_nid = 0;
1268 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1269 break;
1270 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001271 spec->num_mixers = 2;
1272 spec->mixers[0] = ad1986a_laptop_master_mixers;
1273 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001274 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001275 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001276 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001277 spec->multiout.max_channels = 2;
1278 spec->multiout.num_dacs = 1;
1279 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001280 if (!is_jack_available(codec, 0x25))
1281 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001282 spec->input_mux = &ad1986a_automic_capture_source;
1283 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1284 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001285 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001286 case AD1986A_SAMSUNG_P50:
1287 spec->num_mixers = 2;
1288 spec->mixers[0] = ad1986a_automute_master_mixers;
1289 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1290 spec->num_init_verbs = 4;
1291 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1292 spec->init_verbs[2] = ad1986a_automic_verbs;
1293 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1294 spec->multiout.max_channels = 2;
1295 spec->multiout.num_dacs = 1;
1296 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1297 if (!is_jack_available(codec, 0x25))
1298 spec->multiout.dig_out_nid = 0;
1299 spec->input_mux = &ad1986a_automic_capture_source;
1300 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1301 codec->patch_ops.init = ad1986a_samsung_p50_init;
1302 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001303 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001304 spec->num_mixers = 3;
1305 spec->mixers[0] = ad1986a_automute_master_mixers;
1306 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1307 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001308 spec->num_init_verbs = 3;
1309 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1310 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1311 spec->multiout.max_channels = 2;
1312 spec->multiout.num_dacs = 1;
1313 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001314 if (!is_jack_available(codec, 0x25))
1315 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001316 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1317 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1318 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001319 /* Lenovo N100 seems to report the reversed bit
1320 * for HP jack-sensing
1321 */
1322 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001323 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001324 case AD1986A_ULTRA:
1325 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1326 spec->num_init_verbs = 2;
1327 spec->init_verbs[1] = ad1986a_ultra_init;
1328 spec->multiout.max_channels = 2;
1329 spec->multiout.num_dacs = 1;
1330 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1331 spec->multiout.dig_out_nid = 0;
1332 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001333 }
1334
Takashi Iwaid29240c2007-10-26 12:35:56 +02001335 /* AD1986A has a hardware problem that it can't share a stream
1336 * with multiple output pins. The copy of front to surrounds
1337 * causes noisy or silent outputs at a certain timing, e.g.
1338 * changing the volume.
1339 * So, let's disable the shared stream.
1340 */
1341 spec->multiout.no_share_stream = 1;
1342
Takashi Iwai729d55b2009-12-25 22:49:01 +01001343 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001344 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 return 0;
1347}
1348
1349/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001350 * AD1983 specific
1351 */
1352
1353#define AD1983_SPDIF_OUT 0x02
1354#define AD1983_DAC 0x03
1355#define AD1983_ADC 0x04
1356
1357static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001358static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001359static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001360
1361static struct hda_input_mux ad1983_capture_source = {
1362 .num_items = 4,
1363 .items = {
1364 { "Mic", 0x0 },
1365 { "Line", 0x1 },
1366 { "Mix", 0x2 },
1367 { "Mix Mono", 0x3 },
1368 },
1369};
1370
1371/*
1372 * SPDIF playback route
1373 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001374static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001375{
1376 static char *texts[] = { "PCM", "ADC" };
1377
1378 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1379 uinfo->count = 1;
1380 uinfo->value.enumerated.items = 2;
1381 if (uinfo->value.enumerated.item > 1)
1382 uinfo->value.enumerated.item = 1;
1383 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1384 return 0;
1385}
1386
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001387static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001388{
1389 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1390 struct ad198x_spec *spec = codec->spec;
1391
1392 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1393 return 0;
1394}
1395
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001396static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001397{
1398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1399 struct ad198x_spec *spec = codec->spec;
1400
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001401 if (ucontrol->value.enumerated.item[0] > 1)
1402 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001403 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1404 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001405 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1406 AC_VERB_SET_CONNECT_SEL,
1407 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001408 return 1;
1409 }
1410 return 0;
1411}
1412
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001413static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001414 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001426 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001427 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1429 {
1430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431 .name = "Capture Source",
1432 .info = ad198x_mux_enum_info,
1433 .get = ad198x_mux_enum_get,
1434 .put = ad198x_mux_enum_put,
1435 },
1436 {
1437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001438 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001439 .info = ad1983_spdif_route_info,
1440 .get = ad1983_spdif_route_get,
1441 .put = ad1983_spdif_route_put,
1442 },
1443 { } /* end */
1444};
1445
1446static struct hda_verb ad1983_init_verbs[] = {
1447 /* Front, HP, Mono; mute as default */
1448 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1449 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1450 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1451 /* Beep, PCM, Mic, Line-In: mute */
1452 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1453 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1455 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 /* Front, HP selectors; from Mix */
1457 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1458 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1459 /* Mono selector; from Mix */
1460 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1461 /* Mic selector; Mic */
1462 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1463 /* Line-in selector: Line-in */
1464 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1465 /* Mic boost: 0dB */
1466 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1467 /* Record selector: mic */
1468 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1469 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1470 /* SPDIF route: PCM */
1471 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1472 /* Front Pin */
1473 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1474 /* HP Pin */
1475 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1476 /* Mono Pin */
1477 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1478 /* Mic Pin */
1479 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1480 /* Line Pin */
1481 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1482 { } /* end */
1483};
1484
Takashi Iwaicb53c622007-08-10 17:21:45 +02001485#ifdef CONFIG_SND_HDA_POWER_SAVE
1486static struct hda_amp_list ad1983_loopbacks[] = {
1487 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1488 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1489 { } /* end */
1490};
1491#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001492
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001493static int patch_ad1983(struct hda_codec *codec)
1494{
1495 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001496 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001497
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001498 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001499 if (spec == NULL)
1500 return -ENOMEM;
1501
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001502 codec->spec = spec;
1503
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001504 err = snd_hda_attach_beep_device(codec, 0x10);
1505 if (err < 0) {
1506 ad198x_free(codec);
1507 return err;
1508 }
1509 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1510
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001511 spec->multiout.max_channels = 2;
1512 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1513 spec->multiout.dac_nids = ad1983_dac_nids;
1514 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001515 spec->num_adc_nids = 1;
1516 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001517 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001518 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001519 spec->num_mixers = 1;
1520 spec->mixers[0] = ad1983_mixers;
1521 spec->num_init_verbs = 1;
1522 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001523 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001524#ifdef CONFIG_SND_HDA_POWER_SAVE
1525 spec->loopback.amplist = ad1983_loopbacks;
1526#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001527 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001528
1529 codec->patch_ops = ad198x_patch_ops;
1530
Takashi Iwai729d55b2009-12-25 22:49:01 +01001531 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001532 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001533
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001534 return 0;
1535}
1536
1537
1538/*
1539 * AD1981 HD specific
1540 */
1541
1542#define AD1981_SPDIF_OUT 0x02
1543#define AD1981_DAC 0x03
1544#define AD1981_ADC 0x04
1545
1546static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001547static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001548static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001549
1550/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1551static struct hda_input_mux ad1981_capture_source = {
1552 .num_items = 7,
1553 .items = {
1554 { "Front Mic", 0x0 },
1555 { "Line", 0x1 },
1556 { "Mix", 0x2 },
1557 { "Mix Mono", 0x3 },
1558 { "CD", 0x4 },
1559 { "Mic", 0x6 },
1560 { "Aux", 0x7 },
1561 },
1562};
1563
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001564static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001565 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1566 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1567 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1568 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1569 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1574 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1575 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1576 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1577 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1578 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1579 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1580 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1581 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1582 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001583 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1584 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001585 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1586 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1587 {
1588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1589 .name = "Capture Source",
1590 .info = ad198x_mux_enum_info,
1591 .get = ad198x_mux_enum_get,
1592 .put = ad198x_mux_enum_put,
1593 },
1594 /* identical with AD1983 */
1595 {
1596 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001597 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001598 .info = ad1983_spdif_route_info,
1599 .get = ad1983_spdif_route_get,
1600 .put = ad1983_spdif_route_put,
1601 },
1602 { } /* end */
1603};
1604
1605static struct hda_verb ad1981_init_verbs[] = {
1606 /* Front, HP, Mono; mute as default */
1607 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1608 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1609 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1610 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1611 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1612 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1613 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1614 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1615 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1616 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1617 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1618 /* Front, HP selectors; from Mix */
1619 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1620 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1621 /* Mono selector; from Mix */
1622 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1623 /* Mic Mixer; select Front Mic */
1624 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1625 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1626 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001627 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1628 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001629 /* Record selector: Front mic */
1630 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1631 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1632 /* SPDIF route: PCM */
1633 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1634 /* Front Pin */
1635 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1636 /* HP Pin */
1637 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1638 /* Mono Pin */
1639 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1640 /* Front & Rear Mic Pins */
1641 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1642 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1643 /* Line Pin */
1644 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1645 /* Digital Beep */
1646 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1647 /* Line-Out as Input: disabled */
1648 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1649 { } /* end */
1650};
1651
Takashi Iwaicb53c622007-08-10 17:21:45 +02001652#ifdef CONFIG_SND_HDA_POWER_SAVE
1653static struct hda_amp_list ad1981_loopbacks[] = {
1654 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1655 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1656 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1657 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1658 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1659 { } /* end */
1660};
1661#endif
1662
Takashi Iwai18a815d2006-03-01 19:54:39 +01001663/*
1664 * Patch for HP nx6320
1665 *
Tobin Davis18768992007-03-12 22:20:51 +01001666 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001667 * speaker output enabled _and_ mute-LED off.
1668 */
1669
1670#define AD1981_HP_EVENT 0x37
1671#define AD1981_MIC_EVENT 0x38
1672
1673static struct hda_verb ad1981_hp_init_verbs[] = {
1674 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1675 /* pin sensing on HP and Mic jacks */
1676 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1677 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1678 {}
1679};
1680
1681/* turn on/off EAPD (+ mute HP) as a master switch */
1682static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1683 struct snd_ctl_elem_value *ucontrol)
1684{
1685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1686 struct ad198x_spec *spec = codec->spec;
1687
1688 if (! ad198x_eapd_put(kcontrol, ucontrol))
1689 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001690 /* change speaker pin appropriately */
1691 snd_hda_codec_write(codec, 0x05, 0,
1692 AC_VERB_SET_PIN_WIDGET_CONTROL,
1693 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001694 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001695 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1696 HDA_AMP_MUTE,
1697 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001698 return 1;
1699}
1700
1701/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001702static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1703 .ops = &snd_hda_bind_vol,
1704 .values = {
1705 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1706 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1707 0
1708 },
1709};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001710
1711/* mute internal speaker if HP is plugged */
1712static void ad1981_hp_automute(struct hda_codec *codec)
1713{
1714 unsigned int present;
1715
Takashi Iwaid56757a2009-11-18 08:00:14 +01001716 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001717 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1718 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001719}
1720
1721/* toggle input of built-in and mic jack appropriately */
1722static void ad1981_hp_automic(struct hda_codec *codec)
1723{
1724 static struct hda_verb mic_jack_on[] = {
1725 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1726 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1727 {}
1728 };
1729 static struct hda_verb mic_jack_off[] = {
1730 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1731 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1732 {}
1733 };
1734 unsigned int present;
1735
Takashi Iwaid56757a2009-11-18 08:00:14 +01001736 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001737 if (present)
1738 snd_hda_sequence_write(codec, mic_jack_on);
1739 else
1740 snd_hda_sequence_write(codec, mic_jack_off);
1741}
1742
1743/* unsolicited event for HP jack sensing */
1744static void ad1981_hp_unsol_event(struct hda_codec *codec,
1745 unsigned int res)
1746{
1747 res >>= 26;
1748 switch (res) {
1749 case AD1981_HP_EVENT:
1750 ad1981_hp_automute(codec);
1751 break;
1752 case AD1981_MIC_EVENT:
1753 ad1981_hp_automic(codec);
1754 break;
1755 }
1756}
1757
1758static struct hda_input_mux ad1981_hp_capture_source = {
1759 .num_items = 3,
1760 .items = {
1761 { "Mic", 0x0 },
1762 { "Docking-Station", 0x1 },
1763 { "Mix", 0x2 },
1764 },
1765};
1766
1767static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001768 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001769 {
1770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001771 .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
Takashi Iwai18a815d2006-03-01 19:54:39 +01001772 .name = "Master Playback Switch",
1773 .info = ad198x_eapd_info,
1774 .get = ad198x_eapd_get,
1775 .put = ad1981_hp_master_sw_put,
1776 .private_value = 0x05,
1777 },
1778 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1779 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1780#if 0
1781 /* FIXME: analog mic/line loopback doesn't work with my tests...
1782 * (although recording is OK)
1783 */
1784 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1785 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1786 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1787 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1788 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1789 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1790 /* FIXME: does this laptop have analog CD connection? */
1791 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1792 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1793#endif
David Henningsson5f99f862011-01-04 15:24:24 +01001794 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
1795 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001796 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1797 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1798 {
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1800 .name = "Capture Source",
1801 .info = ad198x_mux_enum_info,
1802 .get = ad198x_mux_enum_get,
1803 .put = ad198x_mux_enum_put,
1804 },
1805 { } /* end */
1806};
1807
1808/* initialize jack-sensing, too */
1809static int ad1981_hp_init(struct hda_codec *codec)
1810{
1811 ad198x_init(codec);
1812 ad1981_hp_automute(codec);
1813 ad1981_hp_automic(codec);
1814 return 0;
1815}
1816
Tobin Davis18768992007-03-12 22:20:51 +01001817/* configuration for Toshiba Laptops */
1818static struct hda_verb ad1981_toshiba_init_verbs[] = {
1819 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1820 /* pin sensing on HP and Mic jacks */
1821 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1822 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1823 {}
1824};
1825
1826static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1827 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1828 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1829 { }
1830};
1831
Takashi Iwai01686c52006-04-18 12:54:11 +02001832/* configuration for Lenovo Thinkpad T60 */
1833static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1834 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1835 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1836 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1837 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1838 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1839 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1840 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1841 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01001842 HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
Takashi Iwai01686c52006-04-18 12:54:11 +02001843 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1844 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1845 {
1846 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1847 .name = "Capture Source",
1848 .info = ad198x_mux_enum_info,
1849 .get = ad198x_mux_enum_get,
1850 .put = ad198x_mux_enum_put,
1851 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001852 /* identical with AD1983 */
1853 {
1854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1855 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1856 .info = ad1983_spdif_route_info,
1857 .get = ad1983_spdif_route_get,
1858 .put = ad1983_spdif_route_put,
1859 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001860 { } /* end */
1861};
1862
1863static struct hda_input_mux ad1981_thinkpad_capture_source = {
1864 .num_items = 3,
1865 .items = {
1866 { "Mic", 0x0 },
1867 { "Mix", 0x2 },
1868 { "CD", 0x4 },
1869 },
1870};
1871
Takashi Iwai18a815d2006-03-01 19:54:39 +01001872/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001873enum {
1874 AD1981_BASIC,
1875 AD1981_HP,
1876 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001877 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001878 AD1981_MODELS
1879};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001880
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001881static const char *ad1981_models[AD1981_MODELS] = {
1882 [AD1981_HP] = "hp",
1883 [AD1981_THINKPAD] = "thinkpad",
1884 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001885 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001886};
1887
1888static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001889 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001890 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001891 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001892 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001893 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c52006-04-18 12:54:11 +02001894 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001895 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001896 /* HP nx6320 (reversed SSID, H/W bug) */
1897 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001898 {}
1899};
1900
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001901static int patch_ad1981(struct hda_codec *codec)
1902{
1903 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001904 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001905
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001906 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001907 if (spec == NULL)
1908 return -ENOMEM;
1909
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001910 codec->spec = spec;
1911
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001912 err = snd_hda_attach_beep_device(codec, 0x10);
1913 if (err < 0) {
1914 ad198x_free(codec);
1915 return err;
1916 }
1917 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1918
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001919 spec->multiout.max_channels = 2;
1920 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1921 spec->multiout.dac_nids = ad1981_dac_nids;
1922 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001923 spec->num_adc_nids = 1;
1924 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001925 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001926 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001927 spec->num_mixers = 1;
1928 spec->mixers[0] = ad1981_mixers;
1929 spec->num_init_verbs = 1;
1930 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001931 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001932#ifdef CONFIG_SND_HDA_POWER_SAVE
1933 spec->loopback.amplist = ad1981_loopbacks;
1934#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001935 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001936
1937 codec->patch_ops = ad198x_patch_ops;
1938
Takashi Iwai18a815d2006-03-01 19:54:39 +01001939 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001940 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1941 ad1981_models,
1942 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001943 switch (board_config) {
1944 case AD1981_HP:
1945 spec->mixers[0] = ad1981_hp_mixers;
1946 spec->num_init_verbs = 2;
1947 spec->init_verbs[1] = ad1981_hp_init_verbs;
1948 spec->multiout.dig_out_nid = 0;
1949 spec->input_mux = &ad1981_hp_capture_source;
1950
1951 codec->patch_ops.init = ad1981_hp_init;
1952 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
Daniel T Chen01f59662009-12-13 16:22:58 -05001953 /* set the upper-limit for mixer amp to 0dB for avoiding the
1954 * possible damage by overloading
1955 */
1956 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1957 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1958 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1959 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1960 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai18a815d2006-03-01 19:54:39 +01001961 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001962 case AD1981_THINKPAD:
1963 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001964 spec->input_mux = &ad1981_thinkpad_capture_source;
Daniel T Chenb8e80cf2010-03-30 13:29:28 -04001965 /* set the upper-limit for mixer amp to 0dB for avoiding the
1966 * possible damage by overloading
1967 */
1968 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1969 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1970 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1971 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1972 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai01686c52006-04-18 12:54:11 +02001973 break;
Tobin Davis18768992007-03-12 22:20:51 +01001974 case AD1981_TOSHIBA:
1975 spec->mixers[0] = ad1981_hp_mixers;
1976 spec->mixers[1] = ad1981_toshiba_mixers;
1977 spec->num_init_verbs = 2;
1978 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1979 spec->multiout.dig_out_nid = 0;
1980 spec->input_mux = &ad1981_hp_capture_source;
1981 codec->patch_ops.init = ad1981_hp_init;
1982 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1983 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001984 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01001985
1986 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001987 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001988
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001989 return 0;
1990}
1991
1992
1993/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001994 * AD1988
1995 *
1996 * Output pins and routes
1997 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001998 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001999 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
2000 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
2001 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
2002 * port-D 0x12 (mute/hp) <- 0x29 <- 04
2003 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
2004 * port-F 0x16 (mute) <- 0x2a <- 06
2005 * port-G 0x24 (mute) <- 0x27 <- 05
2006 * port-H 0x25 (mute) <- 0x28 <- 0a
2007 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
2008 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01002009 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
2010 * (*) 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 +01002011 *
2012 * Input pins and routes
2013 *
2014 * pin boost mix input # / adc input #
2015 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
2016 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
2017 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
2018 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
2019 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
2020 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
2021 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
2022 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
2023 *
2024 *
2025 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01002026 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002027 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002028 *
2029 * Inputs of Analog Mix (0x20)
2030 * 0:Port-B (front mic)
2031 * 1:Port-C/G/H (line-in)
2032 * 2:Port-A
2033 * 3:Port-D (line-in/2)
2034 * 4:Port-E/G/H (mic-in)
2035 * 5:Port-F (mic2-in)
2036 * 6:CD
2037 * 7:Beep
2038 *
2039 * ADC selection
2040 * 0:Port-A
2041 * 1:Port-B (front mic-in)
2042 * 2:Port-C (line-in)
2043 * 3:Port-F (mic2-in)
2044 * 4:Port-E (mic-in)
2045 * 5:CD
2046 * 6:Port-G
2047 * 7:Port-H
2048 * 8:Port-D (line-in/2)
2049 * 9:Mix
2050 *
2051 * Proposed pin assignments by the datasheet
2052 *
2053 * 6-stack
2054 * Port-A front headphone
2055 * B front mic-in
2056 * C rear line-in
2057 * D rear front-out
2058 * E rear mic-in
2059 * F rear surround
2060 * G rear CLFE
2061 * H rear side
2062 *
2063 * 3-stack
2064 * Port-A front headphone
2065 * B front mic
2066 * C rear line-in/surround
2067 * D rear front-out
2068 * E rear mic-in/CLFE
2069 *
2070 * laptop
2071 * Port-A headphone
2072 * B mic-in
2073 * C docking station
2074 * D internal speaker (with EAPD)
2075 * E/F quad mic array
2076 */
2077
2078
2079/* models */
2080enum {
2081 AD1988_6STACK,
2082 AD1988_6STACK_DIG,
Raymond Yauc66ddf32011-01-17 11:19:03 +01002083 AD1988_6STACK_DIG_FP,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002084 AD1988_3STACK,
2085 AD1988_3STACK_DIG,
2086 AD1988_LAPTOP,
2087 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01002088 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002089 AD1988_MODEL_LAST,
2090};
2091
Takashi Iwaid32410b12005-11-24 16:06:23 +01002092/* reivision id to check workarounds */
2093#define AD1988A_REV2 0x100200
2094
Takashi Iwai1a806f42006-07-03 15:58:16 +02002095#define is_rev2(codec) \
2096 ((codec)->vendor_id == 0x11d41988 && \
2097 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002098
2099/*
2100 * mixers
2101 */
2102
Takashi Iwaid32410b12005-11-24 16:06:23 +01002103static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002104 0x04, 0x06, 0x05, 0x0a
2105};
2106
Takashi Iwaid32410b12005-11-24 16:06:23 +01002107static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002108 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002109};
2110
2111/* for AD1988A revision-2, DAC2-4 are swapped */
2112static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
2113 0x04, 0x05, 0x0a, 0x06
2114};
2115
Raymond Yauc66ddf32011-01-17 11:19:03 +01002116static hda_nid_t ad1988_alt_dac_nid[1] = {
2117 0x03
2118};
2119
Takashi Iwaid32410b12005-11-24 16:06:23 +01002120static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002121 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002122};
2123
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002124static hda_nid_t ad1988_adc_nids[3] = {
2125 0x08, 0x09, 0x0f
2126};
2127
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002128static hda_nid_t ad1988_capsrc_nids[3] = {
2129 0x0c, 0x0d, 0x0e
2130};
2131
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002132#define AD1988_SPDIF_OUT 0x02
2133#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002134#define AD1988_SPDIF_IN 0x07
2135
Takashi Iwai3a08e302009-02-13 11:37:08 +01002136static hda_nid_t ad1989b_slave_dig_outs[] = {
2137 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002138};
2139
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002140static struct hda_input_mux ad1988_6stack_capture_source = {
2141 .num_items = 5,
2142 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002143 { "Front Mic", 0x1 }, /* port-B */
2144 { "Line", 0x2 }, /* port-C */
2145 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002146 { "CD", 0x5 },
2147 { "Mix", 0x9 },
2148 },
2149};
2150
2151static struct hda_input_mux ad1988_laptop_capture_source = {
2152 .num_items = 3,
2153 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002154 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002155 { "CD", 0x5 },
2156 { "Mix", 0x9 },
2157 },
2158};
2159
2160/*
2161 */
2162static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
2163 struct snd_ctl_elem_info *uinfo)
2164{
2165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2166 struct ad198x_spec *spec = codec->spec;
2167 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
2168 spec->num_channel_mode);
2169}
2170
2171static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
2172 struct snd_ctl_elem_value *ucontrol)
2173{
2174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2175 struct ad198x_spec *spec = codec->spec;
2176 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
2177 spec->num_channel_mode, spec->multiout.max_channels);
2178}
2179
2180static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2181 struct snd_ctl_elem_value *ucontrol)
2182{
2183 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2184 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002185 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2186 spec->num_channel_mode,
2187 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002188 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002189 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002190 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002191}
2192
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002193/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002194static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002195 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2196 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2197 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2198 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2199 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002200 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002201};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002202
Takashi Iwaid32410b12005-11-24 16:06:23 +01002203static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2204 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2205 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2206 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2207 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2208 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002209 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002210};
2211
2212static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002213 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2214 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2215 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2216 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2217 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2218 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2219 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2220
2221 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2222 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2223 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2224 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2225 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2226 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2227 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2228 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2229
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002230 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002231 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2232
David Henningsson5f99f862011-01-04 15:24:24 +01002233 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2234 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002235
2236 { } /* end */
2237};
2238
Raymond Yauc66ddf32011-01-17 11:19:03 +01002239static struct snd_kcontrol_new ad1988_6stack_fp_mixers[] = {
2240 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2241
2242 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2243 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2244 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2245 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2246 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2247 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2248 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2249
2250 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2251 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2252 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2253 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2254 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2255 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2256 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2257 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2258
2259 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2260 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2261
2262 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2263 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
2264
2265 { } /* end */
2266};
2267
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002268/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002269static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002270 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002271 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002272 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2273 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002274 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002275};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002276
Takashi Iwaid32410b12005-11-24 16:06:23 +01002277static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2278 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002279 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2280 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2281 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002282 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002283};
2284
2285static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002286 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002287 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2288 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2289 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002290 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2291 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2292
2293 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2294 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2295 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2296 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2297 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2298 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2299 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2300 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2301
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002302 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002303 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2304
David Henningsson5f99f862011-01-04 15:24:24 +01002305 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2306 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002307 {
2308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2309 .name = "Channel Mode",
2310 .info = ad198x_ch_mode_info,
2311 .get = ad198x_ch_mode_get,
2312 .put = ad198x_ch_mode_put,
2313 },
2314
2315 { } /* end */
2316};
2317
2318/* laptop mode */
2319static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2320 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2321 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2322 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2323
2324 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2325 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2326 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2327 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2328 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2329 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2330
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002331 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002332 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2333
David Henningsson5f99f862011-01-04 15:24:24 +01002334 HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002335
2336 {
2337 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2338 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002339 .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
Takashi Iwai18a815d2006-03-01 19:54:39 +01002340 .info = ad198x_eapd_info,
2341 .get = ad198x_eapd_get,
2342 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +01002343 .private_value = 0x12, /* port-D */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002344 },
2345
2346 { } /* end */
2347};
2348
2349/* capture */
2350static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2351 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2352 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2353 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2354 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2355 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2356 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2357 {
2358 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2359 /* The multiple "Capture Source" controls confuse alsamixer
2360 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002361 */
2362 /* .name = "Capture Source", */
2363 .name = "Input Source",
2364 .count = 3,
2365 .info = ad198x_mux_enum_info,
2366 .get = ad198x_mux_enum_get,
2367 .put = ad198x_mux_enum_put,
2368 },
2369 { } /* end */
2370};
2371
2372static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2373 struct snd_ctl_elem_info *uinfo)
2374{
2375 static char *texts[] = {
2376 "PCM", "ADC1", "ADC2", "ADC3"
2377 };
2378 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2379 uinfo->count = 1;
2380 uinfo->value.enumerated.items = 4;
2381 if (uinfo->value.enumerated.item >= 4)
2382 uinfo->value.enumerated.item = 3;
2383 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2384 return 0;
2385}
2386
2387static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2388 struct snd_ctl_elem_value *ucontrol)
2389{
2390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2391 unsigned int sel;
2392
Takashi Iwaibddcf542007-07-24 18:04:05 +02002393 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2394 AC_AMP_GET_INPUT);
2395 if (!(sel & 0x80))
2396 ucontrol->value.enumerated.item[0] = 0;
2397 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002398 sel = snd_hda_codec_read(codec, 0x0b, 0,
2399 AC_VERB_GET_CONNECT_SEL, 0);
2400 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002401 sel++;
2402 else
2403 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002404 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002405 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002406 return 0;
2407}
2408
2409static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2410 struct snd_ctl_elem_value *ucontrol)
2411{
2412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002413 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002414 int change;
2415
Takashi Iwai35b26722007-05-05 12:17:17 +02002416 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002417 if (val > 3)
2418 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002419 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002420 sel = snd_hda_codec_read(codec, 0x1d, 0,
2421 AC_VERB_GET_AMP_GAIN_MUTE,
2422 AC_AMP_GET_INPUT);
2423 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002424 if (change) {
2425 snd_hda_codec_write_cache(codec, 0x1d, 0,
2426 AC_VERB_SET_AMP_GAIN_MUTE,
2427 AMP_IN_UNMUTE(0));
2428 snd_hda_codec_write_cache(codec, 0x1d, 0,
2429 AC_VERB_SET_AMP_GAIN_MUTE,
2430 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002431 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002432 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002433 sel = snd_hda_codec_read(codec, 0x1d, 0,
2434 AC_VERB_GET_AMP_GAIN_MUTE,
2435 AC_AMP_GET_INPUT | 0x01);
2436 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002437 if (change) {
2438 snd_hda_codec_write_cache(codec, 0x1d, 0,
2439 AC_VERB_SET_AMP_GAIN_MUTE,
2440 AMP_IN_MUTE(0));
2441 snd_hda_codec_write_cache(codec, 0x1d, 0,
2442 AC_VERB_SET_AMP_GAIN_MUTE,
2443 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002444 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002445 sel = snd_hda_codec_read(codec, 0x0b, 0,
2446 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2447 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002448 if (change)
2449 snd_hda_codec_write_cache(codec, 0x0b, 0,
2450 AC_VERB_SET_CONNECT_SEL,
2451 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002452 }
2453 return change;
2454}
2455
2456static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2457 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2458 {
2459 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2460 .name = "IEC958 Playback Source",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002461 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002462 .info = ad1988_spdif_playback_source_info,
2463 .get = ad1988_spdif_playback_source_get,
2464 .put = ad1988_spdif_playback_source_put,
2465 },
2466 { } /* end */
2467};
2468
2469static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2470 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2471 { } /* end */
2472};
2473
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002474static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2475 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002476 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002477 { } /* end */
2478};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002479
2480/*
2481 * initialization verbs
2482 */
2483
2484/*
2485 * for 6-stack (+dig)
2486 */
2487static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002488 /* Front, Surround, CLFE, side DAC; unmute as default */
2489 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2490 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2491 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002493 /* Port-A front headphon path */
2494 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2495 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2496 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2497 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2498 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2499 /* Port-D line-out path */
2500 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2501 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2502 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2504 /* Port-F surround path */
2505 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2506 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2507 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2508 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2509 /* Port-G CLFE path */
2510 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2511 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2512 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2513 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2514 /* Port-H side path */
2515 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2516 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2517 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2519 /* Mono out path */
2520 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2521 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2522 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2523 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2524 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2525 /* Port-B front mic-in path */
2526 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2527 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2528 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2529 /* Port-C line-in path */
2530 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2531 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2532 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2533 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2534 /* Port-E mic-in path */
2535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2536 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2537 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2538 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002539 /* Analog CD Input */
2540 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002541 /* Analog Mix output amp */
2542 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002543
2544 { }
2545};
2546
Raymond Yauc66ddf32011-01-17 11:19:03 +01002547static struct hda_verb ad1988_6stack_fp_init_verbs[] = {
2548 /* Front, Surround, CLFE, side DAC; unmute as default */
2549 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2550 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2551 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2552 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2553 /* Headphone; unmute as default */
2554 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2555 /* Port-A front headphon path */
2556 {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
2557 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2558 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2559 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2560 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2561 /* Port-D line-out path */
2562 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2563 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2564 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2565 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2566 /* Port-F surround path */
2567 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2568 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2569 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2570 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2571 /* Port-G CLFE path */
2572 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2573 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2574 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2575 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2576 /* Port-H side path */
2577 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2578 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2579 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2580 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2581 /* Mono out path */
2582 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2583 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2584 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2585 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2586 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2587 /* Port-B front mic-in path */
2588 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2589 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2590 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2591 /* Port-C line-in path */
2592 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2593 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2594 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2595 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2596 /* Port-E mic-in path */
2597 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2598 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2599 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2600 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2601 /* Analog CD Input */
2602 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2603 /* Analog Mix output amp */
2604 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2605
2606 { }
2607};
2608
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002609static struct hda_verb ad1988_capture_init_verbs[] = {
2610 /* mute analog mix */
2611 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2612 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2613 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2614 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2615 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2616 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2617 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2618 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2619 /* select ADCs - front-mic */
2620 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2621 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2622 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002623
2624 { }
2625};
2626
2627static struct hda_verb ad1988_spdif_init_verbs[] = {
2628 /* SPDIF out sel */
2629 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2630 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2631 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002632 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002633 /* SPDIF out pin */
2634 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002635
2636 { }
2637};
2638
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01002639static struct hda_verb ad1988_spdif_in_init_verbs[] = {
2640 /* unmute SPDIF input pin */
2641 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2642 { }
2643};
2644
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002645/* AD1989 has no ADC -> SPDIF route */
2646static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002647 /* SPDIF-1 out pin */
2648 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002649 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002650 /* SPDIF-2/HDMI out pin */
2651 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2652 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002653 { }
2654};
2655
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002656/*
2657 * verbs for 3stack (+dig)
2658 */
2659static struct hda_verb ad1988_3stack_ch2_init[] = {
2660 /* set port-C to line-in */
2661 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2662 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2663 /* set port-E to mic-in */
2664 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2665 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2666 { } /* end */
2667};
2668
2669static struct hda_verb ad1988_3stack_ch6_init[] = {
2670 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002671 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002672 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002673 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002674 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002675 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002676 { } /* end */
2677};
2678
2679static struct hda_channel_mode ad1988_3stack_modes[2] = {
2680 { 2, ad1988_3stack_ch2_init },
2681 { 6, ad1988_3stack_ch6_init },
2682};
2683
2684static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002685 /* Front, Surround, CLFE, side DAC; unmute as default */
2686 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2687 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2688 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2689 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002690 /* Port-A front headphon path */
2691 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2692 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2693 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2694 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2695 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2696 /* Port-D line-out path */
2697 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2698 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2699 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2700 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2701 /* Mono out path */
2702 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2703 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2704 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2705 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2706 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2707 /* Port-B front mic-in path */
2708 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2709 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2710 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002711 /* Port-C line-in/surround path - 6ch mode as default */
2712 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2713 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002714 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002715 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002716 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002717 /* Port-E mic-in/CLFE path - 6ch mode as default */
2718 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2719 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002720 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002721 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002722 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2723 /* mute analog mix */
2724 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2725 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2726 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2727 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2728 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2729 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2730 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2731 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2732 /* select ADCs - front-mic */
2733 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2734 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2735 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002736 /* Analog Mix output amp */
2737 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002738 { }
2739};
2740
2741/*
2742 * verbs for laptop mode (+dig)
2743 */
2744static struct hda_verb ad1988_laptop_hp_on[] = {
2745 /* unmute port-A and mute port-D */
2746 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2747 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2748 { } /* end */
2749};
2750static struct hda_verb ad1988_laptop_hp_off[] = {
2751 /* mute port-A and unmute port-D */
2752 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2753 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2754 { } /* end */
2755};
2756
2757#define AD1988_HP_EVENT 0x01
2758
2759static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002760 /* Front, Surround, CLFE, side DAC; unmute as default */
2761 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2762 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2763 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2764 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002765 /* Port-A front headphon path */
2766 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2767 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2768 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2769 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2770 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2771 /* unsolicited event for pin-sense */
2772 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2773 /* Port-D line-out path + EAPD */
2774 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2775 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2776 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2777 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2778 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2779 /* Mono out path */
2780 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2781 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2782 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2783 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2784 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2785 /* Port-B mic-in path */
2786 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2787 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2788 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2789 /* Port-C docking station - try to output */
2790 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2791 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2792 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2793 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2794 /* mute analog mix */
2795 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2796 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2797 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2798 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2799 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2800 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2801 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2802 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2803 /* select ADCs - mic */
2804 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2805 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2806 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002807 /* Analog Mix output amp */
2808 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002809 { }
2810};
2811
2812static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2813{
2814 if ((res >> 26) != AD1988_HP_EVENT)
2815 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002816 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002817 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2818 else
2819 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2820}
2821
Takashi Iwaicb53c622007-08-10 17:21:45 +02002822#ifdef CONFIG_SND_HDA_POWER_SAVE
2823static struct hda_amp_list ad1988_loopbacks[] = {
2824 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2825 { 0x20, HDA_INPUT, 1 }, /* Line */
2826 { 0x20, HDA_INPUT, 4 }, /* Mic */
2827 { 0x20, HDA_INPUT, 6 }, /* CD */
2828 { } /* end */
2829};
2830#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002831
2832/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002833 * Automatic parse of I/O pins from the BIOS configuration
2834 */
2835
Takashi Iwaid32410b12005-11-24 16:06:23 +01002836enum {
2837 AD_CTL_WIDGET_VOL,
2838 AD_CTL_WIDGET_MUTE,
2839 AD_CTL_BIND_MUTE,
2840};
2841static struct snd_kcontrol_new ad1988_control_templates[] = {
2842 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2843 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2844 HDA_BIND_MUTE(NULL, 0, 0, 0),
2845};
2846
2847/* add dynamic controls */
2848static int add_control(struct ad198x_spec *spec, int type, const char *name,
2849 unsigned long val)
2850{
2851 struct snd_kcontrol_new *knew;
2852
Takashi Iwai603c4012008-07-30 15:01:44 +02002853 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2854 knew = snd_array_new(&spec->kctls);
2855 if (!knew)
2856 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002857 *knew = ad1988_control_templates[type];
2858 knew->name = kstrdup(name, GFP_KERNEL);
2859 if (! knew->name)
2860 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002861 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002862 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002863 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002864 return 0;
2865}
2866
2867#define AD1988_PIN_CD_NID 0x18
2868#define AD1988_PIN_BEEP_NID 0x10
2869
2870static hda_nid_t ad1988_mixer_nids[8] = {
2871 /* A B C D E F G H */
2872 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2873};
2874
2875static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2876{
2877 static hda_nid_t idx_to_dac[8] = {
2878 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002879 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002880 };
2881 static hda_nid_t idx_to_dac_rev2[8] = {
2882 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002883 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002884 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002885 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002886 return idx_to_dac_rev2[idx];
2887 else
2888 return idx_to_dac[idx];
2889}
2890
2891static hda_nid_t ad1988_boost_nids[8] = {
2892 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2893};
2894
2895static int ad1988_pin_idx(hda_nid_t nid)
2896{
2897 static hda_nid_t ad1988_io_pins[8] = {
2898 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2899 };
2900 int i;
2901 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2902 if (ad1988_io_pins[i] == nid)
2903 return i;
2904 return 0; /* should be -1 */
2905}
2906
2907static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2908{
2909 static int loopback_idx[8] = {
2910 2, 0, 1, 3, 4, 5, 1, 4
2911 };
2912 switch (nid) {
2913 case AD1988_PIN_CD_NID:
2914 return 6;
2915 default:
2916 return loopback_idx[ad1988_pin_idx(nid)];
2917 }
2918}
2919
2920static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2921{
2922 static int adc_idx[8] = {
2923 0, 1, 2, 8, 4, 3, 6, 7
2924 };
2925 switch (nid) {
2926 case AD1988_PIN_CD_NID:
2927 return 5;
2928 default:
2929 return adc_idx[ad1988_pin_idx(nid)];
2930 }
2931}
2932
2933/* fill in the dac_nids table from the parsed pin configuration */
2934static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2935 const struct auto_pin_cfg *cfg)
2936{
2937 struct ad198x_spec *spec = codec->spec;
2938 int i, idx;
2939
2940 spec->multiout.dac_nids = spec->private_dac_nids;
2941
2942 /* check the pins hardwired to audio widget */
2943 for (i = 0; i < cfg->line_outs; i++) {
2944 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2945 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2946 }
2947 spec->multiout.num_dacs = cfg->line_outs;
2948 return 0;
2949}
2950
2951/* add playback controls from the parsed DAC table */
2952static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2953 const struct auto_pin_cfg *cfg)
2954{
2955 char name[32];
2956 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2957 hda_nid_t nid;
2958 int i, err;
2959
2960 for (i = 0; i < cfg->line_outs; i++) {
2961 hda_nid_t dac = spec->multiout.dac_nids[i];
2962 if (! dac)
2963 continue;
2964 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2965 if (i == 2) {
2966 /* Center/LFE */
2967 err = add_control(spec, AD_CTL_WIDGET_VOL,
2968 "Center Playback Volume",
2969 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2970 if (err < 0)
2971 return err;
2972 err = add_control(spec, AD_CTL_WIDGET_VOL,
2973 "LFE Playback Volume",
2974 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2975 if (err < 0)
2976 return err;
2977 err = add_control(spec, AD_CTL_BIND_MUTE,
2978 "Center Playback Switch",
2979 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2980 if (err < 0)
2981 return err;
2982 err = add_control(spec, AD_CTL_BIND_MUTE,
2983 "LFE Playback Switch",
2984 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2985 if (err < 0)
2986 return err;
2987 } else {
2988 sprintf(name, "%s Playback Volume", chname[i]);
2989 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2990 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2991 if (err < 0)
2992 return err;
2993 sprintf(name, "%s Playback Switch", chname[i]);
2994 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2995 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2996 if (err < 0)
2997 return err;
2998 }
2999 }
3000 return 0;
3001}
3002
3003/* add playback controls for speaker and HP outputs */
3004static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3005 const char *pfx)
3006{
3007 struct ad198x_spec *spec = codec->spec;
3008 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02003009 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003010 char name[32];
3011
3012 if (! pin)
3013 return 0;
3014
3015 idx = ad1988_pin_idx(pin);
3016 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02003017 /* check whether the corresponding DAC was already taken */
3018 for (i = 0; i < spec->autocfg.line_outs; i++) {
3019 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3020 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
3021 if (dac == nid)
3022 break;
3023 }
3024 if (i >= spec->autocfg.line_outs) {
3025 /* specify the DAC as the extra output */
3026 if (!spec->multiout.hp_nid)
3027 spec->multiout.hp_nid = nid;
3028 else
3029 spec->multiout.extra_out_nid[0] = nid;
3030 /* control HP volume/switch on the output mixer amp */
3031 sprintf(name, "%s Playback Volume", pfx);
3032 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
3033 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3034 if (err < 0)
3035 return err;
3036 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01003037 nid = ad1988_mixer_nids[idx];
3038 sprintf(name, "%s Playback Switch", pfx);
3039 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
3040 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
3041 return err;
3042 return 0;
3043}
3044
3045/* create input playback/capture controls for the given pin */
3046static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
Takashi Iwai9e042e72010-08-30 13:04:44 +02003047 const char *ctlname, int ctlidx, int boost)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003048{
3049 char name[32];
3050 int err, idx;
3051
3052 sprintf(name, "%s Playback Volume", ctlname);
3053 idx = ad1988_pin_to_loopback_idx(pin);
3054 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
3055 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
3056 return err;
3057 sprintf(name, "%s Playback Switch", ctlname);
3058 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
3059 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
3060 return err;
3061 if (boost) {
3062 hda_nid_t bnid;
3063 idx = ad1988_pin_idx(pin);
3064 bnid = ad1988_boost_nids[idx];
3065 if (bnid) {
David Henningsson5f99f862011-01-04 15:24:24 +01003066 sprintf(name, "%s Boost Volume", ctlname);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003067 return add_control(spec, AD_CTL_WIDGET_VOL, name,
3068 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
3069
3070 }
3071 }
3072 return 0;
3073}
3074
3075/* create playback/capture controls for input pins */
Takashi Iwai10a20af2010-09-09 16:28:02 +02003076static int ad1988_auto_create_analog_input_ctls(struct hda_codec *codec,
Takashi Iwaid32410b12005-11-24 16:06:23 +01003077 const struct auto_pin_cfg *cfg)
3078{
Takashi Iwai10a20af2010-09-09 16:28:02 +02003079 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003080 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003081 int i, err, type, type_idx;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003082
Takashi Iwai9e042e72010-08-30 13:04:44 +02003083 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003084 const char *label;
Takashi Iwai9e042e72010-08-30 13:04:44 +02003085 type = cfg->inputs[i].type;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003086 label = hda_get_autocfg_input_label(codec, cfg, i);
3087 snd_hda_add_imux_item(imux, label,
3088 ad1988_pin_to_adc_idx(cfg->inputs[i].pin),
3089 &type_idx);
Takashi Iwai9e042e72010-08-30 13:04:44 +02003090 err = new_analog_input(spec, cfg->inputs[i].pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003091 label, type_idx,
Takashi Iwai86e29592010-09-09 14:50:17 +02003092 type == AUTO_PIN_MIC);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003093 if (err < 0)
3094 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003095 }
Takashi Iwai10a20af2010-09-09 16:28:02 +02003096 snd_hda_add_imux_item(imux, "Mix", 9, NULL);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003097
3098 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
3099 "Analog Mix Playback Volume",
3100 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
3101 return err;
3102 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
3103 "Analog Mix Playback Switch",
3104 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
3105 return err;
3106
3107 return 0;
3108}
3109
3110static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
3111 hda_nid_t nid, int pin_type,
3112 int dac_idx)
3113{
3114 /* set as output */
3115 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
3116 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3117 switch (nid) {
3118 case 0x11: /* port-A - DAC 04 */
3119 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3120 break;
3121 case 0x14: /* port-B - DAC 06 */
3122 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
3123 break;
3124 case 0x15: /* port-C - DAC 05 */
3125 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
3126 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003127 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01003128 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3129 break;
3130 case 0x13: /* mono - DAC 04 */
3131 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
3132 break;
3133 }
3134}
3135
3136static void ad1988_auto_init_multi_out(struct hda_codec *codec)
3137{
3138 struct ad198x_spec *spec = codec->spec;
3139 int i;
3140
3141 for (i = 0; i < spec->autocfg.line_outs; i++) {
3142 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3143 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
3144 }
3145}
3146
3147static void ad1988_auto_init_extra_out(struct hda_codec *codec)
3148{
3149 struct ad198x_spec *spec = codec->spec;
3150 hda_nid_t pin;
3151
Takashi Iwai82bc9552006-03-21 11:24:42 +01003152 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01003153 if (pin) /* connect to front */
3154 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003155 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01003156 if (pin) /* connect to front */
3157 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3158}
3159
3160static void ad1988_auto_init_analog_input(struct hda_codec *codec)
3161{
3162 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9e042e72010-08-30 13:04:44 +02003163 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003164 int i, idx;
3165
Takashi Iwai9e042e72010-08-30 13:04:44 +02003166 for (i = 0; i < cfg->num_inputs; i++) {
3167 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003168 switch (nid) {
3169 case 0x15: /* port-C */
3170 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3171 break;
3172 case 0x17: /* port-E */
3173 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3174 break;
3175 }
3176 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai86e29592010-09-09 14:50:17 +02003177 i == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003178 if (nid != AD1988_PIN_CD_NID)
3179 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3180 AMP_OUT_MUTE);
3181 idx = ad1988_pin_idx(nid);
3182 if (ad1988_boost_nids[idx])
3183 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
3184 AC_VERB_SET_AMP_GAIN_MUTE,
3185 AMP_OUT_ZERO);
3186 }
3187}
3188
3189/* parse the BIOS configuration and set up the alc_spec */
3190/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
3191static int ad1988_parse_auto_config(struct hda_codec *codec)
3192{
3193 struct ad198x_spec *spec = codec->spec;
3194 int err;
3195
Kailang Yangdf694da2005-12-05 19:42:22 +01003196 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003197 return err;
3198 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3199 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003200 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003201 return 0; /* can't find valid BIOS pin config */
3202 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01003203 (err = ad1988_auto_create_extra_out(codec,
3204 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003205 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003206 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003207 "Headphone")) < 0 ||
Takashi Iwai10a20af2010-09-09 16:28:02 +02003208 (err = ad1988_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003209 return err;
3210
3211 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3212
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003213 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003214 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3215 if (spec->autocfg.dig_in_pin)
3216 spec->dig_in_nid = AD1988_SPDIF_IN;
3217
Takashi Iwai603c4012008-07-30 15:01:44 +02003218 if (spec->kctls.list)
3219 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003220
3221 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
3222
3223 spec->input_mux = &spec->private_imux;
3224
3225 return 1;
3226}
3227
3228/* init callback for auto-configuration model -- overriding the default init */
3229static int ad1988_auto_init(struct hda_codec *codec)
3230{
3231 ad198x_init(codec);
3232 ad1988_auto_init_multi_out(codec);
3233 ad1988_auto_init_extra_out(codec);
3234 ad1988_auto_init_analog_input(codec);
3235 return 0;
3236}
3237
Takashi Iwaid32410b12005-11-24 16:06:23 +01003238/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003239 */
3240
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003241static const char *ad1988_models[AD1988_MODEL_LAST] = {
3242 [AD1988_6STACK] = "6stack",
3243 [AD1988_6STACK_DIG] = "6stack-dig",
Raymond Yauc66ddf32011-01-17 11:19:03 +01003244 [AD1988_6STACK_DIG_FP] = "6stack-dig-fp",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003245 [AD1988_3STACK] = "3stack",
3246 [AD1988_3STACK_DIG] = "3stack-dig",
3247 [AD1988_LAPTOP] = "laptop",
3248 [AD1988_LAPTOP_DIG] = "laptop-dig",
3249 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003250};
3251
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003252static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01003253 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01003254 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02003255 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07003256 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003257 {}
3258};
3259
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003260static int patch_ad1988(struct hda_codec *codec)
3261{
3262 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003263 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003264
3265 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3266 if (spec == NULL)
3267 return -ENOMEM;
3268
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003269 codec->spec = spec;
3270
Takashi Iwai1a806f42006-07-03 15:58:16 +02003271 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003272 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3273
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003274 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003275 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003276 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02003277 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3278 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003279 board_config = AD1988_AUTO;
3280 }
3281
3282 if (board_config == AD1988_AUTO) {
3283 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003284 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003285 if (err < 0) {
3286 ad198x_free(codec);
3287 return err;
3288 } else if (! err) {
3289 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3290 board_config = AD1988_6STACK;
3291 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003292 }
3293
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003294 err = snd_hda_attach_beep_device(codec, 0x10);
3295 if (err < 0) {
3296 ad198x_free(codec);
3297 return err;
3298 }
3299 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3300
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003301 switch (board_config) {
3302 case AD1988_6STACK:
3303 case AD1988_6STACK_DIG:
Raymond Yauc66ddf32011-01-17 11:19:03 +01003304 case AD1988_6STACK_DIG_FP:
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003305 spec->multiout.max_channels = 8;
3306 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003307 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003308 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3309 else
3310 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003311 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003312 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003313 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003314 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3315 else
3316 spec->mixers[0] = ad1988_6stack_mixers1;
Raymond Yauc66ddf32011-01-17 11:19:03 +01003317 if (board_config == AD1988_6STACK_DIG_FP) {
3318 spec->mixers[1] = ad1988_6stack_fp_mixers;
3319 spec->slave_vols = ad1988_6stack_fp_slave_vols;
3320 spec->slave_sws = ad1988_6stack_fp_slave_sws;
3321 spec->alt_dac_nid = ad1988_alt_dac_nid;
3322 spec->stream_analog_alt_playback =
3323 &ad198x_pcm_analog_alt_playback;
3324 } else
3325 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003326 spec->num_init_verbs = 1;
Raymond Yauc66ddf32011-01-17 11:19:03 +01003327 if (board_config == AD1988_6STACK_DIG_FP)
3328 spec->init_verbs[0] = ad1988_6stack_fp_init_verbs;
3329 else
3330 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3331 if ((board_config == AD1988_6STACK_DIG) ||
3332 (board_config == AD1988_6STACK_DIG_FP)) {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003333 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3334 spec->dig_in_nid = AD1988_SPDIF_IN;
3335 }
3336 break;
3337 case AD1988_3STACK:
3338 case AD1988_3STACK_DIG:
3339 spec->multiout.max_channels = 6;
3340 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003341 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003342 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3343 else
3344 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003345 spec->input_mux = &ad1988_6stack_capture_source;
3346 spec->channel_mode = ad1988_3stack_modes;
3347 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003348 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003349 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003350 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3351 else
3352 spec->mixers[0] = ad1988_3stack_mixers1;
3353 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003354 spec->num_init_verbs = 1;
3355 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3356 if (board_config == AD1988_3STACK_DIG)
3357 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3358 break;
3359 case AD1988_LAPTOP:
3360 case AD1988_LAPTOP_DIG:
3361 spec->multiout.max_channels = 2;
3362 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003363 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003364 spec->input_mux = &ad1988_laptop_capture_source;
3365 spec->num_mixers = 1;
3366 spec->mixers[0] = ad1988_laptop_mixers;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01003367 spec->inv_eapd = 1; /* inverted EAPD */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003368 spec->num_init_verbs = 1;
3369 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3370 if (board_config == AD1988_LAPTOP_DIG)
3371 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3372 break;
3373 }
3374
Takashi Iwaid32410b12005-11-24 16:06:23 +01003375 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3376 spec->adc_nids = ad1988_adc_nids;
3377 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003378 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3379 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3380 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003381 if (codec->vendor_id >= 0x11d4989a) {
3382 spec->mixers[spec->num_mixers++] =
3383 ad1989_spdif_out_mixers;
3384 spec->init_verbs[spec->num_init_verbs++] =
3385 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003386 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003387 } else {
3388 spec->mixers[spec->num_mixers++] =
3389 ad1988_spdif_out_mixers;
3390 spec->init_verbs[spec->num_init_verbs++] =
3391 ad1988_spdif_init_verbs;
3392 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003393 }
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003394 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003395 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003396 spec->init_verbs[spec->num_init_verbs++] =
3397 ad1988_spdif_in_init_verbs;
3398 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003399
3400 codec->patch_ops = ad198x_patch_ops;
3401 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003402 case AD1988_AUTO:
3403 codec->patch_ops.init = ad1988_auto_init;
3404 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003405 case AD1988_LAPTOP:
3406 case AD1988_LAPTOP_DIG:
3407 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3408 break;
3409 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003410#ifdef CONFIG_SND_HDA_POWER_SAVE
3411 spec->loopback.amplist = ad1988_loopbacks;
3412#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003413 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003414
Takashi Iwai729d55b2009-12-25 22:49:01 +01003415 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02003416 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01003417
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003418 return 0;
3419}
3420
3421
3422/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003423 * AD1884 / AD1984
3424 *
3425 * port-B - front line/mic-in
3426 * port-E - aux in/out
3427 * port-F - aux in/out
3428 * port-C - rear line/mic-in
3429 * port-D - rear line/hp-out
3430 * port-A - front line/hp-out
3431 *
3432 * AD1984 = AD1884 + two digital mic-ins
3433 *
3434 * FIXME:
3435 * For simplicity, we share the single DAC for both HP and line-outs
3436 * right now. The inidividual playbacks could be easily implemented,
3437 * but no build-up framework is given, so far.
3438 */
3439
3440static hda_nid_t ad1884_dac_nids[1] = {
3441 0x04,
3442};
3443
3444static hda_nid_t ad1884_adc_nids[2] = {
3445 0x08, 0x09,
3446};
3447
3448static hda_nid_t ad1884_capsrc_nids[2] = {
3449 0x0c, 0x0d,
3450};
3451
3452#define AD1884_SPDIF_OUT 0x02
3453
3454static struct hda_input_mux ad1884_capture_source = {
3455 .num_items = 4,
3456 .items = {
3457 { "Front Mic", 0x0 },
3458 { "Mic", 0x1 },
3459 { "CD", 0x2 },
3460 { "Mix", 0x3 },
3461 },
3462};
3463
3464static struct snd_kcontrol_new ad1884_base_mixers[] = {
3465 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3466 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3467 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3468 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3469 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3470 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3471 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3472 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3473 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3474 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3475 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3476 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003477 HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3478 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003479 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3480 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3481 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3482 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3483 {
3484 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3485 /* The multiple "Capture Source" controls confuse alsamixer
3486 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003487 */
3488 /* .name = "Capture Source", */
3489 .name = "Input Source",
3490 .count = 2,
3491 .info = ad198x_mux_enum_info,
3492 .get = ad198x_mux_enum_get,
3493 .put = ad198x_mux_enum_put,
3494 },
3495 /* SPDIF controls */
3496 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3497 {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3500 /* identical with ad1983 */
3501 .info = ad1983_spdif_route_info,
3502 .get = ad1983_spdif_route_get,
3503 .put = ad1983_spdif_route_put,
3504 },
3505 { } /* end */
3506};
3507
3508static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3509 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3510 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3511 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003512 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003513 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003514 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003515 { } /* end */
3516};
3517
3518/*
3519 * initialization verbs
3520 */
3521static struct hda_verb ad1884_init_verbs[] = {
3522 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003523 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3524 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003525 /* Port-A (HP) mixer */
3526 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3527 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3528 /* Port-A pin */
3529 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3530 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3531 /* HP selector - select DAC2 */
3532 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3533 /* Port-D (Line-out) mixer */
3534 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3535 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3536 /* Port-D pin */
3537 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3538 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3539 /* Mono-out mixer */
3540 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3541 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3542 /* Mono-out pin */
3543 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3544 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3545 /* Mono selector */
3546 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3547 /* Port-B (front mic) pin */
3548 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003549 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003550 /* Port-C (rear mic) pin */
3551 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003552 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003553 /* Analog mixer; mute as default */
3554 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3555 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3556 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3557 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3558 /* Analog Mix output amp */
3559 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3560 /* SPDIF output selector */
3561 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3562 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3563 { } /* end */
3564};
3565
Takashi Iwaicb53c622007-08-10 17:21:45 +02003566#ifdef CONFIG_SND_HDA_POWER_SAVE
3567static struct hda_amp_list ad1884_loopbacks[] = {
3568 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3569 { 0x20, HDA_INPUT, 1 }, /* Mic */
3570 { 0x20, HDA_INPUT, 2 }, /* CD */
3571 { 0x20, HDA_INPUT, 4 }, /* Docking */
3572 { } /* end */
3573};
3574#endif
3575
Takashi Iwai2134ea42008-01-10 16:53:55 +01003576static const char *ad1884_slave_vols[] = {
3577 "PCM Playback Volume",
3578 "Mic Playback Volume",
3579 "Mono Playback Volume",
3580 "Front Mic Playback Volume",
3581 "Mic Playback Volume",
3582 "CD Playback Volume",
3583 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003584 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003585 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003586 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003587 NULL
3588};
3589
Takashi Iwai2bac6472007-05-18 18:21:41 +02003590static int patch_ad1884(struct hda_codec *codec)
3591{
3592 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003593 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003594
3595 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3596 if (spec == NULL)
3597 return -ENOMEM;
3598
Takashi Iwai2bac6472007-05-18 18:21:41 +02003599 codec->spec = spec;
3600
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003601 err = snd_hda_attach_beep_device(codec, 0x10);
3602 if (err < 0) {
3603 ad198x_free(codec);
3604 return err;
3605 }
3606 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3607
Takashi Iwai2bac6472007-05-18 18:21:41 +02003608 spec->multiout.max_channels = 2;
3609 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3610 spec->multiout.dac_nids = ad1884_dac_nids;
3611 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3612 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3613 spec->adc_nids = ad1884_adc_nids;
3614 spec->capsrc_nids = ad1884_capsrc_nids;
3615 spec->input_mux = &ad1884_capture_source;
3616 spec->num_mixers = 1;
3617 spec->mixers[0] = ad1884_base_mixers;
3618 spec->num_init_verbs = 1;
3619 spec->init_verbs[0] = ad1884_init_verbs;
3620 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003621#ifdef CONFIG_SND_HDA_POWER_SAVE
3622 spec->loopback.amplist = ad1884_loopbacks;
3623#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003624 spec->vmaster_nid = 0x04;
3625 /* we need to cover all playback volumes */
3626 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003627
3628 codec->patch_ops = ad198x_patch_ops;
3629
Takashi Iwai729d55b2009-12-25 22:49:01 +01003630 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02003631 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01003632
Takashi Iwai2bac6472007-05-18 18:21:41 +02003633 return 0;
3634}
3635
3636/*
3637 * Lenovo Thinkpad T61/X61
3638 */
3639static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003640 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003641 .items = {
3642 { "Mic", 0x0 },
3643 { "Internal Mic", 0x1 },
3644 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003645 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003646 },
3647};
3648
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003649
3650/*
3651 * Dell Precision T3400
3652 */
3653static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3654 .num_items = 3,
3655 .items = {
3656 { "Front Mic", 0x0 },
3657 { "Line-In", 0x1 },
3658 { "Mix", 0x3 },
3659 },
3660};
3661
3662
Takashi Iwai2bac6472007-05-18 18:21:41 +02003663static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3664 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3665 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3666 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3667 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3668 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3669 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3670 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3671 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003672 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3673 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003674 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3675 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003676 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3677 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
3678 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003679 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3680 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3681 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3682 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3683 {
3684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3685 /* The multiple "Capture Source" controls confuse alsamixer
3686 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003687 */
3688 /* .name = "Capture Source", */
3689 .name = "Input Source",
3690 .count = 2,
3691 .info = ad198x_mux_enum_info,
3692 .get = ad198x_mux_enum_get,
3693 .put = ad198x_mux_enum_put,
3694 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003695 /* SPDIF controls */
3696 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3697 {
3698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3699 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3700 /* identical with ad1983 */
3701 .info = ad1983_spdif_route_info,
3702 .get = ad1983_spdif_route_get,
3703 .put = ad1983_spdif_route_put,
3704 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003705 { } /* end */
3706};
3707
3708/* additional verbs */
3709static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3710 /* Port-E (docking station mic) pin */
3711 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3712 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3713 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003714 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003715 /* Analog PC Beeper - allow firmware/ACPI beeps */
3716 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003717 /* Analog mixer - docking mic; mute as default */
3718 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003719 /* enable EAPD bit */
3720 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003721 { } /* end */
3722};
3723
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003724/*
3725 * Dell Precision T3400
3726 */
3727static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3728 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3729 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3730 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3731 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3732 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3733 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3734 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3735 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3736 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003737 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
3738 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003739 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3740 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3741 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3742 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3743 {
3744 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3745 /* The multiple "Capture Source" controls confuse alsamixer
3746 * So call somewhat different..
3747 */
3748 /* .name = "Capture Source", */
3749 .name = "Input Source",
3750 .count = 2,
3751 .info = ad198x_mux_enum_info,
3752 .get = ad198x_mux_enum_get,
3753 .put = ad198x_mux_enum_put,
3754 },
3755 { } /* end */
3756};
3757
Takashi Iwai2bac6472007-05-18 18:21:41 +02003758/* Digial MIC ADC NID 0x05 + 0x06 */
3759static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3760 struct hda_codec *codec,
3761 unsigned int stream_tag,
3762 unsigned int format,
3763 struct snd_pcm_substream *substream)
3764{
3765 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3766 stream_tag, 0, format);
3767 return 0;
3768}
3769
3770static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3771 struct hda_codec *codec,
3772 struct snd_pcm_substream *substream)
3773{
Takashi Iwai888afa12008-03-18 09:57:50 +01003774 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003775 return 0;
3776}
3777
3778static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3779 .substreams = 2,
3780 .channels_min = 2,
3781 .channels_max = 2,
3782 .nid = 0x05,
3783 .ops = {
3784 .prepare = ad1984_pcm_dmic_prepare,
3785 .cleanup = ad1984_pcm_dmic_cleanup
3786 },
3787};
3788
3789static int ad1984_build_pcms(struct hda_codec *codec)
3790{
3791 struct ad198x_spec *spec = codec->spec;
3792 struct hda_pcm *info;
3793 int err;
3794
3795 err = ad198x_build_pcms(codec);
3796 if (err < 0)
3797 return err;
3798
3799 info = spec->pcm_rec + codec->num_pcms;
3800 codec->num_pcms++;
3801 info->name = "AD1984 Digital Mic";
3802 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3803 return 0;
3804}
3805
3806/* models */
3807enum {
3808 AD1984_BASIC,
3809 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003810 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003811 AD1984_MODELS
3812};
3813
3814static const char *ad1984_models[AD1984_MODELS] = {
3815 [AD1984_BASIC] = "basic",
3816 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003817 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003818};
3819
3820static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3821 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003822 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003823 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Luke Yelavich0f9f1ee92010-09-21 17:05:46 +10003824 SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003825 {}
3826};
3827
3828static int patch_ad1984(struct hda_codec *codec)
3829{
3830 struct ad198x_spec *spec;
3831 int board_config, err;
3832
3833 err = patch_ad1884(codec);
3834 if (err < 0)
3835 return err;
3836 spec = codec->spec;
3837 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3838 ad1984_models, ad1984_cfg_tbl);
3839 switch (board_config) {
3840 case AD1984_BASIC:
3841 /* additional digital mics */
3842 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3843 codec->patch_ops.build_pcms = ad1984_build_pcms;
3844 break;
3845 case AD1984_THINKPAD:
Jerone Young68c18692010-08-03 01:46:44 -05003846 if (codec->subsystem_id == 0x17aa20fb) {
3847 /* Thinpad X300 does not have the ability to do SPDIF,
3848 or attach to docking station to use SPDIF */
3849 spec->multiout.dig_out_nid = 0;
3850 } else
3851 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003852 spec->input_mux = &ad1984_thinkpad_capture_source;
3853 spec->mixers[0] = ad1984_thinkpad_mixers;
3854 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +01003855 spec->analog_beep = 1;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003856 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003857 case AD1984_DELL_DESKTOP:
3858 spec->multiout.dig_out_nid = 0;
3859 spec->input_mux = &ad1984_dell_desktop_capture_source;
3860 spec->mixers[0] = ad1984_dell_desktop_mixers;
3861 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003862 }
3863 return 0;
3864}
3865
3866
3867/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003868 * AD1883 / AD1884A / AD1984A / AD1984B
3869 *
3870 * port-B (0x14) - front mic-in
3871 * port-E (0x1c) - rear mic-in
3872 * port-F (0x16) - CD / ext out
3873 * port-C (0x15) - rear line-in
3874 * port-D (0x12) - rear line-out
3875 * port-A (0x11) - front hp-out
3876 *
3877 * AD1984A = AD1884A + digital-mic
3878 * AD1883 = equivalent with AD1984A
3879 * AD1984B = AD1984A + extra SPDIF-out
3880 *
3881 * FIXME:
3882 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3883 */
3884
3885static hda_nid_t ad1884a_dac_nids[1] = {
3886 0x03,
3887};
3888
3889#define ad1884a_adc_nids ad1884_adc_nids
3890#define ad1884a_capsrc_nids ad1884_capsrc_nids
3891
3892#define AD1884A_SPDIF_OUT 0x02
3893
3894static struct hda_input_mux ad1884a_capture_source = {
3895 .num_items = 5,
3896 .items = {
3897 { "Front Mic", 0x0 },
3898 { "Mic", 0x4 },
3899 { "Line", 0x1 },
3900 { "CD", 0x2 },
3901 { "Mix", 0x3 },
3902 },
3903};
3904
3905static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3906 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3907 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3908 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3909 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3910 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3911 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3912 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3913 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3914 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3915 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3916 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3917 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3918 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3919 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3920 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3921 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01003922 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
3923 HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
3924 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003925 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3926 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3927 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3928 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3929 {
3930 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3931 /* The multiple "Capture Source" controls confuse alsamixer
3932 * So call somewhat different..
3933 */
3934 /* .name = "Capture Source", */
3935 .name = "Input Source",
3936 .count = 2,
3937 .info = ad198x_mux_enum_info,
3938 .get = ad198x_mux_enum_get,
3939 .put = ad198x_mux_enum_put,
3940 },
3941 /* SPDIF controls */
3942 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3943 {
3944 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3945 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3946 /* identical with ad1983 */
3947 .info = ad1983_spdif_route_info,
3948 .get = ad1983_spdif_route_get,
3949 .put = ad1983_spdif_route_put,
3950 },
3951 { } /* end */
3952};
3953
3954/*
3955 * initialization verbs
3956 */
3957static struct hda_verb ad1884a_init_verbs[] = {
3958 /* DACs; unmute as default */
3959 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3960 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3961 /* Port-A (HP) mixer - route only from analog mixer */
3962 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3963 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3964 /* Port-A pin */
3965 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3966 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3967 /* Port-D (Line-out) mixer - route only from analog mixer */
3968 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3969 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3970 /* Port-D pin */
3971 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3972 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3973 /* Mono-out mixer - route only from analog mixer */
3974 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3975 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3976 /* Mono-out pin */
3977 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3978 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3979 /* Port-B (front mic) pin */
3980 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003981 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003982 /* Port-C (rear line-in) pin */
3983 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003984 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003985 /* Port-E (rear mic) pin */
3986 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3987 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3988 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3989 /* Port-F (CD) pin */
3990 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3991 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3992 /* Analog mixer; mute as default */
3993 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3994 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3995 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3996 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3997 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3998 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3999 /* Analog Mix output amp */
4000 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4001 /* capture sources */
4002 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
4003 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4004 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4005 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4006 /* SPDIF output amp */
4007 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4008 { } /* end */
4009};
4010
4011#ifdef CONFIG_SND_HDA_POWER_SAVE
4012static struct hda_amp_list ad1884a_loopbacks[] = {
4013 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4014 { 0x20, HDA_INPUT, 1 }, /* Mic */
4015 { 0x20, HDA_INPUT, 2 }, /* CD */
4016 { 0x20, HDA_INPUT, 4 }, /* Docking */
4017 { } /* end */
4018};
4019#endif
4020
4021/*
4022 * Laptop model
4023 *
4024 * Port A: Headphone jack
4025 * Port B: MIC jack
4026 * Port C: Internal MIC
4027 * Port D: Dock Line Out (if enabled)
4028 * Port E: Dock Line In (if enabled)
4029 * Port F: Internal speakers
4030 */
4031
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004032static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
4033 struct snd_ctl_elem_value *ucontrol)
4034{
4035 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4036 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
4037 int mute = (!ucontrol->value.integer.value[0] &&
4038 !ucontrol->value.integer.value[1]);
4039 /* toggle GPIO1 according to the mute state */
4040 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4041 mute ? 0x02 : 0x0);
4042 return ret;
4043}
Takashi Iwaic5059252008-02-16 09:43:56 +01004044
4045static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
4046 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004047 {
4048 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4049 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01004050 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004051 .info = snd_hda_mixer_amp_switch_info,
4052 .get = snd_hda_mixer_amp_switch_get,
4053 .put = ad1884a_mobile_master_sw_put,
4054 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4055 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004056 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4057 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4058 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4059 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4060 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4061 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4062 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4063 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4064 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004065 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
4066 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
4067 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01004068 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4069 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01004070 { } /* end */
4071};
4072
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004073static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
4074 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db172009-07-02 16:10:23 +02004075 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4076 {
4077 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4078 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01004079 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai099db172009-07-02 16:10:23 +02004080 .info = snd_hda_mixer_amp_switch_info,
4081 .get = snd_hda_mixer_amp_switch_get,
4082 .put = ad1884a_mobile_master_sw_put,
4083 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4084 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004085 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4086 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02004087 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
4088 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004089 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4090 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004091 { } /* end */
4092};
4093
Takashi Iwaic5059252008-02-16 09:43:56 +01004094/* mute internal speaker if HP is plugged */
4095static void ad1884a_hp_automute(struct hda_codec *codec)
4096{
4097 unsigned int present;
4098
Takashi Iwaid56757a2009-11-18 08:00:14 +01004099 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01004100 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
4101 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4102 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
4103 present ? 0x00 : 0x02);
4104}
4105
Takashi Iwai269ef192008-05-30 15:32:15 +02004106/* switch to external mic if plugged */
4107static void ad1884a_hp_automic(struct hda_codec *codec)
4108{
4109 unsigned int present;
4110
Takashi Iwaid56757a2009-11-18 08:00:14 +01004111 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02004112 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
4113 present ? 0 : 1);
4114}
4115
Takashi Iwaic5059252008-02-16 09:43:56 +01004116#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02004117#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01004118
4119/* unsolicited event for HP jack sensing */
4120static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4121{
Takashi Iwai269ef192008-05-30 15:32:15 +02004122 switch (res >> 26) {
4123 case AD1884A_HP_EVENT:
4124 ad1884a_hp_automute(codec);
4125 break;
4126 case AD1884A_MIC_EVENT:
4127 ad1884a_hp_automic(codec);
4128 break;
4129 }
Takashi Iwaic5059252008-02-16 09:43:56 +01004130}
4131
4132/* initialize jack-sensing, too */
4133static int ad1884a_hp_init(struct hda_codec *codec)
4134{
4135 ad198x_init(codec);
4136 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02004137 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01004138 return 0;
4139}
4140
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004141/* mute internal speaker if HP or docking HP is plugged */
4142static void ad1884a_laptop_automute(struct hda_codec *codec)
4143{
4144 unsigned int present;
4145
Takashi Iwaid56757a2009-11-18 08:00:14 +01004146 present = snd_hda_jack_detect(codec, 0x11);
4147 if (!present)
4148 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004149 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
4150 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4151 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
4152 present ? 0x00 : 0x02);
4153}
4154
4155/* switch to external mic if plugged */
4156static void ad1884a_laptop_automic(struct hda_codec *codec)
4157{
4158 unsigned int idx;
4159
Takashi Iwaid56757a2009-11-18 08:00:14 +01004160 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004161 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01004162 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004163 idx = 4;
4164 else
4165 idx = 1;
4166 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
4167}
4168
4169/* unsolicited event for HP jack sensing */
4170static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
4171 unsigned int res)
4172{
4173 switch (res >> 26) {
4174 case AD1884A_HP_EVENT:
4175 ad1884a_laptop_automute(codec);
4176 break;
4177 case AD1884A_MIC_EVENT:
4178 ad1884a_laptop_automic(codec);
4179 break;
4180 }
4181}
4182
4183/* initialize jack-sensing, too */
4184static int ad1884a_laptop_init(struct hda_codec *codec)
4185{
4186 ad198x_init(codec);
4187 ad1884a_laptop_automute(codec);
4188 ad1884a_laptop_automic(codec);
4189 return 0;
4190}
4191
Takashi Iwaic5059252008-02-16 09:43:56 +01004192/* additional verbs for laptop model */
4193static struct hda_verb ad1884a_laptop_verbs[] = {
4194 /* Port-A (HP) pin - always unmuted */
4195 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4196 /* Port-F (int speaker) mixer - route only from analog mixer */
4197 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4198 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08004199 /* Port-F (int speaker) pin */
4200 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01004201 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08004202 /* required for compaq 6530s/6531s speaker output */
4203 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004204 /* Port-C pin - internal mic-in */
4205 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4206 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4207 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02004208 /* Port-D (docking line-out) pin - default unmuted */
4209 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01004210 /* analog mix */
4211 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4212 /* unsolicited event for pin-sense */
4213 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004214 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004215 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004216 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02004217 /* allow to touch GPIO1 (for mute control) */
4218 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4219 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4220 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01004221 { } /* end */
4222};
4223
Takashi Iwai73156132009-04-23 08:24:48 +02004224static struct hda_verb ad1884a_mobile_verbs[] = {
4225 /* DACs; unmute as default */
4226 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4227 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4228 /* Port-A (HP) mixer - route only from analog mixer */
4229 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4230 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4231 /* Port-A pin */
4232 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4233 /* Port-A (HP) pin - always unmuted */
4234 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4235 /* Port-B (mic jack) pin */
4236 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4237 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4238 /* Port-C (int mic) pin */
4239 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4240 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4241 /* Port-F (int speaker) mixer - route only from analog mixer */
4242 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4243 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4244 /* Port-F pin */
4245 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4246 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4247 /* Analog mixer; mute as default */
4248 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4249 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4250 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4251 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4252 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4253 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4254 /* Analog Mix output amp */
4255 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4256 /* capture sources */
4257 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4258 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4259 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4260 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4261 /* unsolicited event for pin-sense */
4262 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4263 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db172009-07-02 16:10:23 +02004264 /* allow to touch GPIO1 (for mute control) */
4265 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4266 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4267 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02004268 { } /* end */
4269};
4270
Takashi Iwaic5059252008-02-16 09:43:56 +01004271/*
Takashi Iwaif0813742008-03-18 12:13:03 +01004272 * Thinkpad X300
4273 * 0x11 - HP
4274 * 0x12 - speaker
4275 * 0x14 - mic-in
4276 * 0x17 - built-in mic
4277 */
4278
4279static struct hda_verb ad1984a_thinkpad_verbs[] = {
4280 /* HP unmute */
4281 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4282 /* analog mix */
4283 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4284 /* turn on EAPD */
4285 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4286 /* unsolicited event for pin-sense */
4287 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4288 /* internal mic - dmic */
4289 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02004290 /* set magic COEFs for dmic */
4291 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4292 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01004293 { } /* end */
4294};
4295
4296static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
4297 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, 0x00, HDA_INPUT),
4302 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004303 HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
4304 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01004305 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4306 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4307 {
4308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4309 .name = "Capture Source",
4310 .info = ad198x_mux_enum_info,
4311 .get = ad198x_mux_enum_get,
4312 .put = ad198x_mux_enum_put,
4313 },
4314 { } /* end */
4315};
4316
4317static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4318 .num_items = 3,
4319 .items = {
4320 { "Mic", 0x0 },
4321 { "Internal Mic", 0x5 },
4322 { "Mix", 0x3 },
4323 },
4324};
4325
4326/* mute internal speaker if HP is plugged */
4327static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4328{
4329 unsigned int present;
4330
Takashi Iwaid56757a2009-11-18 08:00:14 +01004331 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004332 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4333 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4334}
4335
4336/* unsolicited event for HP jack sensing */
4337static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4338 unsigned int res)
4339{
4340 if ((res >> 26) != AD1884A_HP_EVENT)
4341 return;
4342 ad1984a_thinkpad_automute(codec);
4343}
4344
4345/* initialize jack-sensing, too */
4346static int ad1984a_thinkpad_init(struct hda_codec *codec)
4347{
4348 ad198x_init(codec);
4349 ad1984a_thinkpad_automute(codec);
4350 return 0;
4351}
4352
4353/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004354 * HP Touchsmart
4355 * port-A (0x11) - front hp-out
4356 * port-B (0x14) - unused
4357 * port-C (0x15) - unused
4358 * port-D (0x12) - rear line out
4359 * port-E (0x1c) - front mic-in
4360 * port-F (0x16) - Internal speakers
4361 * digital-mic (0x17) - Internal mic
4362 */
4363
4364static struct hda_verb ad1984a_touchsmart_verbs[] = {
4365 /* DACs; unmute as default */
4366 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4367 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4368 /* Port-A (HP) mixer - route only from analog mixer */
4369 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4370 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4371 /* Port-A pin */
4372 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4373 /* Port-A (HP) pin - always unmuted */
4374 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4375 /* Port-E (int speaker) mixer - route only from analog mixer */
4376 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4377 /* Port-E pin */
4378 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4379 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4380 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4381 /* Port-F (int speaker) mixer - route only from analog mixer */
4382 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4383 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4384 /* Port-F pin */
4385 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4386 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4387 /* Analog mixer; mute as default */
4388 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4389 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4390 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4391 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4392 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4394 /* Analog Mix output amp */
4395 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4396 /* capture sources */
4397 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4398 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4399 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4400 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4401 /* unsolicited event for pin-sense */
4402 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4403 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4404 /* allow to touch GPIO1 (for mute control) */
4405 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4406 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4407 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4408 /* internal mic - dmic */
4409 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4410 /* set magic COEFs for dmic */
4411 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4412 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4413 { } /* end */
4414};
4415
4416static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4417 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4418/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4419 {
4420 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01004421 .subdevice = HDA_SUBDEV_AMP_FLAG,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004422 .name = "Master Playback Switch",
4423 .info = snd_hda_mixer_amp_switch_info,
4424 .get = snd_hda_mixer_amp_switch_get,
4425 .put = ad1884a_mobile_master_sw_put,
4426 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4427 },
4428 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4429 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4430 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4431 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004432 HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
4433 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004434 { } /* end */
4435};
4436
4437/* switch to external mic if plugged */
4438static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4439{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004440 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004441 snd_hda_codec_write(codec, 0x0c, 0,
4442 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004443 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004444 snd_hda_codec_write(codec, 0x0c, 0,
4445 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004446}
4447
4448
4449/* unsolicited event for HP jack sensing */
4450static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4451 unsigned int res)
4452{
4453 switch (res >> 26) {
4454 case AD1884A_HP_EVENT:
4455 ad1884a_hp_automute(codec);
4456 break;
4457 case AD1884A_MIC_EVENT:
4458 ad1984a_touchsmart_automic(codec);
4459 break;
4460 }
4461}
4462
4463/* initialize jack-sensing, too */
4464static int ad1984a_touchsmart_init(struct hda_codec *codec)
4465{
4466 ad198x_init(codec);
4467 ad1884a_hp_automute(codec);
4468 ad1984a_touchsmart_automic(codec);
4469 return 0;
4470}
4471
4472
4473/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004474 */
4475
4476enum {
4477 AD1884A_DESKTOP,
4478 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004479 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004480 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004481 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004482 AD1884A_MODELS
4483};
4484
4485static const char *ad1884a_models[AD1884A_MODELS] = {
4486 [AD1884A_DESKTOP] = "desktop",
4487 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004488 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004489 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004490 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004491};
4492
4493static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4494 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004495 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004496 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004497 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004498 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004499 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4500 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004501 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004502 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004503 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004504 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004505};
4506
4507static int patch_ad1884a(struct hda_codec *codec)
4508{
4509 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004510 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004511
4512 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4513 if (spec == NULL)
4514 return -ENOMEM;
4515
Takashi Iwaic5059252008-02-16 09:43:56 +01004516 codec->spec = spec;
4517
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004518 err = snd_hda_attach_beep_device(codec, 0x10);
4519 if (err < 0) {
4520 ad198x_free(codec);
4521 return err;
4522 }
4523 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4524
Takashi Iwaic5059252008-02-16 09:43:56 +01004525 spec->multiout.max_channels = 2;
4526 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4527 spec->multiout.dac_nids = ad1884a_dac_nids;
4528 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4529 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4530 spec->adc_nids = ad1884a_adc_nids;
4531 spec->capsrc_nids = ad1884a_capsrc_nids;
4532 spec->input_mux = &ad1884a_capture_source;
4533 spec->num_mixers = 1;
4534 spec->mixers[0] = ad1884a_base_mixers;
4535 spec->num_init_verbs = 1;
4536 spec->init_verbs[0] = ad1884a_init_verbs;
4537 spec->spdif_route = 0;
4538#ifdef CONFIG_SND_HDA_POWER_SAVE
4539 spec->loopback.amplist = ad1884a_loopbacks;
4540#endif
4541 codec->patch_ops = ad198x_patch_ops;
4542
4543 /* override some parameters */
4544 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004545 ad1884a_models,
4546 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004547 switch (board_config) {
4548 case AD1884A_LAPTOP:
4549 spec->mixers[0] = ad1884a_laptop_mixers;
4550 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4551 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004552 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4553 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004554 /* set the upper-limit for mixer amp to 0dB for avoiding the
4555 * possible damage by overloading
4556 */
4557 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4558 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4559 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4560 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4561 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004562 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004563 case AD1884A_MOBILE:
4564 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004565 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004566 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004567 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4568 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004569 /* set the upper-limit for mixer amp to 0dB for avoiding the
4570 * possible damage by overloading
4571 */
4572 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4573 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4574 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4575 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4576 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004577 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004578 case AD1884A_THINKPAD:
4579 spec->mixers[0] = ad1984a_thinkpad_mixers;
4580 spec->init_verbs[spec->num_init_verbs++] =
4581 ad1984a_thinkpad_verbs;
4582 spec->multiout.dig_out_nid = 0;
4583 spec->input_mux = &ad1984a_thinkpad_capture_source;
4584 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4585 codec->patch_ops.init = ad1984a_thinkpad_init;
4586 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004587 case AD1984A_TOUCHSMART:
4588 spec->mixers[0] = ad1984a_touchsmart_mixers;
4589 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4590 spec->multiout.dig_out_nid = 0;
4591 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4592 codec->patch_ops.init = ad1984a_touchsmart_init;
4593 /* set the upper-limit for mixer amp to 0dB for avoiding the
4594 * possible damage by overloading
4595 */
4596 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4597 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4598 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4599 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4600 (1 << AC_AMPCAP_MUTE_SHIFT));
4601 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004602 }
4603
Takashi Iwai729d55b2009-12-25 22:49:01 +01004604 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02004605 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01004606
Takashi Iwaic5059252008-02-16 09:43:56 +01004607 return 0;
4608}
4609
4610
4611/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004612 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004613 *
4614 * port-A - front hp-out
4615 * port-B - front mic-in
4616 * port-C - rear line-in, shared surr-out (3stack)
4617 * port-D - rear line-out
4618 * port-E - rear mic-in, shared clfe-out (3stack)
4619 * port-F - rear surr-out (6stack)
4620 * port-G - rear clfe-out (6stack)
4621 */
4622
4623static hda_nid_t ad1882_dac_nids[3] = {
4624 0x04, 0x03, 0x05
4625};
4626
4627static hda_nid_t ad1882_adc_nids[2] = {
4628 0x08, 0x09,
4629};
4630
4631static hda_nid_t ad1882_capsrc_nids[2] = {
4632 0x0c, 0x0d,
4633};
4634
4635#define AD1882_SPDIF_OUT 0x02
4636
4637/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4638static struct hda_input_mux ad1882_capture_source = {
4639 .num_items = 5,
4640 .items = {
4641 { "Front Mic", 0x1 },
4642 { "Mic", 0x4 },
4643 { "Line", 0x2 },
4644 { "CD", 0x3 },
4645 { "Mix", 0x7 },
4646 },
4647};
4648
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004649/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4650static struct hda_input_mux ad1882a_capture_source = {
4651 .num_items = 5,
4652 .items = {
4653 { "Front Mic", 0x1 },
4654 { "Mic", 0x4},
4655 { "Line", 0x2 },
4656 { "Digital Mic", 0x06 },
4657 { "Mix", 0x7 },
4658 },
4659};
4660
Takashi Iwai0ac85512007-06-20 15:46:13 +02004661static struct snd_kcontrol_new ad1882_base_mixers[] = {
4662 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4663 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4664 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4665 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4666 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4667 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4668 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4669 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004670
David Henningsson5f99f862011-01-04 15:24:24 +01004671 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
4672 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
4673 HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
Takashi Iwai0ac85512007-06-20 15:46:13 +02004674 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4675 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4676 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4677 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4678 {
4679 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4680 /* The multiple "Capture Source" controls confuse alsamixer
4681 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004682 */
4683 /* .name = "Capture Source", */
4684 .name = "Input Source",
4685 .count = 2,
4686 .info = ad198x_mux_enum_info,
4687 .get = ad198x_mux_enum_get,
4688 .put = ad198x_mux_enum_put,
4689 },
4690 /* SPDIF controls */
4691 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4692 {
4693 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4694 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4695 /* identical with ad1983 */
4696 .info = ad1983_spdif_route_info,
4697 .get = ad1983_spdif_route_get,
4698 .put = ad1983_spdif_route_put,
4699 },
4700 { } /* end */
4701};
4702
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004703static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4704 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4705 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4706 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4707 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4708 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4709 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4710 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4711 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004712 { } /* end */
4713};
4714
4715static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4716 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4717 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4718 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4719 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4720 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4721 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4722 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4723 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
David Henningsson5f99f862011-01-04 15:24:24 +01004724 HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004725 { } /* end */
4726};
4727
Takashi Iwai0ac85512007-06-20 15:46:13 +02004728static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4729 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4730 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4731 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4732 {
4733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4734 .name = "Channel Mode",
4735 .info = ad198x_ch_mode_info,
4736 .get = ad198x_ch_mode_get,
4737 .put = ad198x_ch_mode_put,
4738 },
4739 { } /* end */
4740};
4741
4742static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4743 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4744 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4745 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4746 { } /* end */
4747};
4748
4749static struct hda_verb ad1882_ch2_init[] = {
4750 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4751 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4752 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4753 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4754 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4755 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4756 { } /* end */
4757};
4758
4759static struct hda_verb ad1882_ch4_init[] = {
4760 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4761 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4762 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4763 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4764 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4765 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4766 { } /* end */
4767};
4768
4769static struct hda_verb ad1882_ch6_init[] = {
4770 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4771 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4772 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4773 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4774 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4775 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4776 { } /* end */
4777};
4778
4779static struct hda_channel_mode ad1882_modes[3] = {
4780 { 2, ad1882_ch2_init },
4781 { 4, ad1882_ch4_init },
4782 { 6, ad1882_ch6_init },
4783};
4784
4785/*
4786 * initialization verbs
4787 */
4788static struct hda_verb ad1882_init_verbs[] = {
4789 /* DACs; mute as default */
4790 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4791 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4792 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4793 /* Port-A (HP) mixer */
4794 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4795 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4796 /* Port-A pin */
4797 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4798 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4799 /* HP selector - select DAC2 */
4800 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4801 /* Port-D (Line-out) mixer */
4802 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4803 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4804 /* Port-D pin */
4805 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4806 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4807 /* Mono-out mixer */
4808 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4809 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4810 /* Mono-out pin */
4811 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4812 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4813 /* Port-B (front mic) pin */
4814 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4815 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4816 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4817 /* Port-C (line-in) pin */
4818 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4819 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4820 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4821 /* Port-C mixer - mute as input */
4822 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4823 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4824 /* Port-E (mic-in) pin */
4825 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4826 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4827 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4828 /* Port-E mixer - mute as input */
4829 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4830 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4831 /* Port-F (surround) */
4832 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4833 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4834 /* Port-G (CLFE) */
4835 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4836 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4837 /* Analog mixer; mute as default */
4838 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4839 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4840 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4841 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4842 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4843 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4844 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4845 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4846 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4847 /* Analog Mix output amp */
4848 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4849 /* SPDIF output selector */
4850 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4851 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4852 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4853 { } /* end */
4854};
4855
Takashi Iwaicb53c622007-08-10 17:21:45 +02004856#ifdef CONFIG_SND_HDA_POWER_SAVE
4857static struct hda_amp_list ad1882_loopbacks[] = {
4858 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4859 { 0x20, HDA_INPUT, 1 }, /* Mic */
4860 { 0x20, HDA_INPUT, 4 }, /* Line */
4861 { 0x20, HDA_INPUT, 6 }, /* CD */
4862 { } /* end */
4863};
4864#endif
4865
Takashi Iwai0ac85512007-06-20 15:46:13 +02004866/* models */
4867enum {
4868 AD1882_3STACK,
4869 AD1882_6STACK,
4870 AD1882_MODELS
4871};
4872
4873static const char *ad1882_models[AD1986A_MODELS] = {
4874 [AD1882_3STACK] = "3stack",
4875 [AD1882_6STACK] = "6stack",
4876};
4877
4878
4879static int patch_ad1882(struct hda_codec *codec)
4880{
4881 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004882 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004883
4884 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4885 if (spec == NULL)
4886 return -ENOMEM;
4887
Takashi Iwai0ac85512007-06-20 15:46:13 +02004888 codec->spec = spec;
4889
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004890 err = snd_hda_attach_beep_device(codec, 0x10);
4891 if (err < 0) {
4892 ad198x_free(codec);
4893 return err;
4894 }
4895 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4896
Takashi Iwai0ac85512007-06-20 15:46:13 +02004897 spec->multiout.max_channels = 6;
4898 spec->multiout.num_dacs = 3;
4899 spec->multiout.dac_nids = ad1882_dac_nids;
4900 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4901 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4902 spec->adc_nids = ad1882_adc_nids;
4903 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004904 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004905 spec->input_mux = &ad1882_capture_source;
4906 else
4907 spec->input_mux = &ad1882a_capture_source;
4908 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004909 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004910 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004911 spec->mixers[1] = ad1882_loopback_mixers;
4912 else
4913 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004914 spec->num_init_verbs = 1;
4915 spec->init_verbs[0] = ad1882_init_verbs;
4916 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004917#ifdef CONFIG_SND_HDA_POWER_SAVE
4918 spec->loopback.amplist = ad1882_loopbacks;
4919#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004920 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004921
4922 codec->patch_ops = ad198x_patch_ops;
4923
4924 /* override some parameters */
4925 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4926 ad1882_models, NULL);
4927 switch (board_config) {
4928 default:
4929 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004930 spec->num_mixers = 3;
4931 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004932 spec->channel_mode = ad1882_modes;
4933 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4934 spec->need_dac_fix = 1;
4935 spec->multiout.max_channels = 2;
4936 spec->multiout.num_dacs = 1;
4937 break;
4938 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004939 spec->num_mixers = 3;
4940 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004941 break;
4942 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01004943
4944 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02004945 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01004946
Takashi Iwai0ac85512007-06-20 15:46:13 +02004947 return 0;
4948}
4949
4950
4951/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 * patch entries
4953 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004954static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004955 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004956 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004957 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004958 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004959 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4960 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004961 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4962 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004963 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004965 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004966 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004967 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004968 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4969 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 {} /* terminator */
4971};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004972
4973MODULE_ALIAS("snd-hda-codec-id:11d4*");
4974
4975MODULE_LICENSE("GPL");
4976MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4977
4978static struct hda_codec_preset_list analog_list = {
4979 .preset = snd_hda_preset_analog,
4980 .owner = THIS_MODULE,
4981};
4982
4983static int __init patch_analog_init(void)
4984{
4985 return snd_hda_add_codec_preset(&analog_list);
4986}
4987
4988static void __exit patch_analog_exit(void)
4989{
4990 snd_hda_delete_codec_preset(&analog_list);
4991}
4992
4993module_init(patch_analog_init)
4994module_exit(patch_analog_exit)