blob: 69a941c7b1588b7db4a9acd0fe79da65824c8944 [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
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020064 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010065
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020066 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010067
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +020070 struct snd_array kctls;
Takashi Iwaid32410b12005-11-24 16:06:23 +010071 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020072 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +020073
Takashi Iwai8ab78c72007-09-06 14:29:53 +020074 unsigned int jack_present :1;
Takashi Iwaiee6e3652009-12-08 17:23:33 +010075 unsigned int inv_jack_detect:1; /* inverted jack-detection */
76 unsigned int inv_eapd:1; /* inverted EAPD implementation */
Takashi Iwai8ab78c72007-09-06 14:29:53 +020077
Takashi Iwaicb53c622007-08-10 17:21:45 +020078#ifdef CONFIG_SND_HDA_POWER_SAVE
79 struct hda_loopback_check loopback;
80#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010081 /* for virtual master */
82 hda_nid_t vmaster_nid;
Takashi Iwai2134ea42008-01-10 16:53:55 +010083 const char **slave_vols;
84 const char **slave_sws;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020087/*
88 * input MUX handling (common part)
89 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010090static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020091{
92 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
93 struct ad198x_spec *spec = codec->spec;
94
95 return snd_hda_input_mux_info(spec->input_mux, uinfo);
96}
97
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010098static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
Takashi Iwai985be542005-11-02 18:26:49 +0100104 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200105 return 0;
106}
107
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100108static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200109{
110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
111 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100112 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200113
114 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100115 spec->capsrc_nids[adc_idx],
116 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200117}
118
119/*
120 * initialization (common callbacks)
121 */
122static int ad198x_init(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 int i;
126
127 for (i = 0; i < spec->num_init_verbs; i++)
128 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200129 return 0;
130}
131
Takashi Iwai2134ea42008-01-10 16:53:55 +0100132static const char *ad_slave_vols[] = {
133 "Front Playback Volume",
134 "Surround Playback Volume",
135 "Center Playback Volume",
136 "LFE Playback Volume",
137 "Side Playback Volume",
138 "Headphone Playback Volume",
139 "Mono Playback Volume",
Takashi Iwai628ed132008-01-25 11:56:57 +0100140 "Speaker Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100141 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100142 NULL
143};
144
145static const char *ad_slave_sws[] = {
146 "Front Playback Switch",
147 "Surround Playback Switch",
148 "Center Playback Switch",
149 "LFE Playback Switch",
150 "Side Playback Switch",
151 "Headphone Playback Switch",
152 "Mono Playback Switch",
Takashi Iwai628ed132008-01-25 11:56:57 +0100153 "Speaker Playback Switch",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100154 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100155 NULL
156};
157
Takashi Iwai603c4012008-07-30 15:01:44 +0200158static void ad198x_free_kctls(struct hda_codec *codec);
159
Takashi Iwai67d634c2009-11-16 15:35:59 +0100160#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100161/* additional beep mixers; the actual parameters are overwritten at build */
162static struct snd_kcontrol_new ad_beep_mixer[] = {
163 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +0200164 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100165 { } /* end */
166};
167
168#define set_beep_amp(spec, nid, idx, dir) \
169 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100170#else
171#define set_beep_amp(spec, nid, idx, dir) /* NOP */
172#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100173
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200174static int ad198x_build_controls(struct hda_codec *codec)
175{
176 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100177 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200178 int err;
179
Takashi Iwai985be542005-11-02 18:26:49 +0100180 for (i = 0; i < spec->num_mixers; i++) {
181 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
182 if (err < 0)
183 return err;
184 }
185 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200186 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100187 if (err < 0)
188 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100189 err = snd_hda_create_spdif_share_sw(codec,
190 &spec->multiout);
191 if (err < 0)
192 return err;
193 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100194 }
195 if (spec->dig_in_nid) {
196 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
197 if (err < 0)
198 return err;
199 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100200
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100201 /* create beep controls if needed */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100202#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100203 if (spec->beep_amp) {
204 struct snd_kcontrol_new *knew;
205 for (knew = ad_beep_mixer; knew->name; knew++) {
206 struct snd_kcontrol *kctl;
207 kctl = snd_ctl_new1(knew, codec);
208 if (!kctl)
209 return -ENOMEM;
210 kctl->private_value = spec->beep_amp;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100211 err = snd_hda_ctl_add(codec,
212 get_amp_nid_(spec->beep_amp),
213 kctl);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100214 if (err < 0)
215 return err;
216 }
217 }
Takashi Iwai67d634c2009-11-16 15:35:59 +0100218#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100219
Takashi Iwai2134ea42008-01-10 16:53:55 +0100220 /* if we have no master control, let's create it */
221 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100222 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100223 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100224 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100225 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100226 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100227 (spec->slave_vols ?
228 spec->slave_vols : ad_slave_vols));
229 if (err < 0)
230 return err;
231 }
232 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
233 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
234 NULL,
235 (spec->slave_sws ?
236 spec->slave_sws : ad_slave_sws));
237 if (err < 0)
238 return err;
239 }
240
Takashi Iwai603c4012008-07-30 15:01:44 +0200241 ad198x_free_kctls(codec); /* no longer needed */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200242 return 0;
243}
244
Takashi Iwaicb53c622007-08-10 17:21:45 +0200245#ifdef CONFIG_SND_HDA_POWER_SAVE
246static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
247{
248 struct ad198x_spec *spec = codec->spec;
249 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
250}
251#endif
252
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200253/*
254 * Analog playback callbacks
255 */
256static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
257 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100258 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200259{
260 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100261 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
262 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200263}
264
265static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
266 struct hda_codec *codec,
267 unsigned int stream_tag,
268 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100269 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200270{
271 struct ad198x_spec *spec = codec->spec;
272 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
273 format, substream);
274}
275
276static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
277 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100278 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200279{
280 struct ad198x_spec *spec = codec->spec;
281 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
282}
283
284/*
285 * Digital out
286 */
287static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
288 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100289 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200290{
291 struct ad198x_spec *spec = codec->spec;
292 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
293}
294
295static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
296 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100297 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200298{
299 struct ad198x_spec *spec = codec->spec;
300 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
301}
302
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200303static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
304 struct hda_codec *codec,
305 unsigned int stream_tag,
306 unsigned int format,
307 struct snd_pcm_substream *substream)
308{
309 struct ad198x_spec *spec = codec->spec;
310 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
311 format, substream);
312}
313
Takashi Iwai9411e212009-02-13 11:32:28 +0100314static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
315 struct hda_codec *codec,
316 struct snd_pcm_substream *substream)
317{
318 struct ad198x_spec *spec = codec->spec;
319 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
320}
321
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200322/*
323 * Analog capture
324 */
325static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
326 struct hda_codec *codec,
327 unsigned int stream_tag,
328 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100329 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200330{
331 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100332 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
333 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200334 return 0;
335}
336
337static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
338 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100339 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200340{
341 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100342 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200343 return 0;
344}
345
346
347/*
348 */
349static struct hda_pcm_stream ad198x_pcm_analog_playback = {
350 .substreams = 1,
351 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100352 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200353 .nid = 0, /* fill later */
354 .ops = {
355 .open = ad198x_playback_pcm_open,
356 .prepare = ad198x_playback_pcm_prepare,
357 .cleanup = ad198x_playback_pcm_cleanup
358 },
359};
360
361static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100362 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200363 .channels_min = 2,
364 .channels_max = 2,
365 .nid = 0, /* fill later */
366 .ops = {
367 .prepare = ad198x_capture_pcm_prepare,
368 .cleanup = ad198x_capture_pcm_cleanup
369 },
370};
371
372static struct hda_pcm_stream ad198x_pcm_digital_playback = {
373 .substreams = 1,
374 .channels_min = 2,
375 .channels_max = 2,
376 .nid = 0, /* fill later */
377 .ops = {
378 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200379 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100380 .prepare = ad198x_dig_playback_pcm_prepare,
381 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200382 },
383};
384
Takashi Iwai985be542005-11-02 18:26:49 +0100385static struct hda_pcm_stream ad198x_pcm_digital_capture = {
386 .substreams = 1,
387 .channels_min = 2,
388 .channels_max = 2,
389 /* NID is set in alc_build_pcms */
390};
391
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200392static int ad198x_build_pcms(struct hda_codec *codec)
393{
394 struct ad198x_spec *spec = codec->spec;
395 struct hda_pcm *info = spec->pcm_rec;
396
397 codec->num_pcms = 1;
398 codec->pcm_info = info;
399
400 info->name = "AD198x Analog";
401 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
402 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
403 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
404 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100405 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
406 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200407
408 if (spec->multiout.dig_out_nid) {
409 info++;
410 codec->num_pcms++;
411 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100412 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200413 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
414 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100415 if (spec->dig_in_nid) {
416 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
417 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
418 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200419 }
420
421 return 0;
422}
423
Takashi Iwai603c4012008-07-30 15:01:44 +0200424static void ad198x_free_kctls(struct hda_codec *codec)
425{
426 struct ad198x_spec *spec = codec->spec;
427
428 if (spec->kctls.list) {
429 struct snd_kcontrol_new *kctl = spec->kctls.list;
430 int i;
431 for (i = 0; i < spec->kctls.used; i++)
432 kfree(kctl[i].name);
433 }
434 snd_array_free(&spec->kctls);
435}
436
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200437static void ad198x_free(struct hda_codec *codec)
438{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100439 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100440
Takashi Iwai603c4012008-07-30 15:01:44 +0200441 if (!spec)
442 return;
443
444 ad198x_free_kctls(codec);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100445 kfree(spec);
446 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200447}
448
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200449static struct hda_codec_ops ad198x_patch_ops = {
450 .build_controls = ad198x_build_controls,
451 .build_pcms = ad198x_build_pcms,
452 .init = ad198x_init,
453 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200454#ifdef CONFIG_SND_HDA_POWER_SAVE
455 .check_power_status = ad198x_check_power_status,
456#endif
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200457};
458
459
460/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100461 * EAPD control
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100462 * the private value = nid
Takashi Iwai18a815d2006-03-01 19:54:39 +0100463 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200464#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100465
466static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
467 struct snd_ctl_elem_value *ucontrol)
468{
469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
470 struct ad198x_spec *spec = codec->spec;
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100471 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100472 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
473 else
474 ucontrol->value.integer.value[0] = spec->cur_eapd;
475 return 0;
476}
477
478static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
479 struct snd_ctl_elem_value *ucontrol)
480{
481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
482 struct ad198x_spec *spec = codec->spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100483 hda_nid_t nid = kcontrol->private_value & 0xff;
484 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100485 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100486 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100487 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200488 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100489 return 0;
490 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200491 snd_hda_codec_write_cache(codec, nid,
492 0, AC_VERB_SET_EAPD_BTLENABLE,
493 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100494 return 1;
495}
496
Takashi Iwai9230d212006-03-13 13:49:49 +0100497static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_info *uinfo);
499static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol);
501static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
502 struct snd_ctl_elem_value *ucontrol);
503
504
Takashi Iwai18a815d2006-03-01 19:54:39 +0100505/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200506 * AD1986A specific
507 */
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#define AD1986A_SPDIF_OUT 0x02
510#define AD1986A_FRONT_DAC 0x03
511#define AD1986A_SURR_DAC 0x04
512#define AD1986A_CLFE_DAC 0x05
513#define AD1986A_ADC 0x06
514
515static hda_nid_t ad1986a_dac_nids[3] = {
516 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
517};
Takashi Iwai985be542005-11-02 18:26:49 +0100518static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100519static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521static struct hda_input_mux ad1986a_capture_source = {
522 .num_items = 7,
523 .items = {
524 { "Mic", 0x0 },
525 { "CD", 0x1 },
526 { "Aux", 0x3 },
527 { "Line", 0x4 },
528 { "Mix", 0x5 },
529 { "Mono", 0x6 },
530 { "Phone", 0x7 },
531 },
532};
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Takashi Iwai532d5382007-07-27 19:02:40 +0200535static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
536 .ops = &snd_hda_bind_vol,
537 .values = {
538 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
539 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
540 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
541 0
542 },
543};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Takashi Iwai532d5382007-07-27 19:02:40 +0200545static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
546 .ops = &snd_hda_bind_sw,
547 .values = {
548 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
549 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
550 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
551 0
552 },
553};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 * mixers
557 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100558static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200559 /*
560 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
561 */
562 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
563 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
565 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
566 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
570 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
573 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
574 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
575 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
576 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
577 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
578 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
579 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
580 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
581 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100582 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
584 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
585 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
586 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
587 {
588 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
589 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200590 .info = ad198x_mux_enum_info,
591 .get = ad198x_mux_enum_get,
592 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
595 { } /* end */
596};
597
Takashi Iwai9230d212006-03-13 13:49:49 +0100598/* additional mixers for 3stack mode */
599static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
600 {
601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
602 .name = "Channel Mode",
603 .info = ad198x_ch_mode_info,
604 .get = ad198x_ch_mode_get,
605 .put = ad198x_ch_mode_put,
606 },
607 { } /* end */
608};
609
610/* laptop model - 2ch only */
611static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
612
Takashi Iwai20a45e82007-08-15 22:20:45 +0200613/* master controls both pins 0x1a and 0x1b */
614static struct hda_bind_ctls ad1986a_laptop_master_vol = {
615 .ops = &snd_hda_bind_vol,
616 .values = {
617 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
618 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
619 0,
620 },
621};
622
623static struct hda_bind_ctls ad1986a_laptop_master_sw = {
624 .ops = &snd_hda_bind_sw,
625 .values = {
626 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
627 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
628 0,
629 },
630};
631
Takashi Iwai9230d212006-03-13 13:49:49 +0100632static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
633 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
634 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200635 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
636 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100637 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
638 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
639 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
640 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
641 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
642 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
643 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
644 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100645 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100646 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100647 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
648 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
649 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
650 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
651 {
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
653 .name = "Capture Source",
654 .info = ad198x_mux_enum_info,
655 .get = ad198x_mux_enum_get,
656 .put = ad198x_mux_enum_put,
657 },
658 { } /* end */
659};
660
Takashi Iwai825aa972006-03-17 10:50:49 +0100661/* laptop-eapd model - 2ch only */
662
Takashi Iwai825aa972006-03-17 10:50:49 +0100663static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
664 .num_items = 3,
665 .items = {
666 { "Mic", 0x0 },
667 { "Internal Mic", 0x4 },
668 { "Mix", 0x5 },
669 },
670};
671
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100672static struct hda_input_mux ad1986a_automic_capture_source = {
673 .num_items = 2,
674 .items = {
675 { "Mic", 0x0 },
676 { "Mix", 0x5 },
677 },
678};
679
Takashi Iwai16d11a82009-06-24 14:07:53 +0200680static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200681 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
682 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200683 { } /* end */
684};
685
686static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100687 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
688 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100689 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
690 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
691 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
692 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
693 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
694 {
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "Capture Source",
697 .info = ad198x_mux_enum_info,
698 .get = ad198x_mux_enum_get,
699 .put = ad198x_mux_enum_put,
700 },
701 {
702 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
703 .name = "External Amplifier",
704 .info = ad198x_eapd_info,
705 .get = ad198x_eapd_get,
706 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100707 .private_value = 0x1b, /* port-D */
Takashi Iwai1725b822008-11-21 02:25:48 +0100708 },
709 { } /* end */
710};
711
Takashi Iwai16d11a82009-06-24 14:07:53 +0200712static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
713 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
714 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100715 { } /* end */
716};
717
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100718/* re-connect the mic boost input according to the jack sensing */
719static void ad1986a_automic(struct hda_codec *codec)
720{
721 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100722 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100723 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
724 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100725 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100726}
727
728#define AD1986A_MIC_EVENT 0x36
729
730static void ad1986a_automic_unsol_event(struct hda_codec *codec,
731 unsigned int res)
732{
733 if ((res >> 26) != AD1986A_MIC_EVENT)
734 return;
735 ad1986a_automic(codec);
736}
737
738static int ad1986a_automic_init(struct hda_codec *codec)
739{
740 ad198x_init(codec);
741 ad1986a_automic(codec);
742 return 0;
743}
744
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200745/* laptop-automute - 2ch only */
746
747static void ad1986a_update_hp(struct hda_codec *codec)
748{
749 struct ad198x_spec *spec = codec->spec;
750 unsigned int mute;
751
752 if (spec->jack_present)
753 mute = HDA_AMP_MUTE; /* mute internal speaker */
754 else
755 /* unmute internal speaker if necessary */
756 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
757 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
758 HDA_AMP_MUTE, mute);
759}
760
761static void ad1986a_hp_automute(struct hda_codec *codec)
762{
763 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200764
Takashi Iwaid56757a2009-11-18 08:00:14 +0100765 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200766 if (spec->inv_jack_detect)
767 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200768 ad1986a_update_hp(codec);
769}
770
771#define AD1986A_HP_EVENT 0x37
772
773static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
774{
775 if ((res >> 26) != AD1986A_HP_EVENT)
776 return;
777 ad1986a_hp_automute(codec);
778}
779
780static int ad1986a_hp_init(struct hda_codec *codec)
781{
782 ad198x_init(codec);
783 ad1986a_hp_automute(codec);
784 return 0;
785}
786
787/* bind hp and internal speaker mute (with plug check) */
788static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
789 struct snd_ctl_elem_value *ucontrol)
790{
791 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
792 long *valp = ucontrol->value.integer.value;
793 int change;
794
795 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
796 HDA_AMP_MUTE,
797 valp[0] ? 0 : HDA_AMP_MUTE);
798 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
799 HDA_AMP_MUTE,
800 valp[1] ? 0 : HDA_AMP_MUTE);
801 if (change)
802 ad1986a_update_hp(codec);
803 return change;
804}
805
Takashi Iwai16d11a82009-06-24 14:07:53 +0200806static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200807 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
808 {
809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
810 .name = "Master Playback Switch",
811 .info = snd_hda_mixer_amp_switch_info,
812 .get = snd_hda_mixer_amp_switch_get,
813 .put = ad1986a_hp_master_sw_put,
814 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
815 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200816 { } /* end */
817};
818
Takashi Iwai16d11a82009-06-24 14:07:53 +0200819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/*
821 * initialization verbs
822 */
823static struct hda_verb ad1986a_init_verbs[] = {
824 /* Front, Surround, CLFE DAC; mute as default */
825 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
826 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
827 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
828 /* Downmix - off */
829 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
830 /* HP, Line-Out, Surround, CLFE selectors */
831 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
832 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
833 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
834 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
835 /* Mono selector */
836 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
837 /* Mic selector: Mic 1/2 pin */
838 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
839 /* Line-in selector: Line-in */
840 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
841 /* Mic 1/2 swap */
842 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
843 /* Record selector: mic */
844 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
845 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
846 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
847 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
848 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
851 /* PC beep */
852 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
853 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
854 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
855 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
856 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200859 /* HP Pin */
860 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
861 /* Front, Surround, CLFE Pins */
862 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
863 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
864 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
865 /* Mono Pin */
866 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
867 /* Mic Pin */
868 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
869 /* Line, Aux, CD, Beep-In Pin */
870 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
871 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
872 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
873 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
874 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 { } /* end */
876};
877
Takashi Iwai9230d212006-03-13 13:49:49 +0100878static struct hda_verb ad1986a_ch2_init[] = {
879 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200880 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
881 /* Line-in selectors */
882 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100883 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200884 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
885 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
886 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100887 { } /* end */
888};
889
890static struct hda_verb ad1986a_ch4_init[] = {
891 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200892 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
893 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100894 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200895 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
896 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100897 { } /* end */
898};
899
900static struct hda_verb ad1986a_ch6_init[] = {
901 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200902 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
903 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100904 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200905 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
906 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100907 { } /* end */
908};
909
910static struct hda_channel_mode ad1986a_modes[3] = {
911 { 2, ad1986a_ch2_init },
912 { 4, ad1986a_ch4_init },
913 { 6, ad1986a_ch6_init },
914};
915
Takashi Iwai825aa972006-03-17 10:50:49 +0100916/* eapd initialization */
917static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100918 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +0100919 {}
920};
921
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100922static struct hda_verb ad1986a_automic_verbs[] = {
923 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
924 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
925 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
926 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
927 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
928 {}
929};
930
Tobin Davisf36090f2007-01-08 11:07:12 +0100931/* Ultra initialization */
932static struct hda_verb ad1986a_ultra_init[] = {
933 /* eapd initialization */
934 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
935 /* CLFE -> Mic in */
936 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
937 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
938 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
939 { } /* end */
940};
941
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200942/* pin sensing on HP jack */
943static struct hda_verb ad1986a_hp_init_verbs[] = {
944 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
945 {}
946};
947
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200948static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
949 unsigned int res)
950{
951 switch (res >> 26) {
952 case AD1986A_HP_EVENT:
953 ad1986a_hp_automute(codec);
954 break;
955 case AD1986A_MIC_EVENT:
956 ad1986a_automic(codec);
957 break;
958 }
959}
960
961static int ad1986a_samsung_p50_init(struct hda_codec *codec)
962{
963 ad198x_init(codec);
964 ad1986a_hp_automute(codec);
965 ad1986a_automic(codec);
966 return 0;
967}
968
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200969
Takashi Iwai9230d212006-03-13 13:49:49 +0100970/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100971enum {
972 AD1986A_6STACK,
973 AD1986A_3STACK,
974 AD1986A_LAPTOP,
975 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200976 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +0100977 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +0100978 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200979 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100980 AD1986A_MODELS
981};
Takashi Iwai9230d212006-03-13 13:49:49 +0100982
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100983static const char *ad1986a_models[AD1986A_MODELS] = {
984 [AD1986A_6STACK] = "6stack",
985 [AD1986A_3STACK] = "3stack",
986 [AD1986A_LAPTOP] = "laptop",
987 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200988 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +0100989 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +0100990 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200991 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100992};
993
994static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
995 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100996 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100997 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100998 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100999 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1000 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1001 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1002 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001003 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001004 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001005 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1006 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1007 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1008 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1009 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001010 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Takashi Iwai7db756f2007-12-24 14:36:09 +01001011 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
Tobin Davis18768992007-03-12 22:20:51 +01001012 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001013 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001014 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001015 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001016 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001017 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001018 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001019 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001020 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001021 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001022 {}
1023};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Takashi Iwaicb53c622007-08-10 17:21:45 +02001025#ifdef CONFIG_SND_HDA_POWER_SAVE
1026static struct hda_amp_list ad1986a_loopbacks[] = {
1027 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1028 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1029 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1030 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1031 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1032 { } /* end */
1033};
1034#endif
1035
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001036static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1037{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001038 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001039 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1040}
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042static int patch_ad1986a(struct hda_codec *codec)
1043{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001044 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001045 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001047 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (spec == NULL)
1049 return -ENOMEM;
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 codec->spec = spec;
1052
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001053 err = snd_hda_attach_beep_device(codec, 0x19);
1054 if (err < 0) {
1055 ad198x_free(codec);
1056 return err;
1057 }
1058 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 spec->multiout.max_channels = 6;
1061 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1062 spec->multiout.dac_nids = ad1986a_dac_nids;
1063 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001064 spec->num_adc_nids = 1;
1065 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001066 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001067 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001068 spec->num_mixers = 1;
1069 spec->mixers[0] = ad1986a_mixers;
1070 spec->num_init_verbs = 1;
1071 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001072#ifdef CONFIG_SND_HDA_POWER_SAVE
1073 spec->loopback.amplist = ad1986a_loopbacks;
1074#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001075 spec->vmaster_nid = 0x1b;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01001076 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001078 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Takashi Iwai9230d212006-03-13 13:49:49 +01001080 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001081 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1082 ad1986a_models,
1083 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001084 switch (board_config) {
1085 case AD1986A_3STACK:
1086 spec->num_mixers = 2;
1087 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001088 spec->num_init_verbs = 2;
1089 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001090 spec->channel_mode = ad1986a_modes;
1091 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001092 spec->need_dac_fix = 1;
1093 spec->multiout.max_channels = 2;
1094 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001095 break;
1096 case AD1986A_LAPTOP:
1097 spec->mixers[0] = ad1986a_laptop_mixers;
1098 spec->multiout.max_channels = 2;
1099 spec->multiout.num_dacs = 1;
1100 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1101 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001102 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001103 spec->num_mixers = 3;
1104 spec->mixers[0] = ad1986a_laptop_master_mixers;
1105 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1106 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001107 spec->num_init_verbs = 2;
1108 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1109 spec->multiout.max_channels = 2;
1110 spec->multiout.num_dacs = 1;
1111 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1112 if (!is_jack_available(codec, 0x25))
1113 spec->multiout.dig_out_nid = 0;
1114 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1115 break;
1116 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001117 spec->num_mixers = 2;
1118 spec->mixers[0] = ad1986a_laptop_master_mixers;
1119 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001120 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001121 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001122 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001123 spec->multiout.max_channels = 2;
1124 spec->multiout.num_dacs = 1;
1125 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001126 if (!is_jack_available(codec, 0x25))
1127 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001128 spec->input_mux = &ad1986a_automic_capture_source;
1129 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1130 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001131 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001132 case AD1986A_SAMSUNG_P50:
1133 spec->num_mixers = 2;
1134 spec->mixers[0] = ad1986a_automute_master_mixers;
1135 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1136 spec->num_init_verbs = 4;
1137 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1138 spec->init_verbs[2] = ad1986a_automic_verbs;
1139 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1140 spec->multiout.max_channels = 2;
1141 spec->multiout.num_dacs = 1;
1142 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1143 if (!is_jack_available(codec, 0x25))
1144 spec->multiout.dig_out_nid = 0;
1145 spec->input_mux = &ad1986a_automic_capture_source;
1146 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1147 codec->patch_ops.init = ad1986a_samsung_p50_init;
1148 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001149 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001150 spec->num_mixers = 3;
1151 spec->mixers[0] = ad1986a_automute_master_mixers;
1152 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1153 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001154 spec->num_init_verbs = 3;
1155 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1156 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1157 spec->multiout.max_channels = 2;
1158 spec->multiout.num_dacs = 1;
1159 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001160 if (!is_jack_available(codec, 0x25))
1161 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001162 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1163 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1164 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001165 /* Lenovo N100 seems to report the reversed bit
1166 * for HP jack-sensing
1167 */
1168 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001169 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001170 case AD1986A_ULTRA:
1171 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1172 spec->num_init_verbs = 2;
1173 spec->init_verbs[1] = ad1986a_ultra_init;
1174 spec->multiout.max_channels = 2;
1175 spec->multiout.num_dacs = 1;
1176 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1177 spec->multiout.dig_out_nid = 0;
1178 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001179 }
1180
Takashi Iwaid29240c2007-10-26 12:35:56 +02001181 /* AD1986A has a hardware problem that it can't share a stream
1182 * with multiple output pins. The copy of front to surrounds
1183 * causes noisy or silent outputs at a certain timing, e.g.
1184 * changing the volume.
1185 * So, let's disable the shared stream.
1186 */
1187 spec->multiout.no_share_stream = 1;
1188
Takashi Iwai729d55b2009-12-25 22:49:01 +01001189 codec->no_trigger_sense = 1;
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 return 0;
1192}
1193
1194/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001195 * AD1983 specific
1196 */
1197
1198#define AD1983_SPDIF_OUT 0x02
1199#define AD1983_DAC 0x03
1200#define AD1983_ADC 0x04
1201
1202static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001203static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001204static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001205
1206static struct hda_input_mux ad1983_capture_source = {
1207 .num_items = 4,
1208 .items = {
1209 { "Mic", 0x0 },
1210 { "Line", 0x1 },
1211 { "Mix", 0x2 },
1212 { "Mix Mono", 0x3 },
1213 },
1214};
1215
1216/*
1217 * SPDIF playback route
1218 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001219static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001220{
1221 static char *texts[] = { "PCM", "ADC" };
1222
1223 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1224 uinfo->count = 1;
1225 uinfo->value.enumerated.items = 2;
1226 if (uinfo->value.enumerated.item > 1)
1227 uinfo->value.enumerated.item = 1;
1228 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1229 return 0;
1230}
1231
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001232static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001233{
1234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1235 struct ad198x_spec *spec = codec->spec;
1236
1237 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1238 return 0;
1239}
1240
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001241static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001242{
1243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1244 struct ad198x_spec *spec = codec->spec;
1245
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001246 if (ucontrol->value.enumerated.item[0] > 1)
1247 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001248 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1249 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001250 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1251 AC_VERB_SET_CONNECT_SEL,
1252 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001253 return 1;
1254 }
1255 return 0;
1256}
1257
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001258static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001259 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1261 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1262 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1269 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001271 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1274 {
1275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1276 .name = "Capture Source",
1277 .info = ad198x_mux_enum_info,
1278 .get = ad198x_mux_enum_get,
1279 .put = ad198x_mux_enum_put,
1280 },
1281 {
1282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001283 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001284 .info = ad1983_spdif_route_info,
1285 .get = ad1983_spdif_route_get,
1286 .put = ad1983_spdif_route_put,
1287 },
1288 { } /* end */
1289};
1290
1291static struct hda_verb ad1983_init_verbs[] = {
1292 /* Front, HP, Mono; mute as default */
1293 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1294 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1295 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1296 /* Beep, PCM, Mic, Line-In: mute */
1297 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1298 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1299 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1300 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1301 /* Front, HP selectors; from Mix */
1302 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1303 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1304 /* Mono selector; from Mix */
1305 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1306 /* Mic selector; Mic */
1307 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1308 /* Line-in selector: Line-in */
1309 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1310 /* Mic boost: 0dB */
1311 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1312 /* Record selector: mic */
1313 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1314 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1315 /* SPDIF route: PCM */
1316 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1317 /* Front Pin */
1318 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1319 /* HP Pin */
1320 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1321 /* Mono Pin */
1322 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1323 /* Mic Pin */
1324 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1325 /* Line Pin */
1326 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1327 { } /* end */
1328};
1329
Takashi Iwaicb53c622007-08-10 17:21:45 +02001330#ifdef CONFIG_SND_HDA_POWER_SAVE
1331static struct hda_amp_list ad1983_loopbacks[] = {
1332 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1333 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1334 { } /* end */
1335};
1336#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001337
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001338static int patch_ad1983(struct hda_codec *codec)
1339{
1340 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001341 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001342
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001344 if (spec == NULL)
1345 return -ENOMEM;
1346
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001347 codec->spec = spec;
1348
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001349 err = snd_hda_attach_beep_device(codec, 0x10);
1350 if (err < 0) {
1351 ad198x_free(codec);
1352 return err;
1353 }
1354 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1355
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001356 spec->multiout.max_channels = 2;
1357 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1358 spec->multiout.dac_nids = ad1983_dac_nids;
1359 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001360 spec->num_adc_nids = 1;
1361 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001362 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001363 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001364 spec->num_mixers = 1;
1365 spec->mixers[0] = ad1983_mixers;
1366 spec->num_init_verbs = 1;
1367 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001368 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001369#ifdef CONFIG_SND_HDA_POWER_SAVE
1370 spec->loopback.amplist = ad1983_loopbacks;
1371#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001372 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001373
1374 codec->patch_ops = ad198x_patch_ops;
1375
Takashi Iwai729d55b2009-12-25 22:49:01 +01001376 codec->no_trigger_sense = 1;
1377
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001378 return 0;
1379}
1380
1381
1382/*
1383 * AD1981 HD specific
1384 */
1385
1386#define AD1981_SPDIF_OUT 0x02
1387#define AD1981_DAC 0x03
1388#define AD1981_ADC 0x04
1389
1390static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001391static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001392static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001393
1394/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1395static struct hda_input_mux ad1981_capture_source = {
1396 .num_items = 7,
1397 .items = {
1398 { "Front Mic", 0x0 },
1399 { "Line", 0x1 },
1400 { "Mix", 0x2 },
1401 { "Mix Mono", 0x3 },
1402 { "CD", 0x4 },
1403 { "Mic", 0x6 },
1404 { "Aux", 0x7 },
1405 },
1406};
1407
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001408static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001409 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1425 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001427 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1428 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1429 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1431 {
1432 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1433 .name = "Capture Source",
1434 .info = ad198x_mux_enum_info,
1435 .get = ad198x_mux_enum_get,
1436 .put = ad198x_mux_enum_put,
1437 },
1438 /* identical with AD1983 */
1439 {
1440 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001441 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001442 .info = ad1983_spdif_route_info,
1443 .get = ad1983_spdif_route_get,
1444 .put = ad1983_spdif_route_put,
1445 },
1446 { } /* end */
1447};
1448
1449static struct hda_verb ad1981_init_verbs[] = {
1450 /* Front, HP, Mono; mute as default */
1451 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1452 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1453 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1455 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1458 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1459 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1460 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1461 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1462 /* Front, HP selectors; from Mix */
1463 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1464 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1465 /* Mono selector; from Mix */
1466 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1467 /* Mic Mixer; select Front Mic */
1468 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1469 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1470 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001471 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1472 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001473 /* Record selector: Front mic */
1474 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1475 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1476 /* SPDIF route: PCM */
1477 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1478 /* Front Pin */
1479 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1480 /* HP Pin */
1481 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1482 /* Mono Pin */
1483 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1484 /* Front & Rear Mic Pins */
1485 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1486 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1487 /* Line Pin */
1488 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1489 /* Digital Beep */
1490 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1491 /* Line-Out as Input: disabled */
1492 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1493 { } /* end */
1494};
1495
Takashi Iwaicb53c622007-08-10 17:21:45 +02001496#ifdef CONFIG_SND_HDA_POWER_SAVE
1497static struct hda_amp_list ad1981_loopbacks[] = {
1498 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1499 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1500 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1501 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1502 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1503 { } /* end */
1504};
1505#endif
1506
Takashi Iwai18a815d2006-03-01 19:54:39 +01001507/*
1508 * Patch for HP nx6320
1509 *
Tobin Davis18768992007-03-12 22:20:51 +01001510 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001511 * speaker output enabled _and_ mute-LED off.
1512 */
1513
1514#define AD1981_HP_EVENT 0x37
1515#define AD1981_MIC_EVENT 0x38
1516
1517static struct hda_verb ad1981_hp_init_verbs[] = {
1518 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1519 /* pin sensing on HP and Mic jacks */
1520 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1521 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1522 {}
1523};
1524
1525/* turn on/off EAPD (+ mute HP) as a master switch */
1526static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1527 struct snd_ctl_elem_value *ucontrol)
1528{
1529 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1530 struct ad198x_spec *spec = codec->spec;
1531
1532 if (! ad198x_eapd_put(kcontrol, ucontrol))
1533 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001534 /* change speaker pin appropriately */
1535 snd_hda_codec_write(codec, 0x05, 0,
1536 AC_VERB_SET_PIN_WIDGET_CONTROL,
1537 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001538 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001539 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1540 HDA_AMP_MUTE,
1541 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001542 return 1;
1543}
1544
1545/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001546static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1547 .ops = &snd_hda_bind_vol,
1548 .values = {
1549 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1550 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1551 0
1552 },
1553};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001554
1555/* mute internal speaker if HP is plugged */
1556static void ad1981_hp_automute(struct hda_codec *codec)
1557{
1558 unsigned int present;
1559
Takashi Iwaid56757a2009-11-18 08:00:14 +01001560 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001561 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1562 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001563}
1564
1565/* toggle input of built-in and mic jack appropriately */
1566static void ad1981_hp_automic(struct hda_codec *codec)
1567{
1568 static struct hda_verb mic_jack_on[] = {
1569 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1570 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1571 {}
1572 };
1573 static struct hda_verb mic_jack_off[] = {
1574 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1575 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1576 {}
1577 };
1578 unsigned int present;
1579
Takashi Iwaid56757a2009-11-18 08:00:14 +01001580 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001581 if (present)
1582 snd_hda_sequence_write(codec, mic_jack_on);
1583 else
1584 snd_hda_sequence_write(codec, mic_jack_off);
1585}
1586
1587/* unsolicited event for HP jack sensing */
1588static void ad1981_hp_unsol_event(struct hda_codec *codec,
1589 unsigned int res)
1590{
1591 res >>= 26;
1592 switch (res) {
1593 case AD1981_HP_EVENT:
1594 ad1981_hp_automute(codec);
1595 break;
1596 case AD1981_MIC_EVENT:
1597 ad1981_hp_automic(codec);
1598 break;
1599 }
1600}
1601
1602static struct hda_input_mux ad1981_hp_capture_source = {
1603 .num_items = 3,
1604 .items = {
1605 { "Mic", 0x0 },
1606 { "Docking-Station", 0x1 },
1607 { "Mix", 0x2 },
1608 },
1609};
1610
1611static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001612 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001613 {
1614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1615 .name = "Master Playback Switch",
1616 .info = ad198x_eapd_info,
1617 .get = ad198x_eapd_get,
1618 .put = ad1981_hp_master_sw_put,
1619 .private_value = 0x05,
1620 },
1621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1623#if 0
1624 /* FIXME: analog mic/line loopback doesn't work with my tests...
1625 * (although recording is OK)
1626 */
1627 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1629 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1630 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1633 /* FIXME: does this laptop have analog CD connection? */
1634 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1635 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1636#endif
1637 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1638 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1639 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1640 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1641 {
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1643 .name = "Capture Source",
1644 .info = ad198x_mux_enum_info,
1645 .get = ad198x_mux_enum_get,
1646 .put = ad198x_mux_enum_put,
1647 },
1648 { } /* end */
1649};
1650
1651/* initialize jack-sensing, too */
1652static int ad1981_hp_init(struct hda_codec *codec)
1653{
1654 ad198x_init(codec);
1655 ad1981_hp_automute(codec);
1656 ad1981_hp_automic(codec);
1657 return 0;
1658}
1659
Tobin Davis18768992007-03-12 22:20:51 +01001660/* configuration for Toshiba Laptops */
1661static struct hda_verb ad1981_toshiba_init_verbs[] = {
1662 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1663 /* pin sensing on HP and Mic jacks */
1664 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1665 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1666 {}
1667};
1668
1669static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1670 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1671 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1672 { }
1673};
1674
Takashi Iwai01686c52006-04-18 12:54:11 +02001675/* configuration for Lenovo Thinkpad T60 */
1676static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1677 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1678 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1681 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1682 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1683 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1684 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1685 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1686 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1687 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1688 {
1689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1690 .name = "Capture Source",
1691 .info = ad198x_mux_enum_info,
1692 .get = ad198x_mux_enum_get,
1693 .put = ad198x_mux_enum_put,
1694 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001695 /* identical with AD1983 */
1696 {
1697 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1698 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1699 .info = ad1983_spdif_route_info,
1700 .get = ad1983_spdif_route_get,
1701 .put = ad1983_spdif_route_put,
1702 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001703 { } /* end */
1704};
1705
1706static struct hda_input_mux ad1981_thinkpad_capture_source = {
1707 .num_items = 3,
1708 .items = {
1709 { "Mic", 0x0 },
1710 { "Mix", 0x2 },
1711 { "CD", 0x4 },
1712 },
1713};
1714
Takashi Iwai18a815d2006-03-01 19:54:39 +01001715/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001716enum {
1717 AD1981_BASIC,
1718 AD1981_HP,
1719 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001720 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001721 AD1981_MODELS
1722};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001723
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001724static const char *ad1981_models[AD1981_MODELS] = {
1725 [AD1981_HP] = "hp",
1726 [AD1981_THINKPAD] = "thinkpad",
1727 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001728 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001729};
1730
1731static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001732 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001733 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001734 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001735 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001736 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c52006-04-18 12:54:11 +02001737 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001738 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001739 /* HP nx6320 (reversed SSID, H/W bug) */
1740 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001741 {}
1742};
1743
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001744static int patch_ad1981(struct hda_codec *codec)
1745{
1746 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001747 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001748
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001749 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001750 if (spec == NULL)
1751 return -ENOMEM;
1752
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001753 codec->spec = spec;
1754
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001755 err = snd_hda_attach_beep_device(codec, 0x10);
1756 if (err < 0) {
1757 ad198x_free(codec);
1758 return err;
1759 }
1760 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1761
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001762 spec->multiout.max_channels = 2;
1763 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1764 spec->multiout.dac_nids = ad1981_dac_nids;
1765 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001766 spec->num_adc_nids = 1;
1767 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001768 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001769 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001770 spec->num_mixers = 1;
1771 spec->mixers[0] = ad1981_mixers;
1772 spec->num_init_verbs = 1;
1773 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001774 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001775#ifdef CONFIG_SND_HDA_POWER_SAVE
1776 spec->loopback.amplist = ad1981_loopbacks;
1777#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001778 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001779
1780 codec->patch_ops = ad198x_patch_ops;
1781
Takashi Iwai18a815d2006-03-01 19:54:39 +01001782 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001783 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1784 ad1981_models,
1785 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001786 switch (board_config) {
1787 case AD1981_HP:
1788 spec->mixers[0] = ad1981_hp_mixers;
1789 spec->num_init_verbs = 2;
1790 spec->init_verbs[1] = ad1981_hp_init_verbs;
1791 spec->multiout.dig_out_nid = 0;
1792 spec->input_mux = &ad1981_hp_capture_source;
1793
1794 codec->patch_ops.init = ad1981_hp_init;
1795 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
Daniel T Chen01f59662009-12-13 16:22:58 -05001796 /* set the upper-limit for mixer amp to 0dB for avoiding the
1797 * possible damage by overloading
1798 */
1799 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1800 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1801 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1802 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1803 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai18a815d2006-03-01 19:54:39 +01001804 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001805 case AD1981_THINKPAD:
1806 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001807 spec->input_mux = &ad1981_thinkpad_capture_source;
1808 break;
Tobin Davis18768992007-03-12 22:20:51 +01001809 case AD1981_TOSHIBA:
1810 spec->mixers[0] = ad1981_hp_mixers;
1811 spec->mixers[1] = ad1981_toshiba_mixers;
1812 spec->num_init_verbs = 2;
1813 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1814 spec->multiout.dig_out_nid = 0;
1815 spec->input_mux = &ad1981_hp_capture_source;
1816 codec->patch_ops.init = ad1981_hp_init;
1817 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1818 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001819 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01001820
1821 codec->no_trigger_sense = 1;
1822
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001823 return 0;
1824}
1825
1826
1827/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001828 * AD1988
1829 *
1830 * Output pins and routes
1831 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001832 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001833 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1834 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1835 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1836 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1837 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1838 * port-F 0x16 (mute) <- 0x2a <- 06
1839 * port-G 0x24 (mute) <- 0x27 <- 05
1840 * port-H 0x25 (mute) <- 0x28 <- 0a
1841 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1842 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001843 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1844 * (*) 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 +01001845 *
1846 * Input pins and routes
1847 *
1848 * pin boost mix input # / adc input #
1849 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1850 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1851 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1852 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1853 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1854 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1855 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1856 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1857 *
1858 *
1859 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001860 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001861 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001862 *
1863 * Inputs of Analog Mix (0x20)
1864 * 0:Port-B (front mic)
1865 * 1:Port-C/G/H (line-in)
1866 * 2:Port-A
1867 * 3:Port-D (line-in/2)
1868 * 4:Port-E/G/H (mic-in)
1869 * 5:Port-F (mic2-in)
1870 * 6:CD
1871 * 7:Beep
1872 *
1873 * ADC selection
1874 * 0:Port-A
1875 * 1:Port-B (front mic-in)
1876 * 2:Port-C (line-in)
1877 * 3:Port-F (mic2-in)
1878 * 4:Port-E (mic-in)
1879 * 5:CD
1880 * 6:Port-G
1881 * 7:Port-H
1882 * 8:Port-D (line-in/2)
1883 * 9:Mix
1884 *
1885 * Proposed pin assignments by the datasheet
1886 *
1887 * 6-stack
1888 * Port-A front headphone
1889 * B front mic-in
1890 * C rear line-in
1891 * D rear front-out
1892 * E rear mic-in
1893 * F rear surround
1894 * G rear CLFE
1895 * H rear side
1896 *
1897 * 3-stack
1898 * Port-A front headphone
1899 * B front mic
1900 * C rear line-in/surround
1901 * D rear front-out
1902 * E rear mic-in/CLFE
1903 *
1904 * laptop
1905 * Port-A headphone
1906 * B mic-in
1907 * C docking station
1908 * D internal speaker (with EAPD)
1909 * E/F quad mic array
1910 */
1911
1912
1913/* models */
1914enum {
1915 AD1988_6STACK,
1916 AD1988_6STACK_DIG,
1917 AD1988_3STACK,
1918 AD1988_3STACK_DIG,
1919 AD1988_LAPTOP,
1920 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001921 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001922 AD1988_MODEL_LAST,
1923};
1924
Takashi Iwaid32410b12005-11-24 16:06:23 +01001925/* reivision id to check workarounds */
1926#define AD1988A_REV2 0x100200
1927
Takashi Iwai1a806f42006-07-03 15:58:16 +02001928#define is_rev2(codec) \
1929 ((codec)->vendor_id == 0x11d41988 && \
1930 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001931
1932/*
1933 * mixers
1934 */
1935
Takashi Iwaid32410b12005-11-24 16:06:23 +01001936static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001937 0x04, 0x06, 0x05, 0x0a
1938};
1939
Takashi Iwaid32410b12005-11-24 16:06:23 +01001940static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001941 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001942};
1943
1944/* for AD1988A revision-2, DAC2-4 are swapped */
1945static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1946 0x04, 0x05, 0x0a, 0x06
1947};
1948
1949static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001950 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001951};
1952
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001953static hda_nid_t ad1988_adc_nids[3] = {
1954 0x08, 0x09, 0x0f
1955};
1956
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001957static hda_nid_t ad1988_capsrc_nids[3] = {
1958 0x0c, 0x0d, 0x0e
1959};
1960
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001961#define AD1988_SPDIF_OUT 0x02
1962#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001963#define AD1988_SPDIF_IN 0x07
1964
Takashi Iwai3a08e302009-02-13 11:37:08 +01001965static hda_nid_t ad1989b_slave_dig_outs[] = {
1966 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001967};
1968
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001969static struct hda_input_mux ad1988_6stack_capture_source = {
1970 .num_items = 5,
1971 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001972 { "Front Mic", 0x1 }, /* port-B */
1973 { "Line", 0x2 }, /* port-C */
1974 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001975 { "CD", 0x5 },
1976 { "Mix", 0x9 },
1977 },
1978};
1979
1980static struct hda_input_mux ad1988_laptop_capture_source = {
1981 .num_items = 3,
1982 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001983 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001984 { "CD", 0x5 },
1985 { "Mix", 0x9 },
1986 },
1987};
1988
1989/*
1990 */
1991static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1992 struct snd_ctl_elem_info *uinfo)
1993{
1994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1995 struct ad198x_spec *spec = codec->spec;
1996 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1997 spec->num_channel_mode);
1998}
1999
2000static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
2001 struct snd_ctl_elem_value *ucontrol)
2002{
2003 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2004 struct ad198x_spec *spec = codec->spec;
2005 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
2006 spec->num_channel_mode, spec->multiout.max_channels);
2007}
2008
2009static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2010 struct snd_ctl_elem_value *ucontrol)
2011{
2012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2013 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002014 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2015 spec->num_channel_mode,
2016 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002017 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002018 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002019 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002020}
2021
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002022/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002023static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002024 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2025 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2026 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2027 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2028 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002029 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002030};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002031
Takashi Iwaid32410b12005-11-24 16:06:23 +01002032static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2033 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2034 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2035 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2036 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2037 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002038 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002039};
2040
2041static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002042 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2043 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2044 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2045 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2046 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2047 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2048 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2049
2050 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2051 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2052 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2053 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2054 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2055 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2056 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2057 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2058
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002059 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002060 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2061
2062 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2063 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2064
2065 { } /* end */
2066};
2067
2068/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002069static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002070 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002071 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002072 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2073 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002074 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002075};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002076
Takashi Iwaid32410b12005-11-24 16:06:23 +01002077static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2078 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002079 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2080 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2081 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002082 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002083};
2084
2085static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002086 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002087 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2088 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2089 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002090 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2091 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2092
2093 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2094 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2095 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2096 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2097 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2098 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2099 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2100 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2101
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002102 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002103 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2104
2105 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2106 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2107 {
2108 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2109 .name = "Channel Mode",
2110 .info = ad198x_ch_mode_info,
2111 .get = ad198x_ch_mode_get,
2112 .put = ad198x_ch_mode_put,
2113 },
2114
2115 { } /* end */
2116};
2117
2118/* laptop mode */
2119static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2120 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2121 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2122 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2123
2124 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2125 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2126 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2127 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2128 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2129 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2130
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002131 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002132 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2133
2134 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2135
2136 {
2137 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2138 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01002139 .info = ad198x_eapd_info,
2140 .get = ad198x_eapd_get,
2141 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +01002142 .private_value = 0x12, /* port-D */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002143 },
2144
2145 { } /* end */
2146};
2147
2148/* capture */
2149static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2150 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2151 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2152 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2153 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2154 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2155 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2156 {
2157 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2158 /* The multiple "Capture Source" controls confuse alsamixer
2159 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002160 */
2161 /* .name = "Capture Source", */
2162 .name = "Input Source",
2163 .count = 3,
2164 .info = ad198x_mux_enum_info,
2165 .get = ad198x_mux_enum_get,
2166 .put = ad198x_mux_enum_put,
2167 },
2168 { } /* end */
2169};
2170
2171static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2172 struct snd_ctl_elem_info *uinfo)
2173{
2174 static char *texts[] = {
2175 "PCM", "ADC1", "ADC2", "ADC3"
2176 };
2177 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2178 uinfo->count = 1;
2179 uinfo->value.enumerated.items = 4;
2180 if (uinfo->value.enumerated.item >= 4)
2181 uinfo->value.enumerated.item = 3;
2182 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2183 return 0;
2184}
2185
2186static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2187 struct snd_ctl_elem_value *ucontrol)
2188{
2189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2190 unsigned int sel;
2191
Takashi Iwaibddcf542007-07-24 18:04:05 +02002192 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2193 AC_AMP_GET_INPUT);
2194 if (!(sel & 0x80))
2195 ucontrol->value.enumerated.item[0] = 0;
2196 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002197 sel = snd_hda_codec_read(codec, 0x0b, 0,
2198 AC_VERB_GET_CONNECT_SEL, 0);
2199 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002200 sel++;
2201 else
2202 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002203 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002204 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002205 return 0;
2206}
2207
2208static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2209 struct snd_ctl_elem_value *ucontrol)
2210{
2211 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002212 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002213 int change;
2214
Takashi Iwai35b26722007-05-05 12:17:17 +02002215 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002216 if (val > 3)
2217 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002218 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002219 sel = snd_hda_codec_read(codec, 0x1d, 0,
2220 AC_VERB_GET_AMP_GAIN_MUTE,
2221 AC_AMP_GET_INPUT);
2222 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002223 if (change) {
2224 snd_hda_codec_write_cache(codec, 0x1d, 0,
2225 AC_VERB_SET_AMP_GAIN_MUTE,
2226 AMP_IN_UNMUTE(0));
2227 snd_hda_codec_write_cache(codec, 0x1d, 0,
2228 AC_VERB_SET_AMP_GAIN_MUTE,
2229 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002230 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002231 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002232 sel = snd_hda_codec_read(codec, 0x1d, 0,
2233 AC_VERB_GET_AMP_GAIN_MUTE,
2234 AC_AMP_GET_INPUT | 0x01);
2235 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002236 if (change) {
2237 snd_hda_codec_write_cache(codec, 0x1d, 0,
2238 AC_VERB_SET_AMP_GAIN_MUTE,
2239 AMP_IN_MUTE(0));
2240 snd_hda_codec_write_cache(codec, 0x1d, 0,
2241 AC_VERB_SET_AMP_GAIN_MUTE,
2242 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002243 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002244 sel = snd_hda_codec_read(codec, 0x0b, 0,
2245 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2246 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002247 if (change)
2248 snd_hda_codec_write_cache(codec, 0x0b, 0,
2249 AC_VERB_SET_CONNECT_SEL,
2250 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002251 }
2252 return change;
2253}
2254
2255static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2256 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2257 {
2258 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2259 .name = "IEC958 Playback Source",
2260 .info = ad1988_spdif_playback_source_info,
2261 .get = ad1988_spdif_playback_source_get,
2262 .put = ad1988_spdif_playback_source_put,
2263 },
2264 { } /* end */
2265};
2266
2267static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2268 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2269 { } /* end */
2270};
2271
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002272static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2273 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002274 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002275 { } /* end */
2276};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002277
2278/*
2279 * initialization verbs
2280 */
2281
2282/*
2283 * for 6-stack (+dig)
2284 */
2285static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002286 /* Front, Surround, CLFE, side DAC; unmute as default */
2287 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2289 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002291 /* Port-A front headphon path */
2292 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2293 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2294 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2295 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2296 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2297 /* Port-D line-out path */
2298 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2299 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2300 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2301 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 /* Port-F surround path */
2303 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2304 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2305 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2306 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2307 /* Port-G CLFE path */
2308 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2309 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2310 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2311 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2312 /* Port-H side path */
2313 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2314 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2315 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2316 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2317 /* Mono out path */
2318 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2319 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2320 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2321 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2322 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2323 /* Port-B front mic-in path */
2324 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2325 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2326 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2327 /* Port-C line-in path */
2328 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2329 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2330 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2331 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2332 /* Port-E mic-in path */
2333 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2334 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2335 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2336 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002337 /* Analog CD Input */
2338 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002339 /* Analog Mix output amp */
2340 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002341
2342 { }
2343};
2344
2345static struct hda_verb ad1988_capture_init_verbs[] = {
2346 /* mute analog mix */
2347 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2348 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2349 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2350 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2351 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2352 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2353 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2354 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2355 /* select ADCs - front-mic */
2356 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2357 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2358 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002359
2360 { }
2361};
2362
2363static struct hda_verb ad1988_spdif_init_verbs[] = {
2364 /* SPDIF out sel */
2365 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2366 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2367 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002368 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002369 /* SPDIF out pin */
2370 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002371
2372 { }
2373};
2374
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002375/* AD1989 has no ADC -> SPDIF route */
2376static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002377 /* SPDIF-1 out pin */
2378 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002379 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002380 /* SPDIF-2/HDMI out pin */
2381 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2382 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002383 { }
2384};
2385
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002386/*
2387 * verbs for 3stack (+dig)
2388 */
2389static struct hda_verb ad1988_3stack_ch2_init[] = {
2390 /* set port-C to line-in */
2391 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2392 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2393 /* set port-E to mic-in */
2394 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2395 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2396 { } /* end */
2397};
2398
2399static struct hda_verb ad1988_3stack_ch6_init[] = {
2400 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002401 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002402 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002403 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002404 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002405 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002406 { } /* end */
2407};
2408
2409static struct hda_channel_mode ad1988_3stack_modes[2] = {
2410 { 2, ad1988_3stack_ch2_init },
2411 { 6, ad1988_3stack_ch6_init },
2412};
2413
2414static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002415 /* Front, Surround, CLFE, side DAC; unmute as default */
2416 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2417 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2418 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2419 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002420 /* Port-A front headphon path */
2421 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2422 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2423 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2424 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2425 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2426 /* Port-D line-out path */
2427 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2428 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2429 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2430 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2431 /* Mono out path */
2432 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2433 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2434 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2435 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2436 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2437 /* Port-B front mic-in path */
2438 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2439 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2440 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002441 /* Port-C line-in/surround path - 6ch mode as default */
2442 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2443 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002444 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002445 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002446 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002447 /* Port-E mic-in/CLFE path - 6ch mode as default */
2448 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2449 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002450 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002451 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002452 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2453 /* mute analog mix */
2454 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2455 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2456 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2457 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2458 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2459 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2460 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2461 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2462 /* select ADCs - front-mic */
2463 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2464 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2465 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002466 /* Analog Mix output amp */
2467 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002468 { }
2469};
2470
2471/*
2472 * verbs for laptop mode (+dig)
2473 */
2474static struct hda_verb ad1988_laptop_hp_on[] = {
2475 /* unmute port-A and mute port-D */
2476 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2477 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2478 { } /* end */
2479};
2480static struct hda_verb ad1988_laptop_hp_off[] = {
2481 /* mute port-A and unmute port-D */
2482 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2483 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2484 { } /* end */
2485};
2486
2487#define AD1988_HP_EVENT 0x01
2488
2489static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002490 /* Front, Surround, CLFE, side DAC; unmute as default */
2491 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2493 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002495 /* Port-A front headphon path */
2496 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2497 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2498 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2499 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2501 /* unsolicited event for pin-sense */
2502 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2503 /* Port-D line-out path + EAPD */
2504 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2505 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2506 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2507 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2508 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2509 /* Mono out path */
2510 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2511 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2512 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2513 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2514 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2515 /* Port-B mic-in path */
2516 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2517 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2518 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2519 /* Port-C docking station - try to output */
2520 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2521 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2522 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2523 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2524 /* mute analog mix */
2525 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2526 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2527 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2528 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2529 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2530 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2531 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2532 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2533 /* select ADCs - mic */
2534 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2535 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2536 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002537 /* Analog Mix output amp */
2538 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002539 { }
2540};
2541
2542static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2543{
2544 if ((res >> 26) != AD1988_HP_EVENT)
2545 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002546 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002547 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2548 else
2549 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2550}
2551
Takashi Iwaicb53c622007-08-10 17:21:45 +02002552#ifdef CONFIG_SND_HDA_POWER_SAVE
2553static struct hda_amp_list ad1988_loopbacks[] = {
2554 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2555 { 0x20, HDA_INPUT, 1 }, /* Line */
2556 { 0x20, HDA_INPUT, 4 }, /* Mic */
2557 { 0x20, HDA_INPUT, 6 }, /* CD */
2558 { } /* end */
2559};
2560#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002561
2562/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002563 * Automatic parse of I/O pins from the BIOS configuration
2564 */
2565
Takashi Iwaid32410b12005-11-24 16:06:23 +01002566enum {
2567 AD_CTL_WIDGET_VOL,
2568 AD_CTL_WIDGET_MUTE,
2569 AD_CTL_BIND_MUTE,
2570};
2571static struct snd_kcontrol_new ad1988_control_templates[] = {
2572 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2573 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2574 HDA_BIND_MUTE(NULL, 0, 0, 0),
2575};
2576
2577/* add dynamic controls */
2578static int add_control(struct ad198x_spec *spec, int type, const char *name,
2579 unsigned long val)
2580{
2581 struct snd_kcontrol_new *knew;
2582
Takashi Iwai603c4012008-07-30 15:01:44 +02002583 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2584 knew = snd_array_new(&spec->kctls);
2585 if (!knew)
2586 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002587 *knew = ad1988_control_templates[type];
2588 knew->name = kstrdup(name, GFP_KERNEL);
2589 if (! knew->name)
2590 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002591 if (get_amp_nid_(val))
Takashi Iwai9c96fa52009-11-16 11:25:33 +01002592 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002593 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002594 return 0;
2595}
2596
2597#define AD1988_PIN_CD_NID 0x18
2598#define AD1988_PIN_BEEP_NID 0x10
2599
2600static hda_nid_t ad1988_mixer_nids[8] = {
2601 /* A B C D E F G H */
2602 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2603};
2604
2605static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2606{
2607 static hda_nid_t idx_to_dac[8] = {
2608 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002609 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002610 };
2611 static hda_nid_t idx_to_dac_rev2[8] = {
2612 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002613 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002614 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002615 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002616 return idx_to_dac_rev2[idx];
2617 else
2618 return idx_to_dac[idx];
2619}
2620
2621static hda_nid_t ad1988_boost_nids[8] = {
2622 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2623};
2624
2625static int ad1988_pin_idx(hda_nid_t nid)
2626{
2627 static hda_nid_t ad1988_io_pins[8] = {
2628 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2629 };
2630 int i;
2631 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2632 if (ad1988_io_pins[i] == nid)
2633 return i;
2634 return 0; /* should be -1 */
2635}
2636
2637static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2638{
2639 static int loopback_idx[8] = {
2640 2, 0, 1, 3, 4, 5, 1, 4
2641 };
2642 switch (nid) {
2643 case AD1988_PIN_CD_NID:
2644 return 6;
2645 default:
2646 return loopback_idx[ad1988_pin_idx(nid)];
2647 }
2648}
2649
2650static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2651{
2652 static int adc_idx[8] = {
2653 0, 1, 2, 8, 4, 3, 6, 7
2654 };
2655 switch (nid) {
2656 case AD1988_PIN_CD_NID:
2657 return 5;
2658 default:
2659 return adc_idx[ad1988_pin_idx(nid)];
2660 }
2661}
2662
2663/* fill in the dac_nids table from the parsed pin configuration */
2664static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2665 const struct auto_pin_cfg *cfg)
2666{
2667 struct ad198x_spec *spec = codec->spec;
2668 int i, idx;
2669
2670 spec->multiout.dac_nids = spec->private_dac_nids;
2671
2672 /* check the pins hardwired to audio widget */
2673 for (i = 0; i < cfg->line_outs; i++) {
2674 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2675 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2676 }
2677 spec->multiout.num_dacs = cfg->line_outs;
2678 return 0;
2679}
2680
2681/* add playback controls from the parsed DAC table */
2682static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2683 const struct auto_pin_cfg *cfg)
2684{
2685 char name[32];
2686 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2687 hda_nid_t nid;
2688 int i, err;
2689
2690 for (i = 0; i < cfg->line_outs; i++) {
2691 hda_nid_t dac = spec->multiout.dac_nids[i];
2692 if (! dac)
2693 continue;
2694 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2695 if (i == 2) {
2696 /* Center/LFE */
2697 err = add_control(spec, AD_CTL_WIDGET_VOL,
2698 "Center Playback Volume",
2699 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2700 if (err < 0)
2701 return err;
2702 err = add_control(spec, AD_CTL_WIDGET_VOL,
2703 "LFE Playback Volume",
2704 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2705 if (err < 0)
2706 return err;
2707 err = add_control(spec, AD_CTL_BIND_MUTE,
2708 "Center Playback Switch",
2709 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2710 if (err < 0)
2711 return err;
2712 err = add_control(spec, AD_CTL_BIND_MUTE,
2713 "LFE Playback Switch",
2714 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2715 if (err < 0)
2716 return err;
2717 } else {
2718 sprintf(name, "%s Playback Volume", chname[i]);
2719 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2720 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2721 if (err < 0)
2722 return err;
2723 sprintf(name, "%s Playback Switch", chname[i]);
2724 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2725 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2726 if (err < 0)
2727 return err;
2728 }
2729 }
2730 return 0;
2731}
2732
2733/* add playback controls for speaker and HP outputs */
2734static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2735 const char *pfx)
2736{
2737 struct ad198x_spec *spec = codec->spec;
2738 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002739 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002740 char name[32];
2741
2742 if (! pin)
2743 return 0;
2744
2745 idx = ad1988_pin_idx(pin);
2746 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002747 /* check whether the corresponding DAC was already taken */
2748 for (i = 0; i < spec->autocfg.line_outs; i++) {
2749 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2750 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2751 if (dac == nid)
2752 break;
2753 }
2754 if (i >= spec->autocfg.line_outs) {
2755 /* specify the DAC as the extra output */
2756 if (!spec->multiout.hp_nid)
2757 spec->multiout.hp_nid = nid;
2758 else
2759 spec->multiout.extra_out_nid[0] = nid;
2760 /* control HP volume/switch on the output mixer amp */
2761 sprintf(name, "%s Playback Volume", pfx);
2762 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2763 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2764 if (err < 0)
2765 return err;
2766 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002767 nid = ad1988_mixer_nids[idx];
2768 sprintf(name, "%s Playback Switch", pfx);
2769 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2770 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2771 return err;
2772 return 0;
2773}
2774
2775/* create input playback/capture controls for the given pin */
2776static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2777 const char *ctlname, int boost)
2778{
2779 char name[32];
2780 int err, idx;
2781
2782 sprintf(name, "%s Playback Volume", ctlname);
2783 idx = ad1988_pin_to_loopback_idx(pin);
2784 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2785 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2786 return err;
2787 sprintf(name, "%s Playback Switch", ctlname);
2788 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2789 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2790 return err;
2791 if (boost) {
2792 hda_nid_t bnid;
2793 idx = ad1988_pin_idx(pin);
2794 bnid = ad1988_boost_nids[idx];
2795 if (bnid) {
2796 sprintf(name, "%s Boost", ctlname);
2797 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2798 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2799
2800 }
2801 }
2802 return 0;
2803}
2804
2805/* create playback/capture controls for input pins */
2806static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2807 const struct auto_pin_cfg *cfg)
2808{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002809 struct hda_input_mux *imux = &spec->private_imux;
2810 int i, err;
2811
2812 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002813 err = new_analog_input(spec, cfg->input_pins[i],
2814 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002815 i <= AUTO_PIN_FRONT_MIC);
2816 if (err < 0)
2817 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002818 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002819 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2820 imux->num_items++;
2821 }
2822 imux->items[imux->num_items].label = "Mix";
2823 imux->items[imux->num_items].index = 9;
2824 imux->num_items++;
2825
2826 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2827 "Analog Mix Playback Volume",
2828 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2829 return err;
2830 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2831 "Analog Mix Playback Switch",
2832 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2833 return err;
2834
2835 return 0;
2836}
2837
2838static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2839 hda_nid_t nid, int pin_type,
2840 int dac_idx)
2841{
2842 /* set as output */
2843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2844 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2845 switch (nid) {
2846 case 0x11: /* port-A - DAC 04 */
2847 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2848 break;
2849 case 0x14: /* port-B - DAC 06 */
2850 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2851 break;
2852 case 0x15: /* port-C - DAC 05 */
2853 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2854 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002855 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002856 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2857 break;
2858 case 0x13: /* mono - DAC 04 */
2859 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2860 break;
2861 }
2862}
2863
2864static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2865{
2866 struct ad198x_spec *spec = codec->spec;
2867 int i;
2868
2869 for (i = 0; i < spec->autocfg.line_outs; i++) {
2870 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2871 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2872 }
2873}
2874
2875static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2876{
2877 struct ad198x_spec *spec = codec->spec;
2878 hda_nid_t pin;
2879
Takashi Iwai82bc9552006-03-21 11:24:42 +01002880 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002881 if (pin) /* connect to front */
2882 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002883 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002884 if (pin) /* connect to front */
2885 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2886}
2887
2888static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2889{
2890 struct ad198x_spec *spec = codec->spec;
2891 int i, idx;
2892
2893 for (i = 0; i < AUTO_PIN_LAST; i++) {
2894 hda_nid_t nid = spec->autocfg.input_pins[i];
2895 if (! nid)
2896 continue;
2897 switch (nid) {
2898 case 0x15: /* port-C */
2899 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2900 break;
2901 case 0x17: /* port-E */
2902 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2903 break;
2904 }
2905 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2906 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2907 if (nid != AD1988_PIN_CD_NID)
2908 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2909 AMP_OUT_MUTE);
2910 idx = ad1988_pin_idx(nid);
2911 if (ad1988_boost_nids[idx])
2912 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2913 AC_VERB_SET_AMP_GAIN_MUTE,
2914 AMP_OUT_ZERO);
2915 }
2916}
2917
2918/* parse the BIOS configuration and set up the alc_spec */
2919/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2920static int ad1988_parse_auto_config(struct hda_codec *codec)
2921{
2922 struct ad198x_spec *spec = codec->spec;
2923 int err;
2924
Kailang Yangdf694da2005-12-05 19:42:22 +01002925 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002926 return err;
2927 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2928 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002929 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002930 return 0; /* can't find valid BIOS pin config */
2931 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002932 (err = ad1988_auto_create_extra_out(codec,
2933 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002934 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002935 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002936 "Headphone")) < 0 ||
2937 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2938 return err;
2939
2940 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2941
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002942 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002943 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2944 if (spec->autocfg.dig_in_pin)
2945 spec->dig_in_nid = AD1988_SPDIF_IN;
2946
Takashi Iwai603c4012008-07-30 15:01:44 +02002947 if (spec->kctls.list)
2948 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002949
2950 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2951
2952 spec->input_mux = &spec->private_imux;
2953
2954 return 1;
2955}
2956
2957/* init callback for auto-configuration model -- overriding the default init */
2958static int ad1988_auto_init(struct hda_codec *codec)
2959{
2960 ad198x_init(codec);
2961 ad1988_auto_init_multi_out(codec);
2962 ad1988_auto_init_extra_out(codec);
2963 ad1988_auto_init_analog_input(codec);
2964 return 0;
2965}
2966
2967
2968/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002969 */
2970
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002971static const char *ad1988_models[AD1988_MODEL_LAST] = {
2972 [AD1988_6STACK] = "6stack",
2973 [AD1988_6STACK_DIG] = "6stack-dig",
2974 [AD1988_3STACK] = "3stack",
2975 [AD1988_3STACK_DIG] = "3stack-dig",
2976 [AD1988_LAPTOP] = "laptop",
2977 [AD1988_LAPTOP_DIG] = "laptop-dig",
2978 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002979};
2980
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002981static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01002982 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01002983 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02002984 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07002985 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002986 {}
2987};
2988
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002989static int patch_ad1988(struct hda_codec *codec)
2990{
2991 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01002992 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002993
2994 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2995 if (spec == NULL)
2996 return -ENOMEM;
2997
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002998 codec->spec = spec;
2999
Takashi Iwai1a806f42006-07-03 15:58:16 +02003000 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003001 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3002
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003003 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003004 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003005 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02003006 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3007 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003008 board_config = AD1988_AUTO;
3009 }
3010
3011 if (board_config == AD1988_AUTO) {
3012 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003013 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003014 if (err < 0) {
3015 ad198x_free(codec);
3016 return err;
3017 } else if (! err) {
3018 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3019 board_config = AD1988_6STACK;
3020 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003021 }
3022
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003023 err = snd_hda_attach_beep_device(codec, 0x10);
3024 if (err < 0) {
3025 ad198x_free(codec);
3026 return err;
3027 }
3028 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3029
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003030 switch (board_config) {
3031 case AD1988_6STACK:
3032 case AD1988_6STACK_DIG:
3033 spec->multiout.max_channels = 8;
3034 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003035 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003036 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3037 else
3038 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003039 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003040 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003041 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003042 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3043 else
3044 spec->mixers[0] = ad1988_6stack_mixers1;
3045 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003046 spec->num_init_verbs = 1;
3047 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3048 if (board_config == AD1988_6STACK_DIG) {
3049 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3050 spec->dig_in_nid = AD1988_SPDIF_IN;
3051 }
3052 break;
3053 case AD1988_3STACK:
3054 case AD1988_3STACK_DIG:
3055 spec->multiout.max_channels = 6;
3056 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003057 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003058 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3059 else
3060 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003061 spec->input_mux = &ad1988_6stack_capture_source;
3062 spec->channel_mode = ad1988_3stack_modes;
3063 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003064 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003065 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003066 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3067 else
3068 spec->mixers[0] = ad1988_3stack_mixers1;
3069 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003070 spec->num_init_verbs = 1;
3071 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3072 if (board_config == AD1988_3STACK_DIG)
3073 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3074 break;
3075 case AD1988_LAPTOP:
3076 case AD1988_LAPTOP_DIG:
3077 spec->multiout.max_channels = 2;
3078 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003079 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003080 spec->input_mux = &ad1988_laptop_capture_source;
3081 spec->num_mixers = 1;
3082 spec->mixers[0] = ad1988_laptop_mixers;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01003083 spec->inv_eapd = 1; /* inverted EAPD */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003084 spec->num_init_verbs = 1;
3085 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3086 if (board_config == AD1988_LAPTOP_DIG)
3087 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3088 break;
3089 }
3090
Takashi Iwaid32410b12005-11-24 16:06:23 +01003091 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3092 spec->adc_nids = ad1988_adc_nids;
3093 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003094 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3095 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3096 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003097 if (codec->vendor_id >= 0x11d4989a) {
3098 spec->mixers[spec->num_mixers++] =
3099 ad1989_spdif_out_mixers;
3100 spec->init_verbs[spec->num_init_verbs++] =
3101 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003102 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003103 } else {
3104 spec->mixers[spec->num_mixers++] =
3105 ad1988_spdif_out_mixers;
3106 spec->init_verbs[spec->num_init_verbs++] =
3107 ad1988_spdif_init_verbs;
3108 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003109 }
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003110 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003111 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3112
3113 codec->patch_ops = ad198x_patch_ops;
3114 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003115 case AD1988_AUTO:
3116 codec->patch_ops.init = ad1988_auto_init;
3117 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003118 case AD1988_LAPTOP:
3119 case AD1988_LAPTOP_DIG:
3120 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3121 break;
3122 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003123#ifdef CONFIG_SND_HDA_POWER_SAVE
3124 spec->loopback.amplist = ad1988_loopbacks;
3125#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003126 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003127
Takashi Iwai729d55b2009-12-25 22:49:01 +01003128 codec->no_trigger_sense = 1;
3129
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003130 return 0;
3131}
3132
3133
3134/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003135 * AD1884 / AD1984
3136 *
3137 * port-B - front line/mic-in
3138 * port-E - aux in/out
3139 * port-F - aux in/out
3140 * port-C - rear line/mic-in
3141 * port-D - rear line/hp-out
3142 * port-A - front line/hp-out
3143 *
3144 * AD1984 = AD1884 + two digital mic-ins
3145 *
3146 * FIXME:
3147 * For simplicity, we share the single DAC for both HP and line-outs
3148 * right now. The inidividual playbacks could be easily implemented,
3149 * but no build-up framework is given, so far.
3150 */
3151
3152static hda_nid_t ad1884_dac_nids[1] = {
3153 0x04,
3154};
3155
3156static hda_nid_t ad1884_adc_nids[2] = {
3157 0x08, 0x09,
3158};
3159
3160static hda_nid_t ad1884_capsrc_nids[2] = {
3161 0x0c, 0x0d,
3162};
3163
3164#define AD1884_SPDIF_OUT 0x02
3165
3166static struct hda_input_mux ad1884_capture_source = {
3167 .num_items = 4,
3168 .items = {
3169 { "Front Mic", 0x0 },
3170 { "Mic", 0x1 },
3171 { "CD", 0x2 },
3172 { "Mix", 0x3 },
3173 },
3174};
3175
3176static struct snd_kcontrol_new ad1884_base_mixers[] = {
3177 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3178 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3179 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3180 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3181 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3182 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3183 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3184 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3185 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3186 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3187 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3188 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003189 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3190 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3191 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3192 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3193 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3194 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3195 {
3196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3197 /* The multiple "Capture Source" controls confuse alsamixer
3198 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003199 */
3200 /* .name = "Capture Source", */
3201 .name = "Input Source",
3202 .count = 2,
3203 .info = ad198x_mux_enum_info,
3204 .get = ad198x_mux_enum_get,
3205 .put = ad198x_mux_enum_put,
3206 },
3207 /* SPDIF controls */
3208 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3209 {
3210 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3211 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3212 /* identical with ad1983 */
3213 .info = ad1983_spdif_route_info,
3214 .get = ad1983_spdif_route_get,
3215 .put = ad1983_spdif_route_put,
3216 },
3217 { } /* end */
3218};
3219
3220static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3221 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3222 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3223 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003224 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003225 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003226 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003227 { } /* end */
3228};
3229
3230/*
3231 * initialization verbs
3232 */
3233static struct hda_verb ad1884_init_verbs[] = {
3234 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003235 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3236 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003237 /* Port-A (HP) mixer */
3238 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3239 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3240 /* Port-A pin */
3241 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3242 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3243 /* HP selector - select DAC2 */
3244 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3245 /* Port-D (Line-out) mixer */
3246 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3247 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3248 /* Port-D pin */
3249 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3250 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3251 /* Mono-out mixer */
3252 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3253 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3254 /* Mono-out pin */
3255 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3256 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3257 /* Mono selector */
3258 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3259 /* Port-B (front mic) pin */
3260 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003261 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003262 /* Port-C (rear mic) pin */
3263 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003264 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003265 /* Analog mixer; mute as default */
3266 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3267 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3268 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3269 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3270 /* Analog Mix output amp */
3271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3272 /* SPDIF output selector */
3273 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3274 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3275 { } /* end */
3276};
3277
Takashi Iwaicb53c622007-08-10 17:21:45 +02003278#ifdef CONFIG_SND_HDA_POWER_SAVE
3279static struct hda_amp_list ad1884_loopbacks[] = {
3280 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3281 { 0x20, HDA_INPUT, 1 }, /* Mic */
3282 { 0x20, HDA_INPUT, 2 }, /* CD */
3283 { 0x20, HDA_INPUT, 4 }, /* Docking */
3284 { } /* end */
3285};
3286#endif
3287
Takashi Iwai2134ea42008-01-10 16:53:55 +01003288static const char *ad1884_slave_vols[] = {
3289 "PCM Playback Volume",
3290 "Mic Playback Volume",
3291 "Mono Playback Volume",
3292 "Front Mic Playback Volume",
3293 "Mic Playback Volume",
3294 "CD Playback Volume",
3295 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003296 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003297 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003298 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003299 NULL
3300};
3301
Takashi Iwai2bac6472007-05-18 18:21:41 +02003302static int patch_ad1884(struct hda_codec *codec)
3303{
3304 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003305 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003306
3307 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3308 if (spec == NULL)
3309 return -ENOMEM;
3310
Takashi Iwai2bac6472007-05-18 18:21:41 +02003311 codec->spec = spec;
3312
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003313 err = snd_hda_attach_beep_device(codec, 0x10);
3314 if (err < 0) {
3315 ad198x_free(codec);
3316 return err;
3317 }
3318 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3319
Takashi Iwai2bac6472007-05-18 18:21:41 +02003320 spec->multiout.max_channels = 2;
3321 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3322 spec->multiout.dac_nids = ad1884_dac_nids;
3323 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3324 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3325 spec->adc_nids = ad1884_adc_nids;
3326 spec->capsrc_nids = ad1884_capsrc_nids;
3327 spec->input_mux = &ad1884_capture_source;
3328 spec->num_mixers = 1;
3329 spec->mixers[0] = ad1884_base_mixers;
3330 spec->num_init_verbs = 1;
3331 spec->init_verbs[0] = ad1884_init_verbs;
3332 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003333#ifdef CONFIG_SND_HDA_POWER_SAVE
3334 spec->loopback.amplist = ad1884_loopbacks;
3335#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003336 spec->vmaster_nid = 0x04;
3337 /* we need to cover all playback volumes */
3338 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003339
3340 codec->patch_ops = ad198x_patch_ops;
3341
Takashi Iwai729d55b2009-12-25 22:49:01 +01003342 codec->no_trigger_sense = 1;
3343
Takashi Iwai2bac6472007-05-18 18:21:41 +02003344 return 0;
3345}
3346
3347/*
3348 * Lenovo Thinkpad T61/X61
3349 */
3350static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003351 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003352 .items = {
3353 { "Mic", 0x0 },
3354 { "Internal Mic", 0x1 },
3355 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003356 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003357 },
3358};
3359
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003360
3361/*
3362 * Dell Precision T3400
3363 */
3364static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3365 .num_items = 3,
3366 .items = {
3367 { "Front Mic", 0x0 },
3368 { "Line-In", 0x1 },
3369 { "Mix", 0x3 },
3370 },
3371};
3372
3373
Takashi Iwai2bac6472007-05-18 18:21:41 +02003374static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3375 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3376 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3377 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3378 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3379 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3380 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3381 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3382 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3383 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3384 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003385 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3386 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003387 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003388 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3389 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3390 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3391 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3392 {
3393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3394 /* The multiple "Capture Source" controls confuse alsamixer
3395 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003396 */
3397 /* .name = "Capture Source", */
3398 .name = "Input Source",
3399 .count = 2,
3400 .info = ad198x_mux_enum_info,
3401 .get = ad198x_mux_enum_get,
3402 .put = ad198x_mux_enum_put,
3403 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003404 /* SPDIF controls */
3405 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3406 {
3407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3408 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3409 /* identical with ad1983 */
3410 .info = ad1983_spdif_route_info,
3411 .get = ad1983_spdif_route_get,
3412 .put = ad1983_spdif_route_put,
3413 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003414 { } /* end */
3415};
3416
3417/* additional verbs */
3418static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3419 /* Port-E (docking station mic) pin */
3420 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3421 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3422 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003423 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003424 /* Analog mixer - docking mic; mute as default */
3425 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003426 /* enable EAPD bit */
3427 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003428 { } /* end */
3429};
3430
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003431/*
3432 * Dell Precision T3400
3433 */
3434static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3435 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3436 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3437 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3438 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3439 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3440 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3441 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3442 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3443 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003444 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3445 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3446 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3447 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3448 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3449 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3450 {
3451 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3452 /* The multiple "Capture Source" controls confuse alsamixer
3453 * So call somewhat different..
3454 */
3455 /* .name = "Capture Source", */
3456 .name = "Input Source",
3457 .count = 2,
3458 .info = ad198x_mux_enum_info,
3459 .get = ad198x_mux_enum_get,
3460 .put = ad198x_mux_enum_put,
3461 },
3462 { } /* end */
3463};
3464
Takashi Iwai2bac6472007-05-18 18:21:41 +02003465/* Digial MIC ADC NID 0x05 + 0x06 */
3466static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3467 struct hda_codec *codec,
3468 unsigned int stream_tag,
3469 unsigned int format,
3470 struct snd_pcm_substream *substream)
3471{
3472 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3473 stream_tag, 0, format);
3474 return 0;
3475}
3476
3477static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3478 struct hda_codec *codec,
3479 struct snd_pcm_substream *substream)
3480{
Takashi Iwai888afa12008-03-18 09:57:50 +01003481 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003482 return 0;
3483}
3484
3485static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3486 .substreams = 2,
3487 .channels_min = 2,
3488 .channels_max = 2,
3489 .nid = 0x05,
3490 .ops = {
3491 .prepare = ad1984_pcm_dmic_prepare,
3492 .cleanup = ad1984_pcm_dmic_cleanup
3493 },
3494};
3495
3496static int ad1984_build_pcms(struct hda_codec *codec)
3497{
3498 struct ad198x_spec *spec = codec->spec;
3499 struct hda_pcm *info;
3500 int err;
3501
3502 err = ad198x_build_pcms(codec);
3503 if (err < 0)
3504 return err;
3505
3506 info = spec->pcm_rec + codec->num_pcms;
3507 codec->num_pcms++;
3508 info->name = "AD1984 Digital Mic";
3509 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3510 return 0;
3511}
3512
3513/* models */
3514enum {
3515 AD1984_BASIC,
3516 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003517 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003518 AD1984_MODELS
3519};
3520
3521static const char *ad1984_models[AD1984_MODELS] = {
3522 [AD1984_BASIC] = "basic",
3523 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003524 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003525};
3526
3527static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3528 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003529 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003530 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003531 {}
3532};
3533
3534static int patch_ad1984(struct hda_codec *codec)
3535{
3536 struct ad198x_spec *spec;
3537 int board_config, err;
3538
3539 err = patch_ad1884(codec);
3540 if (err < 0)
3541 return err;
3542 spec = codec->spec;
3543 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3544 ad1984_models, ad1984_cfg_tbl);
3545 switch (board_config) {
3546 case AD1984_BASIC:
3547 /* additional digital mics */
3548 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3549 codec->patch_ops.build_pcms = ad1984_build_pcms;
3550 break;
3551 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003552 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003553 spec->input_mux = &ad1984_thinkpad_capture_source;
3554 spec->mixers[0] = ad1984_thinkpad_mixers;
3555 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3556 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003557 case AD1984_DELL_DESKTOP:
3558 spec->multiout.dig_out_nid = 0;
3559 spec->input_mux = &ad1984_dell_desktop_capture_source;
3560 spec->mixers[0] = ad1984_dell_desktop_mixers;
3561 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003562 }
3563 return 0;
3564}
3565
3566
3567/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003568 * AD1883 / AD1884A / AD1984A / AD1984B
3569 *
3570 * port-B (0x14) - front mic-in
3571 * port-E (0x1c) - rear mic-in
3572 * port-F (0x16) - CD / ext out
3573 * port-C (0x15) - rear line-in
3574 * port-D (0x12) - rear line-out
3575 * port-A (0x11) - front hp-out
3576 *
3577 * AD1984A = AD1884A + digital-mic
3578 * AD1883 = equivalent with AD1984A
3579 * AD1984B = AD1984A + extra SPDIF-out
3580 *
3581 * FIXME:
3582 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3583 */
3584
3585static hda_nid_t ad1884a_dac_nids[1] = {
3586 0x03,
3587};
3588
3589#define ad1884a_adc_nids ad1884_adc_nids
3590#define ad1884a_capsrc_nids ad1884_capsrc_nids
3591
3592#define AD1884A_SPDIF_OUT 0x02
3593
3594static struct hda_input_mux ad1884a_capture_source = {
3595 .num_items = 5,
3596 .items = {
3597 { "Front Mic", 0x0 },
3598 { "Mic", 0x4 },
3599 { "Line", 0x1 },
3600 { "CD", 0x2 },
3601 { "Mix", 0x3 },
3602 },
3603};
3604
3605static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3606 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3607 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3608 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3609 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3610 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3611 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3612 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3613 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3614 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3615 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3616 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3617 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3618 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3619 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3620 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3621 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003622 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3623 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3624 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3625 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3626 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3627 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3628 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3629 {
3630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3631 /* The multiple "Capture Source" controls confuse alsamixer
3632 * So call somewhat different..
3633 */
3634 /* .name = "Capture Source", */
3635 .name = "Input Source",
3636 .count = 2,
3637 .info = ad198x_mux_enum_info,
3638 .get = ad198x_mux_enum_get,
3639 .put = ad198x_mux_enum_put,
3640 },
3641 /* SPDIF controls */
3642 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3643 {
3644 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3645 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3646 /* identical with ad1983 */
3647 .info = ad1983_spdif_route_info,
3648 .get = ad1983_spdif_route_get,
3649 .put = ad1983_spdif_route_put,
3650 },
3651 { } /* end */
3652};
3653
3654/*
3655 * initialization verbs
3656 */
3657static struct hda_verb ad1884a_init_verbs[] = {
3658 /* DACs; unmute as default */
3659 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3660 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3661 /* Port-A (HP) mixer - route only from analog mixer */
3662 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3663 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3664 /* Port-A pin */
3665 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3666 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3667 /* Port-D (Line-out) mixer - route only from analog mixer */
3668 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3669 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3670 /* Port-D pin */
3671 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3672 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3673 /* Mono-out mixer - route only from analog mixer */
3674 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3675 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3676 /* Mono-out pin */
3677 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3678 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3679 /* Port-B (front mic) pin */
3680 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003681 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003682 /* Port-C (rear line-in) pin */
3683 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003684 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003685 /* Port-E (rear mic) pin */
3686 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3687 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3688 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3689 /* Port-F (CD) pin */
3690 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3691 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3692 /* Analog mixer; mute as default */
3693 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3694 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3695 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3696 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3697 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3698 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3699 /* Analog Mix output amp */
3700 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3701 /* capture sources */
3702 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3703 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3704 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3705 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3706 /* SPDIF output amp */
3707 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3708 { } /* end */
3709};
3710
3711#ifdef CONFIG_SND_HDA_POWER_SAVE
3712static struct hda_amp_list ad1884a_loopbacks[] = {
3713 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3714 { 0x20, HDA_INPUT, 1 }, /* Mic */
3715 { 0x20, HDA_INPUT, 2 }, /* CD */
3716 { 0x20, HDA_INPUT, 4 }, /* Docking */
3717 { } /* end */
3718};
3719#endif
3720
3721/*
3722 * Laptop model
3723 *
3724 * Port A: Headphone jack
3725 * Port B: MIC jack
3726 * Port C: Internal MIC
3727 * Port D: Dock Line Out (if enabled)
3728 * Port E: Dock Line In (if enabled)
3729 * Port F: Internal speakers
3730 */
3731
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003732static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3733 struct snd_ctl_elem_value *ucontrol)
3734{
3735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3736 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3737 int mute = (!ucontrol->value.integer.value[0] &&
3738 !ucontrol->value.integer.value[1]);
3739 /* toggle GPIO1 according to the mute state */
3740 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3741 mute ? 0x02 : 0x0);
3742 return ret;
3743}
Takashi Iwaic5059252008-02-16 09:43:56 +01003744
3745static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3746 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003747 {
3748 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3749 .name = "Master Playback Switch",
3750 .info = snd_hda_mixer_amp_switch_info,
3751 .get = snd_hda_mixer_amp_switch_get,
3752 .put = ad1884a_mobile_master_sw_put,
3753 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3754 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003755 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3756 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3757 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3758 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3759 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3761 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3762 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3763 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003764 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3765 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3766 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3767 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3768 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003769 { } /* end */
3770};
3771
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003772static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3773 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db172009-07-02 16:10:23 +02003774 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3775 {
3776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3777 .name = "Master Playback Switch",
3778 .info = snd_hda_mixer_amp_switch_info,
3779 .get = snd_hda_mixer_amp_switch_get,
3780 .put = ad1884a_mobile_master_sw_put,
3781 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3782 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003783 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3784 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003785 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3786 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003787 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3788 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003789 { } /* end */
3790};
3791
Takashi Iwaic5059252008-02-16 09:43:56 +01003792/* mute internal speaker if HP is plugged */
3793static void ad1884a_hp_automute(struct hda_codec *codec)
3794{
3795 unsigned int present;
3796
Takashi Iwaid56757a2009-11-18 08:00:14 +01003797 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01003798 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3799 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3800 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3801 present ? 0x00 : 0x02);
3802}
3803
Takashi Iwai269ef192008-05-30 15:32:15 +02003804/* switch to external mic if plugged */
3805static void ad1884a_hp_automic(struct hda_codec *codec)
3806{
3807 unsigned int present;
3808
Takashi Iwaid56757a2009-11-18 08:00:14 +01003809 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02003810 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3811 present ? 0 : 1);
3812}
3813
Takashi Iwaic5059252008-02-16 09:43:56 +01003814#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02003815#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01003816
3817/* unsolicited event for HP jack sensing */
3818static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3819{
Takashi Iwai269ef192008-05-30 15:32:15 +02003820 switch (res >> 26) {
3821 case AD1884A_HP_EVENT:
3822 ad1884a_hp_automute(codec);
3823 break;
3824 case AD1884A_MIC_EVENT:
3825 ad1884a_hp_automic(codec);
3826 break;
3827 }
Takashi Iwaic5059252008-02-16 09:43:56 +01003828}
3829
3830/* initialize jack-sensing, too */
3831static int ad1884a_hp_init(struct hda_codec *codec)
3832{
3833 ad198x_init(codec);
3834 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02003835 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01003836 return 0;
3837}
3838
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003839/* mute internal speaker if HP or docking HP is plugged */
3840static void ad1884a_laptop_automute(struct hda_codec *codec)
3841{
3842 unsigned int present;
3843
Takashi Iwaid56757a2009-11-18 08:00:14 +01003844 present = snd_hda_jack_detect(codec, 0x11);
3845 if (!present)
3846 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003847 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3848 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3849 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3850 present ? 0x00 : 0x02);
3851}
3852
3853/* switch to external mic if plugged */
3854static void ad1884a_laptop_automic(struct hda_codec *codec)
3855{
3856 unsigned int idx;
3857
Takashi Iwaid56757a2009-11-18 08:00:14 +01003858 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003859 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01003860 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003861 idx = 4;
3862 else
3863 idx = 1;
3864 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3865}
3866
3867/* unsolicited event for HP jack sensing */
3868static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3869 unsigned int res)
3870{
3871 switch (res >> 26) {
3872 case AD1884A_HP_EVENT:
3873 ad1884a_laptop_automute(codec);
3874 break;
3875 case AD1884A_MIC_EVENT:
3876 ad1884a_laptop_automic(codec);
3877 break;
3878 }
3879}
3880
3881/* initialize jack-sensing, too */
3882static int ad1884a_laptop_init(struct hda_codec *codec)
3883{
3884 ad198x_init(codec);
3885 ad1884a_laptop_automute(codec);
3886 ad1884a_laptop_automic(codec);
3887 return 0;
3888}
3889
Takashi Iwaic5059252008-02-16 09:43:56 +01003890/* additional verbs for laptop model */
3891static struct hda_verb ad1884a_laptop_verbs[] = {
3892 /* Port-A (HP) pin - always unmuted */
3893 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3894 /* Port-F (int speaker) mixer - route only from analog mixer */
3895 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3896 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08003897 /* Port-F (int speaker) pin */
3898 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01003899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08003900 /* required for compaq 6530s/6531s speaker output */
3901 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003902 /* Port-C pin - internal mic-in */
3903 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3904 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3905 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02003906 /* Port-D (docking line-out) pin - default unmuted */
3907 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01003908 /* analog mix */
3909 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3910 /* unsolicited event for pin-sense */
3911 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003912 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003913 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003914 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02003915 /* allow to touch GPIO1 (for mute control) */
3916 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3917 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3918 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01003919 { } /* end */
3920};
3921
Takashi Iwai73156132009-04-23 08:24:48 +02003922static struct hda_verb ad1884a_mobile_verbs[] = {
3923 /* DACs; unmute as default */
3924 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3925 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3926 /* Port-A (HP) mixer - route only from analog mixer */
3927 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3928 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3929 /* Port-A pin */
3930 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3931 /* Port-A (HP) pin - always unmuted */
3932 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3933 /* Port-B (mic jack) pin */
3934 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3935 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3936 /* Port-C (int mic) pin */
3937 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3938 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3939 /* Port-F (int speaker) mixer - route only from analog mixer */
3940 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3941 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3942 /* Port-F pin */
3943 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3944 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3945 /* Analog mixer; mute as default */
3946 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3947 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3948 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3949 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3950 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3951 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3952 /* Analog Mix output amp */
3953 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3954 /* capture sources */
3955 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3956 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3957 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3958 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3959 /* unsolicited event for pin-sense */
3960 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3961 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db172009-07-02 16:10:23 +02003962 /* allow to touch GPIO1 (for mute control) */
3963 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3964 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3965 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02003966 { } /* end */
3967};
3968
Takashi Iwaic5059252008-02-16 09:43:56 +01003969/*
Takashi Iwaif0813742008-03-18 12:13:03 +01003970 * Thinkpad X300
3971 * 0x11 - HP
3972 * 0x12 - speaker
3973 * 0x14 - mic-in
3974 * 0x17 - built-in mic
3975 */
3976
3977static struct hda_verb ad1984a_thinkpad_verbs[] = {
3978 /* HP unmute */
3979 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3980 /* analog mix */
3981 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3982 /* turn on EAPD */
3983 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3984 /* unsolicited event for pin-sense */
3985 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3986 /* internal mic - dmic */
3987 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02003988 /* set magic COEFs for dmic */
3989 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3990 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01003991 { } /* end */
3992};
3993
3994static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3995 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3996 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3997 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3998 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3999 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4000 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01004001 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
4002 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4003 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4004 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4005 {
4006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4007 .name = "Capture Source",
4008 .info = ad198x_mux_enum_info,
4009 .get = ad198x_mux_enum_get,
4010 .put = ad198x_mux_enum_put,
4011 },
4012 { } /* end */
4013};
4014
4015static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4016 .num_items = 3,
4017 .items = {
4018 { "Mic", 0x0 },
4019 { "Internal Mic", 0x5 },
4020 { "Mix", 0x3 },
4021 },
4022};
4023
4024/* mute internal speaker if HP is plugged */
4025static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4026{
4027 unsigned int present;
4028
Takashi Iwaid56757a2009-11-18 08:00:14 +01004029 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004030 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4031 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4032}
4033
4034/* unsolicited event for HP jack sensing */
4035static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4036 unsigned int res)
4037{
4038 if ((res >> 26) != AD1884A_HP_EVENT)
4039 return;
4040 ad1984a_thinkpad_automute(codec);
4041}
4042
4043/* initialize jack-sensing, too */
4044static int ad1984a_thinkpad_init(struct hda_codec *codec)
4045{
4046 ad198x_init(codec);
4047 ad1984a_thinkpad_automute(codec);
4048 return 0;
4049}
4050
4051/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004052 * HP Touchsmart
4053 * port-A (0x11) - front hp-out
4054 * port-B (0x14) - unused
4055 * port-C (0x15) - unused
4056 * port-D (0x12) - rear line out
4057 * port-E (0x1c) - front mic-in
4058 * port-F (0x16) - Internal speakers
4059 * digital-mic (0x17) - Internal mic
4060 */
4061
4062static struct hda_verb ad1984a_touchsmart_verbs[] = {
4063 /* DACs; unmute as default */
4064 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4065 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4066 /* Port-A (HP) mixer - route only from analog mixer */
4067 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4068 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4069 /* Port-A pin */
4070 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4071 /* Port-A (HP) pin - always unmuted */
4072 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4073 /* Port-E (int speaker) mixer - route only from analog mixer */
4074 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4075 /* Port-E pin */
4076 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4077 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4078 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4079 /* Port-F (int speaker) mixer - route only from analog mixer */
4080 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4081 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4082 /* Port-F pin */
4083 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4084 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4085 /* Analog mixer; mute as default */
4086 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4087 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4088 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4089 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4090 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4091 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4092 /* Analog Mix output amp */
4093 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4094 /* capture sources */
4095 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4096 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4097 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4098 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4099 /* unsolicited event for pin-sense */
4100 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4101 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4102 /* allow to touch GPIO1 (for mute control) */
4103 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4104 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4105 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4106 /* internal mic - dmic */
4107 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4108 /* set magic COEFs for dmic */
4109 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4110 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4111 { } /* end */
4112};
4113
4114static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4115 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4116/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4117 {
4118 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4119 .name = "Master Playback Switch",
4120 .info = snd_hda_mixer_amp_switch_info,
4121 .get = snd_hda_mixer_amp_switch_get,
4122 .put = ad1884a_mobile_master_sw_put,
4123 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4124 },
4125 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4126 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4127 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4128 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4129 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4130 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4131 { } /* end */
4132};
4133
4134/* switch to external mic if plugged */
4135static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4136{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004137 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004138 snd_hda_codec_write(codec, 0x0c, 0,
4139 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004140 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004141 snd_hda_codec_write(codec, 0x0c, 0,
4142 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004143}
4144
4145
4146/* unsolicited event for HP jack sensing */
4147static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4148 unsigned int res)
4149{
4150 switch (res >> 26) {
4151 case AD1884A_HP_EVENT:
4152 ad1884a_hp_automute(codec);
4153 break;
4154 case AD1884A_MIC_EVENT:
4155 ad1984a_touchsmart_automic(codec);
4156 break;
4157 }
4158}
4159
4160/* initialize jack-sensing, too */
4161static int ad1984a_touchsmart_init(struct hda_codec *codec)
4162{
4163 ad198x_init(codec);
4164 ad1884a_hp_automute(codec);
4165 ad1984a_touchsmart_automic(codec);
4166 return 0;
4167}
4168
4169
4170/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004171 */
4172
4173enum {
4174 AD1884A_DESKTOP,
4175 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004176 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004177 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004178 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004179 AD1884A_MODELS
4180};
4181
4182static const char *ad1884a_models[AD1884A_MODELS] = {
4183 [AD1884A_DESKTOP] = "desktop",
4184 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004185 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004186 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004187 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004188};
4189
4190static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4191 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004192 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004193 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004194 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004195 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004196 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4197 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004198 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004199 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004200 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004201 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004202};
4203
4204static int patch_ad1884a(struct hda_codec *codec)
4205{
4206 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004207 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004208
4209 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4210 if (spec == NULL)
4211 return -ENOMEM;
4212
Takashi Iwaic5059252008-02-16 09:43:56 +01004213 codec->spec = spec;
4214
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004215 err = snd_hda_attach_beep_device(codec, 0x10);
4216 if (err < 0) {
4217 ad198x_free(codec);
4218 return err;
4219 }
4220 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4221
Takashi Iwaic5059252008-02-16 09:43:56 +01004222 spec->multiout.max_channels = 2;
4223 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4224 spec->multiout.dac_nids = ad1884a_dac_nids;
4225 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4226 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4227 spec->adc_nids = ad1884a_adc_nids;
4228 spec->capsrc_nids = ad1884a_capsrc_nids;
4229 spec->input_mux = &ad1884a_capture_source;
4230 spec->num_mixers = 1;
4231 spec->mixers[0] = ad1884a_base_mixers;
4232 spec->num_init_verbs = 1;
4233 spec->init_verbs[0] = ad1884a_init_verbs;
4234 spec->spdif_route = 0;
4235#ifdef CONFIG_SND_HDA_POWER_SAVE
4236 spec->loopback.amplist = ad1884a_loopbacks;
4237#endif
4238 codec->patch_ops = ad198x_patch_ops;
4239
4240 /* override some parameters */
4241 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004242 ad1884a_models,
4243 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004244 switch (board_config) {
4245 case AD1884A_LAPTOP:
4246 spec->mixers[0] = ad1884a_laptop_mixers;
4247 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4248 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004249 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4250 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004251 /* set the upper-limit for mixer amp to 0dB for avoiding the
4252 * possible damage by overloading
4253 */
4254 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4255 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4256 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4257 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4258 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004259 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004260 case AD1884A_MOBILE:
4261 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004262 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004263 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004264 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4265 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004266 /* set the upper-limit for mixer amp to 0dB for avoiding the
4267 * possible damage by overloading
4268 */
4269 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4270 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4271 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4272 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4273 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004274 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004275 case AD1884A_THINKPAD:
4276 spec->mixers[0] = ad1984a_thinkpad_mixers;
4277 spec->init_verbs[spec->num_init_verbs++] =
4278 ad1984a_thinkpad_verbs;
4279 spec->multiout.dig_out_nid = 0;
4280 spec->input_mux = &ad1984a_thinkpad_capture_source;
4281 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4282 codec->patch_ops.init = ad1984a_thinkpad_init;
4283 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004284 case AD1984A_TOUCHSMART:
4285 spec->mixers[0] = ad1984a_touchsmart_mixers;
4286 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4287 spec->multiout.dig_out_nid = 0;
4288 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4289 codec->patch_ops.init = ad1984a_touchsmart_init;
4290 /* set the upper-limit for mixer amp to 0dB for avoiding the
4291 * possible damage by overloading
4292 */
4293 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4294 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4295 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4296 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4297 (1 << AC_AMPCAP_MUTE_SHIFT));
4298 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004299 }
4300
Takashi Iwai729d55b2009-12-25 22:49:01 +01004301 codec->no_trigger_sense = 1;
4302
Takashi Iwaic5059252008-02-16 09:43:56 +01004303 return 0;
4304}
4305
4306
4307/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004308 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004309 *
4310 * port-A - front hp-out
4311 * port-B - front mic-in
4312 * port-C - rear line-in, shared surr-out (3stack)
4313 * port-D - rear line-out
4314 * port-E - rear mic-in, shared clfe-out (3stack)
4315 * port-F - rear surr-out (6stack)
4316 * port-G - rear clfe-out (6stack)
4317 */
4318
4319static hda_nid_t ad1882_dac_nids[3] = {
4320 0x04, 0x03, 0x05
4321};
4322
4323static hda_nid_t ad1882_adc_nids[2] = {
4324 0x08, 0x09,
4325};
4326
4327static hda_nid_t ad1882_capsrc_nids[2] = {
4328 0x0c, 0x0d,
4329};
4330
4331#define AD1882_SPDIF_OUT 0x02
4332
4333/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4334static struct hda_input_mux ad1882_capture_source = {
4335 .num_items = 5,
4336 .items = {
4337 { "Front Mic", 0x1 },
4338 { "Mic", 0x4 },
4339 { "Line", 0x2 },
4340 { "CD", 0x3 },
4341 { "Mix", 0x7 },
4342 },
4343};
4344
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004345/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4346static struct hda_input_mux ad1882a_capture_source = {
4347 .num_items = 5,
4348 .items = {
4349 { "Front Mic", 0x1 },
4350 { "Mic", 0x4},
4351 { "Line", 0x2 },
4352 { "Digital Mic", 0x06 },
4353 { "Mix", 0x7 },
4354 },
4355};
4356
Takashi Iwai0ac85512007-06-20 15:46:13 +02004357static struct snd_kcontrol_new ad1882_base_mixers[] = {
4358 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4359 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4360 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4361 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4362 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4363 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4364 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4365 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004366
Takashi Iwai0ac85512007-06-20 15:46:13 +02004367 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4368 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4369 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4370 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4371 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4372 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4373 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4374 {
4375 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4376 /* The multiple "Capture Source" controls confuse alsamixer
4377 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004378 */
4379 /* .name = "Capture Source", */
4380 .name = "Input Source",
4381 .count = 2,
4382 .info = ad198x_mux_enum_info,
4383 .get = ad198x_mux_enum_get,
4384 .put = ad198x_mux_enum_put,
4385 },
4386 /* SPDIF controls */
4387 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4388 {
4389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4390 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4391 /* identical with ad1983 */
4392 .info = ad1983_spdif_route_info,
4393 .get = ad1983_spdif_route_get,
4394 .put = ad1983_spdif_route_put,
4395 },
4396 { } /* end */
4397};
4398
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004399static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4400 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4401 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4402 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4403 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4404 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4405 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4406 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4407 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004408 { } /* end */
4409};
4410
4411static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4412 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4413 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4414 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4415 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4416 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4417 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4418 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4419 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004420 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4421 { } /* end */
4422};
4423
Takashi Iwai0ac85512007-06-20 15:46:13 +02004424static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4425 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4426 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4427 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4428 {
4429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4430 .name = "Channel Mode",
4431 .info = ad198x_ch_mode_info,
4432 .get = ad198x_ch_mode_get,
4433 .put = ad198x_ch_mode_put,
4434 },
4435 { } /* end */
4436};
4437
4438static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4439 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4440 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4441 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4442 { } /* end */
4443};
4444
4445static struct hda_verb ad1882_ch2_init[] = {
4446 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4447 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4448 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4449 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4450 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4451 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4452 { } /* end */
4453};
4454
4455static struct hda_verb ad1882_ch4_init[] = {
4456 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4457 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4458 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4459 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4460 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4461 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4462 { } /* end */
4463};
4464
4465static struct hda_verb ad1882_ch6_init[] = {
4466 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4467 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4468 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4469 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4470 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4471 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4472 { } /* end */
4473};
4474
4475static struct hda_channel_mode ad1882_modes[3] = {
4476 { 2, ad1882_ch2_init },
4477 { 4, ad1882_ch4_init },
4478 { 6, ad1882_ch6_init },
4479};
4480
4481/*
4482 * initialization verbs
4483 */
4484static struct hda_verb ad1882_init_verbs[] = {
4485 /* DACs; mute as default */
4486 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4487 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4489 /* Port-A (HP) mixer */
4490 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4491 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4492 /* Port-A pin */
4493 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4494 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4495 /* HP selector - select DAC2 */
4496 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4497 /* Port-D (Line-out) mixer */
4498 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4499 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4500 /* Port-D pin */
4501 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4502 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4503 /* Mono-out mixer */
4504 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4505 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4506 /* Mono-out pin */
4507 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4508 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4509 /* Port-B (front mic) pin */
4510 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4511 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4512 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4513 /* Port-C (line-in) pin */
4514 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4515 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4516 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4517 /* Port-C mixer - mute as input */
4518 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4519 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4520 /* Port-E (mic-in) pin */
4521 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4522 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4523 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4524 /* Port-E mixer - mute as input */
4525 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4526 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4527 /* Port-F (surround) */
4528 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4529 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4530 /* Port-G (CLFE) */
4531 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4532 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4533 /* Analog mixer; mute as default */
4534 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4535 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4536 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4537 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4538 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4539 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4540 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4541 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4542 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4543 /* Analog Mix output amp */
4544 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4545 /* SPDIF output selector */
4546 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4547 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4548 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4549 { } /* end */
4550};
4551
Takashi Iwaicb53c622007-08-10 17:21:45 +02004552#ifdef CONFIG_SND_HDA_POWER_SAVE
4553static struct hda_amp_list ad1882_loopbacks[] = {
4554 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4555 { 0x20, HDA_INPUT, 1 }, /* Mic */
4556 { 0x20, HDA_INPUT, 4 }, /* Line */
4557 { 0x20, HDA_INPUT, 6 }, /* CD */
4558 { } /* end */
4559};
4560#endif
4561
Takashi Iwai0ac85512007-06-20 15:46:13 +02004562/* models */
4563enum {
4564 AD1882_3STACK,
4565 AD1882_6STACK,
4566 AD1882_MODELS
4567};
4568
4569static const char *ad1882_models[AD1986A_MODELS] = {
4570 [AD1882_3STACK] = "3stack",
4571 [AD1882_6STACK] = "6stack",
4572};
4573
4574
4575static int patch_ad1882(struct hda_codec *codec)
4576{
4577 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004578 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004579
4580 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4581 if (spec == NULL)
4582 return -ENOMEM;
4583
Takashi Iwai0ac85512007-06-20 15:46:13 +02004584 codec->spec = spec;
4585
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004586 err = snd_hda_attach_beep_device(codec, 0x10);
4587 if (err < 0) {
4588 ad198x_free(codec);
4589 return err;
4590 }
4591 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4592
Takashi Iwai0ac85512007-06-20 15:46:13 +02004593 spec->multiout.max_channels = 6;
4594 spec->multiout.num_dacs = 3;
4595 spec->multiout.dac_nids = ad1882_dac_nids;
4596 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4597 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4598 spec->adc_nids = ad1882_adc_nids;
4599 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004600 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004601 spec->input_mux = &ad1882_capture_source;
4602 else
4603 spec->input_mux = &ad1882a_capture_source;
4604 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004605 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004606 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004607 spec->mixers[1] = ad1882_loopback_mixers;
4608 else
4609 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004610 spec->num_init_verbs = 1;
4611 spec->init_verbs[0] = ad1882_init_verbs;
4612 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004613#ifdef CONFIG_SND_HDA_POWER_SAVE
4614 spec->loopback.amplist = ad1882_loopbacks;
4615#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004616 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004617
4618 codec->patch_ops = ad198x_patch_ops;
4619
4620 /* override some parameters */
4621 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4622 ad1882_models, NULL);
4623 switch (board_config) {
4624 default:
4625 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004626 spec->num_mixers = 3;
4627 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004628 spec->channel_mode = ad1882_modes;
4629 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4630 spec->need_dac_fix = 1;
4631 spec->multiout.max_channels = 2;
4632 spec->multiout.num_dacs = 1;
4633 break;
4634 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004635 spec->num_mixers = 3;
4636 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004637 break;
4638 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01004639
4640 codec->no_trigger_sense = 1;
4641
Takashi Iwai0ac85512007-06-20 15:46:13 +02004642 return 0;
4643}
4644
4645
4646/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 * patch entries
4648 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004649static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004650 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004651 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004652 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004653 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004654 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4655 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004656 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4657 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004658 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004660 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004661 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004662 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004663 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4664 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 {} /* terminator */
4666};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004667
4668MODULE_ALIAS("snd-hda-codec-id:11d4*");
4669
4670MODULE_LICENSE("GPL");
4671MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4672
4673static struct hda_codec_preset_list analog_list = {
4674 .preset = snd_hda_preset_analog,
4675 .owner = THIS_MODULE,
4676};
4677
4678static int __init patch_analog_init(void)
4679{
4680 return snd_hda_add_codec_preset(&analog_list);
4681}
4682
4683static void __exit patch_analog_exit(void)
4684{
4685 snd_hda_delete_codec_preset(&analog_list);
4686}
4687
4688module_init(patch_analog_init)
4689module_exit(patch_analog_exit)