blob: 1a36137e13eca5f3d488402da0084500fa4489bc [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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwai825aa9722006-03-17 10:50:49 +0100661/* laptop-eapd model - 2ch only */
662
Takashi Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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 Iwai825aa9722006-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
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 return 0;
1190}
1191
1192/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001193 * AD1983 specific
1194 */
1195
1196#define AD1983_SPDIF_OUT 0x02
1197#define AD1983_DAC 0x03
1198#define AD1983_ADC 0x04
1199
1200static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001201static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001202static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001203
1204static struct hda_input_mux ad1983_capture_source = {
1205 .num_items = 4,
1206 .items = {
1207 { "Mic", 0x0 },
1208 { "Line", 0x1 },
1209 { "Mix", 0x2 },
1210 { "Mix Mono", 0x3 },
1211 },
1212};
1213
1214/*
1215 * SPDIF playback route
1216 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001217static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001218{
1219 static char *texts[] = { "PCM", "ADC" };
1220
1221 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1222 uinfo->count = 1;
1223 uinfo->value.enumerated.items = 2;
1224 if (uinfo->value.enumerated.item > 1)
1225 uinfo->value.enumerated.item = 1;
1226 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1227 return 0;
1228}
1229
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001230static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001231{
1232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1233 struct ad198x_spec *spec = codec->spec;
1234
1235 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1236 return 0;
1237}
1238
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001239static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001240{
1241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1242 struct ad198x_spec *spec = codec->spec;
1243
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001244 if (ucontrol->value.enumerated.item[0] > 1)
1245 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001246 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1247 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001248 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1249 AC_VERB_SET_CONNECT_SEL,
1250 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001251 return 1;
1252 }
1253 return 0;
1254}
1255
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001256static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001257 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1258 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1259 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1261 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1262 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001269 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1271 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1272 {
1273 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1274 .name = "Capture Source",
1275 .info = ad198x_mux_enum_info,
1276 .get = ad198x_mux_enum_get,
1277 .put = ad198x_mux_enum_put,
1278 },
1279 {
1280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001281 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001282 .info = ad1983_spdif_route_info,
1283 .get = ad1983_spdif_route_get,
1284 .put = ad1983_spdif_route_put,
1285 },
1286 { } /* end */
1287};
1288
1289static struct hda_verb ad1983_init_verbs[] = {
1290 /* Front, HP, Mono; mute as default */
1291 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1292 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1293 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1294 /* Beep, PCM, Mic, Line-In: mute */
1295 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1296 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1297 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1298 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1299 /* Front, HP selectors; from Mix */
1300 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1301 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1302 /* Mono selector; from Mix */
1303 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1304 /* Mic selector; Mic */
1305 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1306 /* Line-in selector: Line-in */
1307 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1308 /* Mic boost: 0dB */
1309 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1310 /* Record selector: mic */
1311 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1312 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1313 /* SPDIF route: PCM */
1314 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1315 /* Front Pin */
1316 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1317 /* HP Pin */
1318 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1319 /* Mono Pin */
1320 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1321 /* Mic Pin */
1322 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1323 /* Line Pin */
1324 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1325 { } /* end */
1326};
1327
Takashi Iwaicb53c622007-08-10 17:21:45 +02001328#ifdef CONFIG_SND_HDA_POWER_SAVE
1329static struct hda_amp_list ad1983_loopbacks[] = {
1330 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1331 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1332 { } /* end */
1333};
1334#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001335
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001336static int patch_ad1983(struct hda_codec *codec)
1337{
1338 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001339 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001340
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001341 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001342 if (spec == NULL)
1343 return -ENOMEM;
1344
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001345 codec->spec = spec;
1346
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001347 err = snd_hda_attach_beep_device(codec, 0x10);
1348 if (err < 0) {
1349 ad198x_free(codec);
1350 return err;
1351 }
1352 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1353
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001354 spec->multiout.max_channels = 2;
1355 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1356 spec->multiout.dac_nids = ad1983_dac_nids;
1357 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001358 spec->num_adc_nids = 1;
1359 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001360 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001361 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001362 spec->num_mixers = 1;
1363 spec->mixers[0] = ad1983_mixers;
1364 spec->num_init_verbs = 1;
1365 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001366 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001367#ifdef CONFIG_SND_HDA_POWER_SAVE
1368 spec->loopback.amplist = ad1983_loopbacks;
1369#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001370 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001371
1372 codec->patch_ops = ad198x_patch_ops;
1373
1374 return 0;
1375}
1376
1377
1378/*
1379 * AD1981 HD specific
1380 */
1381
1382#define AD1981_SPDIF_OUT 0x02
1383#define AD1981_DAC 0x03
1384#define AD1981_ADC 0x04
1385
1386static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001387static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001388static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001389
1390/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1391static struct hda_input_mux ad1981_capture_source = {
1392 .num_items = 7,
1393 .items = {
1394 { "Front Mic", 0x0 },
1395 { "Line", 0x1 },
1396 { "Mix", 0x2 },
1397 { "Mix Mono", 0x3 },
1398 { "CD", 0x4 },
1399 { "Mic", 0x6 },
1400 { "Aux", 0x7 },
1401 },
1402};
1403
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001404static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001405 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1406 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001423 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1427 {
1428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1429 .name = "Capture Source",
1430 .info = ad198x_mux_enum_info,
1431 .get = ad198x_mux_enum_get,
1432 .put = ad198x_mux_enum_put,
1433 },
1434 /* identical with AD1983 */
1435 {
1436 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001437 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001438 .info = ad1983_spdif_route_info,
1439 .get = ad1983_spdif_route_get,
1440 .put = ad1983_spdif_route_put,
1441 },
1442 { } /* end */
1443};
1444
1445static struct hda_verb ad1981_init_verbs[] = {
1446 /* Front, HP, Mono; mute as default */
1447 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1448 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1449 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1450 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1451 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1452 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1453 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1455 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1458 /* Front, HP selectors; from Mix */
1459 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1460 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1461 /* Mono selector; from Mix */
1462 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1463 /* Mic Mixer; select Front Mic */
1464 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1465 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1466 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001467 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1468 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001469 /* Record selector: Front mic */
1470 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1471 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1472 /* SPDIF route: PCM */
1473 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1474 /* Front Pin */
1475 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1476 /* HP Pin */
1477 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1478 /* Mono Pin */
1479 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1480 /* Front & Rear Mic Pins */
1481 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1482 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1483 /* Line Pin */
1484 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1485 /* Digital Beep */
1486 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1487 /* Line-Out as Input: disabled */
1488 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1489 { } /* end */
1490};
1491
Takashi Iwaicb53c622007-08-10 17:21:45 +02001492#ifdef CONFIG_SND_HDA_POWER_SAVE
1493static struct hda_amp_list ad1981_loopbacks[] = {
1494 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1495 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1496 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1497 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1498 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1499 { } /* end */
1500};
1501#endif
1502
Takashi Iwai18a815d2006-03-01 19:54:39 +01001503/*
1504 * Patch for HP nx6320
1505 *
Tobin Davis18768992007-03-12 22:20:51 +01001506 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001507 * speaker output enabled _and_ mute-LED off.
1508 */
1509
1510#define AD1981_HP_EVENT 0x37
1511#define AD1981_MIC_EVENT 0x38
1512
1513static struct hda_verb ad1981_hp_init_verbs[] = {
1514 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1515 /* pin sensing on HP and Mic jacks */
1516 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1517 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1518 {}
1519};
1520
1521/* turn on/off EAPD (+ mute HP) as a master switch */
1522static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1523 struct snd_ctl_elem_value *ucontrol)
1524{
1525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1526 struct ad198x_spec *spec = codec->spec;
1527
1528 if (! ad198x_eapd_put(kcontrol, ucontrol))
1529 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001530 /* change speaker pin appropriately */
1531 snd_hda_codec_write(codec, 0x05, 0,
1532 AC_VERB_SET_PIN_WIDGET_CONTROL,
1533 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001534 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001535 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1536 HDA_AMP_MUTE,
1537 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001538 return 1;
1539}
1540
1541/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001542static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1543 .ops = &snd_hda_bind_vol,
1544 .values = {
1545 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1546 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1547 0
1548 },
1549};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001550
1551/* mute internal speaker if HP is plugged */
1552static void ad1981_hp_automute(struct hda_codec *codec)
1553{
1554 unsigned int present;
1555
Takashi Iwaid56757a2009-11-18 08:00:14 +01001556 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001557 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1558 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001559}
1560
1561/* toggle input of built-in and mic jack appropriately */
1562static void ad1981_hp_automic(struct hda_codec *codec)
1563{
1564 static struct hda_verb mic_jack_on[] = {
1565 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1566 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1567 {}
1568 };
1569 static struct hda_verb mic_jack_off[] = {
1570 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1571 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1572 {}
1573 };
1574 unsigned int present;
1575
Takashi Iwaid56757a2009-11-18 08:00:14 +01001576 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001577 if (present)
1578 snd_hda_sequence_write(codec, mic_jack_on);
1579 else
1580 snd_hda_sequence_write(codec, mic_jack_off);
1581}
1582
1583/* unsolicited event for HP jack sensing */
1584static void ad1981_hp_unsol_event(struct hda_codec *codec,
1585 unsigned int res)
1586{
1587 res >>= 26;
1588 switch (res) {
1589 case AD1981_HP_EVENT:
1590 ad1981_hp_automute(codec);
1591 break;
1592 case AD1981_MIC_EVENT:
1593 ad1981_hp_automic(codec);
1594 break;
1595 }
1596}
1597
1598static struct hda_input_mux ad1981_hp_capture_source = {
1599 .num_items = 3,
1600 .items = {
1601 { "Mic", 0x0 },
1602 { "Docking-Station", 0x1 },
1603 { "Mix", 0x2 },
1604 },
1605};
1606
1607static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001608 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001609 {
1610 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1611 .name = "Master Playback Switch",
1612 .info = ad198x_eapd_info,
1613 .get = ad198x_eapd_get,
1614 .put = ad1981_hp_master_sw_put,
1615 .private_value = 0x05,
1616 },
1617 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1618 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1619#if 0
1620 /* FIXME: analog mic/line loopback doesn't work with my tests...
1621 * (although recording is OK)
1622 */
1623 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1624 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1625 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1626 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1627 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1629 /* FIXME: does this laptop have analog CD connection? */
1630 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1632#endif
1633 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1634 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1635 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1636 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1637 {
1638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1639 .name = "Capture Source",
1640 .info = ad198x_mux_enum_info,
1641 .get = ad198x_mux_enum_get,
1642 .put = ad198x_mux_enum_put,
1643 },
1644 { } /* end */
1645};
1646
1647/* initialize jack-sensing, too */
1648static int ad1981_hp_init(struct hda_codec *codec)
1649{
1650 ad198x_init(codec);
1651 ad1981_hp_automute(codec);
1652 ad1981_hp_automic(codec);
1653 return 0;
1654}
1655
Tobin Davis18768992007-03-12 22:20:51 +01001656/* configuration for Toshiba Laptops */
1657static struct hda_verb ad1981_toshiba_init_verbs[] = {
1658 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1659 /* pin sensing on HP and Mic jacks */
1660 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1661 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1662 {}
1663};
1664
1665static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1666 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1667 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1668 { }
1669};
1670
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001671/* configuration for Lenovo Thinkpad T60 */
1672static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1673 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1674 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1675 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1676 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1677 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1678 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1681 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1682 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1683 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1684 {
1685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1686 .name = "Capture Source",
1687 .info = ad198x_mux_enum_info,
1688 .get = ad198x_mux_enum_get,
1689 .put = ad198x_mux_enum_put,
1690 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001691 /* identical with AD1983 */
1692 {
1693 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1694 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1695 .info = ad1983_spdif_route_info,
1696 .get = ad1983_spdif_route_get,
1697 .put = ad1983_spdif_route_put,
1698 },
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001699 { } /* end */
1700};
1701
1702static struct hda_input_mux ad1981_thinkpad_capture_source = {
1703 .num_items = 3,
1704 .items = {
1705 { "Mic", 0x0 },
1706 { "Mix", 0x2 },
1707 { "CD", 0x4 },
1708 },
1709};
1710
Takashi Iwai18a815d2006-03-01 19:54:39 +01001711/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001712enum {
1713 AD1981_BASIC,
1714 AD1981_HP,
1715 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001716 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001717 AD1981_MODELS
1718};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001719
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001720static const char *ad1981_models[AD1981_MODELS] = {
1721 [AD1981_HP] = "hp",
1722 [AD1981_THINKPAD] = "thinkpad",
1723 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001724 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001725};
1726
1727static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001728 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001729 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001730 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001731 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001732 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001733 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001734 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001735 /* HP nx6320 (reversed SSID, H/W bug) */
1736 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001737 {}
1738};
1739
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001740static int patch_ad1981(struct hda_codec *codec)
1741{
1742 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001743 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001744
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001745 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001746 if (spec == NULL)
1747 return -ENOMEM;
1748
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001749 codec->spec = spec;
1750
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001751 err = snd_hda_attach_beep_device(codec, 0x10);
1752 if (err < 0) {
1753 ad198x_free(codec);
1754 return err;
1755 }
1756 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1757
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001758 spec->multiout.max_channels = 2;
1759 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1760 spec->multiout.dac_nids = ad1981_dac_nids;
1761 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001762 spec->num_adc_nids = 1;
1763 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001764 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001765 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001766 spec->num_mixers = 1;
1767 spec->mixers[0] = ad1981_mixers;
1768 spec->num_init_verbs = 1;
1769 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001770 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001771#ifdef CONFIG_SND_HDA_POWER_SAVE
1772 spec->loopback.amplist = ad1981_loopbacks;
1773#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001774 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001775
1776 codec->patch_ops = ad198x_patch_ops;
1777
Takashi Iwai18a815d2006-03-01 19:54:39 +01001778 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001779 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1780 ad1981_models,
1781 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001782 switch (board_config) {
1783 case AD1981_HP:
1784 spec->mixers[0] = ad1981_hp_mixers;
1785 spec->num_init_verbs = 2;
1786 spec->init_verbs[1] = ad1981_hp_init_verbs;
1787 spec->multiout.dig_out_nid = 0;
1788 spec->input_mux = &ad1981_hp_capture_source;
1789
1790 codec->patch_ops.init = ad1981_hp_init;
1791 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
Daniel T Chen01f59662009-12-13 16:22:58 -05001792 /* set the upper-limit for mixer amp to 0dB for avoiding the
1793 * possible damage by overloading
1794 */
1795 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1796 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1797 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1798 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1799 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai18a815d2006-03-01 19:54:39 +01001800 break;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001801 case AD1981_THINKPAD:
1802 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001803 spec->input_mux = &ad1981_thinkpad_capture_source;
1804 break;
Tobin Davis18768992007-03-12 22:20:51 +01001805 case AD1981_TOSHIBA:
1806 spec->mixers[0] = ad1981_hp_mixers;
1807 spec->mixers[1] = ad1981_toshiba_mixers;
1808 spec->num_init_verbs = 2;
1809 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1810 spec->multiout.dig_out_nid = 0;
1811 spec->input_mux = &ad1981_hp_capture_source;
1812 codec->patch_ops.init = ad1981_hp_init;
1813 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1814 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001815 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001816 return 0;
1817}
1818
1819
1820/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001821 * AD1988
1822 *
1823 * Output pins and routes
1824 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001825 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001826 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1827 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1828 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1829 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1830 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1831 * port-F 0x16 (mute) <- 0x2a <- 06
1832 * port-G 0x24 (mute) <- 0x27 <- 05
1833 * port-H 0x25 (mute) <- 0x28 <- 0a
1834 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1835 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001836 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1837 * (*) 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 +01001838 *
1839 * Input pins and routes
1840 *
1841 * pin boost mix input # / adc input #
1842 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1843 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1844 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1845 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1846 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1847 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1848 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1849 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1850 *
1851 *
1852 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001853 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001854 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001855 *
1856 * Inputs of Analog Mix (0x20)
1857 * 0:Port-B (front mic)
1858 * 1:Port-C/G/H (line-in)
1859 * 2:Port-A
1860 * 3:Port-D (line-in/2)
1861 * 4:Port-E/G/H (mic-in)
1862 * 5:Port-F (mic2-in)
1863 * 6:CD
1864 * 7:Beep
1865 *
1866 * ADC selection
1867 * 0:Port-A
1868 * 1:Port-B (front mic-in)
1869 * 2:Port-C (line-in)
1870 * 3:Port-F (mic2-in)
1871 * 4:Port-E (mic-in)
1872 * 5:CD
1873 * 6:Port-G
1874 * 7:Port-H
1875 * 8:Port-D (line-in/2)
1876 * 9:Mix
1877 *
1878 * Proposed pin assignments by the datasheet
1879 *
1880 * 6-stack
1881 * Port-A front headphone
1882 * B front mic-in
1883 * C rear line-in
1884 * D rear front-out
1885 * E rear mic-in
1886 * F rear surround
1887 * G rear CLFE
1888 * H rear side
1889 *
1890 * 3-stack
1891 * Port-A front headphone
1892 * B front mic
1893 * C rear line-in/surround
1894 * D rear front-out
1895 * E rear mic-in/CLFE
1896 *
1897 * laptop
1898 * Port-A headphone
1899 * B mic-in
1900 * C docking station
1901 * D internal speaker (with EAPD)
1902 * E/F quad mic array
1903 */
1904
1905
1906/* models */
1907enum {
1908 AD1988_6STACK,
1909 AD1988_6STACK_DIG,
1910 AD1988_3STACK,
1911 AD1988_3STACK_DIG,
1912 AD1988_LAPTOP,
1913 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001914 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001915 AD1988_MODEL_LAST,
1916};
1917
Takashi Iwaid32410b12005-11-24 16:06:23 +01001918/* reivision id to check workarounds */
1919#define AD1988A_REV2 0x100200
1920
Takashi Iwai1a806f42006-07-03 15:58:16 +02001921#define is_rev2(codec) \
1922 ((codec)->vendor_id == 0x11d41988 && \
1923 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001924
1925/*
1926 * mixers
1927 */
1928
Takashi Iwaid32410b12005-11-24 16:06:23 +01001929static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001930 0x04, 0x06, 0x05, 0x0a
1931};
1932
Takashi Iwaid32410b12005-11-24 16:06:23 +01001933static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001934 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001935};
1936
1937/* for AD1988A revision-2, DAC2-4 are swapped */
1938static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1939 0x04, 0x05, 0x0a, 0x06
1940};
1941
1942static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001943 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001944};
1945
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001946static hda_nid_t ad1988_adc_nids[3] = {
1947 0x08, 0x09, 0x0f
1948};
1949
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001950static hda_nid_t ad1988_capsrc_nids[3] = {
1951 0x0c, 0x0d, 0x0e
1952};
1953
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001954#define AD1988_SPDIF_OUT 0x02
1955#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001956#define AD1988_SPDIF_IN 0x07
1957
Takashi Iwai3a08e302009-02-13 11:37:08 +01001958static hda_nid_t ad1989b_slave_dig_outs[] = {
1959 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001960};
1961
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001962static struct hda_input_mux ad1988_6stack_capture_source = {
1963 .num_items = 5,
1964 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001965 { "Front Mic", 0x1 }, /* port-B */
1966 { "Line", 0x2 }, /* port-C */
1967 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001968 { "CD", 0x5 },
1969 { "Mix", 0x9 },
1970 },
1971};
1972
1973static struct hda_input_mux ad1988_laptop_capture_source = {
1974 .num_items = 3,
1975 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001976 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001977 { "CD", 0x5 },
1978 { "Mix", 0x9 },
1979 },
1980};
1981
1982/*
1983 */
1984static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1985 struct snd_ctl_elem_info *uinfo)
1986{
1987 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1988 struct ad198x_spec *spec = codec->spec;
1989 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1990 spec->num_channel_mode);
1991}
1992
1993static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1994 struct snd_ctl_elem_value *ucontrol)
1995{
1996 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1997 struct ad198x_spec *spec = codec->spec;
1998 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1999 spec->num_channel_mode, spec->multiout.max_channels);
2000}
2001
2002static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_value *ucontrol)
2004{
2005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2006 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002007 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2008 spec->num_channel_mode,
2009 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002010 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002011 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002012 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002013}
2014
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002015/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002016static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002017 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2018 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2019 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2020 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2021 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002022 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002023};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002024
Takashi Iwaid32410b12005-11-24 16:06:23 +01002025static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2026 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2027 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2028 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2029 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2030 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002031 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002032};
2033
2034static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002035 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2036 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2037 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2038 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2039 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2040 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2041 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2042
2043 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2044 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2045 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2046 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2047 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2048 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2049 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2050 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2051
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002052 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002053 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2054
2055 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2056 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2057
2058 { } /* end */
2059};
2060
2061/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002062static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002063 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002064 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002065 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2066 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002067 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002068};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002069
Takashi Iwaid32410b12005-11-24 16:06:23 +01002070static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2071 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002072 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2073 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2074 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002075 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002076};
2077
2078static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002079 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002080 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2081 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2082 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002083 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2084 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2085
2086 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2087 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2088 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2089 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2090 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2091 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2092 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2093 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2094
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002095 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002096 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2097
2098 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2099 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2100 {
2101 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2102 .name = "Channel Mode",
2103 .info = ad198x_ch_mode_info,
2104 .get = ad198x_ch_mode_get,
2105 .put = ad198x_ch_mode_put,
2106 },
2107
2108 { } /* end */
2109};
2110
2111/* laptop mode */
2112static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2113 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2114 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2115 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2116
2117 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2118 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2119 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2120 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2121 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2122 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2123
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002124 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002125 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2126
2127 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2128
2129 {
2130 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2131 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01002132 .info = ad198x_eapd_info,
2133 .get = ad198x_eapd_get,
2134 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +01002135 .private_value = 0x12, /* port-D */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002136 },
2137
2138 { } /* end */
2139};
2140
2141/* capture */
2142static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2143 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2144 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2145 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2146 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2147 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2148 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2149 {
2150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151 /* The multiple "Capture Source" controls confuse alsamixer
2152 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002153 */
2154 /* .name = "Capture Source", */
2155 .name = "Input Source",
2156 .count = 3,
2157 .info = ad198x_mux_enum_info,
2158 .get = ad198x_mux_enum_get,
2159 .put = ad198x_mux_enum_put,
2160 },
2161 { } /* end */
2162};
2163
2164static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2165 struct snd_ctl_elem_info *uinfo)
2166{
2167 static char *texts[] = {
2168 "PCM", "ADC1", "ADC2", "ADC3"
2169 };
2170 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2171 uinfo->count = 1;
2172 uinfo->value.enumerated.items = 4;
2173 if (uinfo->value.enumerated.item >= 4)
2174 uinfo->value.enumerated.item = 3;
2175 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2176 return 0;
2177}
2178
2179static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2180 struct snd_ctl_elem_value *ucontrol)
2181{
2182 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2183 unsigned int sel;
2184
Takashi Iwaibddcf542007-07-24 18:04:05 +02002185 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2186 AC_AMP_GET_INPUT);
2187 if (!(sel & 0x80))
2188 ucontrol->value.enumerated.item[0] = 0;
2189 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002190 sel = snd_hda_codec_read(codec, 0x0b, 0,
2191 AC_VERB_GET_CONNECT_SEL, 0);
2192 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002193 sel++;
2194 else
2195 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002196 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002197 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002198 return 0;
2199}
2200
2201static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2202 struct snd_ctl_elem_value *ucontrol)
2203{
2204 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002205 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002206 int change;
2207
Takashi Iwai35b26722007-05-05 12:17:17 +02002208 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002209 if (val > 3)
2210 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002211 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002212 sel = snd_hda_codec_read(codec, 0x1d, 0,
2213 AC_VERB_GET_AMP_GAIN_MUTE,
2214 AC_AMP_GET_INPUT);
2215 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002216 if (change) {
2217 snd_hda_codec_write_cache(codec, 0x1d, 0,
2218 AC_VERB_SET_AMP_GAIN_MUTE,
2219 AMP_IN_UNMUTE(0));
2220 snd_hda_codec_write_cache(codec, 0x1d, 0,
2221 AC_VERB_SET_AMP_GAIN_MUTE,
2222 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002223 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002224 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002225 sel = snd_hda_codec_read(codec, 0x1d, 0,
2226 AC_VERB_GET_AMP_GAIN_MUTE,
2227 AC_AMP_GET_INPUT | 0x01);
2228 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002229 if (change) {
2230 snd_hda_codec_write_cache(codec, 0x1d, 0,
2231 AC_VERB_SET_AMP_GAIN_MUTE,
2232 AMP_IN_MUTE(0));
2233 snd_hda_codec_write_cache(codec, 0x1d, 0,
2234 AC_VERB_SET_AMP_GAIN_MUTE,
2235 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002236 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002237 sel = snd_hda_codec_read(codec, 0x0b, 0,
2238 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2239 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002240 if (change)
2241 snd_hda_codec_write_cache(codec, 0x0b, 0,
2242 AC_VERB_SET_CONNECT_SEL,
2243 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002244 }
2245 return change;
2246}
2247
2248static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2249 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2250 {
2251 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2252 .name = "IEC958 Playback Source",
2253 .info = ad1988_spdif_playback_source_info,
2254 .get = ad1988_spdif_playback_source_get,
2255 .put = ad1988_spdif_playback_source_put,
2256 },
2257 { } /* end */
2258};
2259
2260static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2261 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2262 { } /* end */
2263};
2264
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002265static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2266 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002267 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002268 { } /* end */
2269};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002270
2271/*
2272 * initialization verbs
2273 */
2274
2275/*
2276 * for 6-stack (+dig)
2277 */
2278static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002279 /* Front, Surround, CLFE, side DAC; unmute as default */
2280 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2281 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2282 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2283 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002284 /* Port-A front headphon path */
2285 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2286 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2287 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2288 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2289 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2290 /* Port-D line-out path */
2291 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2292 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2293 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2294 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2295 /* Port-F surround path */
2296 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2297 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2298 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2299 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2300 /* Port-G CLFE path */
2301 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2302 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2303 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2304 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2305 /* Port-H side path */
2306 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2307 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2308 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2309 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2310 /* Mono out path */
2311 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2312 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2313 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2314 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2315 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2316 /* Port-B front mic-in path */
2317 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2318 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2319 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2320 /* Port-C line-in path */
2321 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2322 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2323 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2324 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2325 /* Port-E mic-in path */
2326 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2327 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2328 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2329 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002330 /* Analog CD Input */
2331 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002332 /* Analog Mix output amp */
2333 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002334
2335 { }
2336};
2337
2338static struct hda_verb ad1988_capture_init_verbs[] = {
2339 /* mute analog mix */
2340 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2341 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2342 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2343 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2344 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2345 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2346 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2347 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2348 /* select ADCs - front-mic */
2349 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2350 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2351 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002352
2353 { }
2354};
2355
2356static struct hda_verb ad1988_spdif_init_verbs[] = {
2357 /* SPDIF out sel */
2358 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2359 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2360 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002361 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002362 /* SPDIF out pin */
2363 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002364
2365 { }
2366};
2367
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002368/* AD1989 has no ADC -> SPDIF route */
2369static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002370 /* SPDIF-1 out pin */
2371 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002372 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002373 /* SPDIF-2/HDMI out pin */
2374 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2375 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002376 { }
2377};
2378
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002379/*
2380 * verbs for 3stack (+dig)
2381 */
2382static struct hda_verb ad1988_3stack_ch2_init[] = {
2383 /* set port-C to line-in */
2384 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2385 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2386 /* set port-E to mic-in */
2387 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2388 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2389 { } /* end */
2390};
2391
2392static struct hda_verb ad1988_3stack_ch6_init[] = {
2393 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002394 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002395 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002396 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002397 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002398 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002399 { } /* end */
2400};
2401
2402static struct hda_channel_mode ad1988_3stack_modes[2] = {
2403 { 2, ad1988_3stack_ch2_init },
2404 { 6, ad1988_3stack_ch6_init },
2405};
2406
2407static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002408 /* Front, Surround, CLFE, side DAC; unmute as default */
2409 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2410 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2411 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2412 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002413 /* Port-A front headphon path */
2414 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2415 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2416 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2417 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2418 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2419 /* Port-D line-out path */
2420 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2421 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2422 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2423 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2424 /* Mono out path */
2425 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2426 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2427 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2428 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2429 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2430 /* Port-B front mic-in path */
2431 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2432 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2433 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002434 /* Port-C line-in/surround path - 6ch mode as default */
2435 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2436 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002437 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002438 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002439 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002440 /* Port-E mic-in/CLFE path - 6ch mode as default */
2441 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2442 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002443 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002444 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002445 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2446 /* mute analog mix */
2447 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2448 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2449 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2450 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2451 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2452 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2453 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2454 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2455 /* select ADCs - front-mic */
2456 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2457 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2458 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002459 /* Analog Mix output amp */
2460 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002461 { }
2462};
2463
2464/*
2465 * verbs for laptop mode (+dig)
2466 */
2467static struct hda_verb ad1988_laptop_hp_on[] = {
2468 /* unmute port-A and mute port-D */
2469 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2470 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2471 { } /* end */
2472};
2473static struct hda_verb ad1988_laptop_hp_off[] = {
2474 /* mute port-A and unmute port-D */
2475 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2476 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2477 { } /* end */
2478};
2479
2480#define AD1988_HP_EVENT 0x01
2481
2482static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002483 /* Front, Surround, CLFE, side DAC; unmute as default */
2484 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2487 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002488 /* Port-A front headphon path */
2489 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2490 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2491 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2492 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2493 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2494 /* unsolicited event for pin-sense */
2495 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2496 /* Port-D line-out path + EAPD */
2497 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2498 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2499 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2501 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2502 /* Mono out path */
2503 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2504 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2505 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2506 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2507 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2508 /* Port-B mic-in path */
2509 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2510 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2511 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2512 /* Port-C docking station - try to output */
2513 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2514 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2515 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2516 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2517 /* mute analog mix */
2518 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2519 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2520 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2521 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2522 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2523 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2524 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2525 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2526 /* select ADCs - mic */
2527 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2528 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2529 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002530 /* Analog Mix output amp */
2531 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002532 { }
2533};
2534
2535static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2536{
2537 if ((res >> 26) != AD1988_HP_EVENT)
2538 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002539 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002540 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2541 else
2542 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2543}
2544
Takashi Iwaicb53c622007-08-10 17:21:45 +02002545#ifdef CONFIG_SND_HDA_POWER_SAVE
2546static struct hda_amp_list ad1988_loopbacks[] = {
2547 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2548 { 0x20, HDA_INPUT, 1 }, /* Line */
2549 { 0x20, HDA_INPUT, 4 }, /* Mic */
2550 { 0x20, HDA_INPUT, 6 }, /* CD */
2551 { } /* end */
2552};
2553#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002554
2555/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002556 * Automatic parse of I/O pins from the BIOS configuration
2557 */
2558
Takashi Iwaid32410b12005-11-24 16:06:23 +01002559enum {
2560 AD_CTL_WIDGET_VOL,
2561 AD_CTL_WIDGET_MUTE,
2562 AD_CTL_BIND_MUTE,
2563};
2564static struct snd_kcontrol_new ad1988_control_templates[] = {
2565 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2566 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2567 HDA_BIND_MUTE(NULL, 0, 0, 0),
2568};
2569
2570/* add dynamic controls */
2571static int add_control(struct ad198x_spec *spec, int type, const char *name,
2572 unsigned long val)
2573{
2574 struct snd_kcontrol_new *knew;
2575
Takashi Iwai603c4012008-07-30 15:01:44 +02002576 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2577 knew = snd_array_new(&spec->kctls);
2578 if (!knew)
2579 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002580 *knew = ad1988_control_templates[type];
2581 knew->name = kstrdup(name, GFP_KERNEL);
2582 if (! knew->name)
2583 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002584 if (get_amp_nid_(val))
Takashi Iwai9c96fa52009-11-16 11:25:33 +01002585 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002586 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002587 return 0;
2588}
2589
2590#define AD1988_PIN_CD_NID 0x18
2591#define AD1988_PIN_BEEP_NID 0x10
2592
2593static hda_nid_t ad1988_mixer_nids[8] = {
2594 /* A B C D E F G H */
2595 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2596};
2597
2598static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2599{
2600 static hda_nid_t idx_to_dac[8] = {
2601 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002602 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002603 };
2604 static hda_nid_t idx_to_dac_rev2[8] = {
2605 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002606 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002607 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002608 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002609 return idx_to_dac_rev2[idx];
2610 else
2611 return idx_to_dac[idx];
2612}
2613
2614static hda_nid_t ad1988_boost_nids[8] = {
2615 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2616};
2617
2618static int ad1988_pin_idx(hda_nid_t nid)
2619{
2620 static hda_nid_t ad1988_io_pins[8] = {
2621 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2622 };
2623 int i;
2624 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2625 if (ad1988_io_pins[i] == nid)
2626 return i;
2627 return 0; /* should be -1 */
2628}
2629
2630static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2631{
2632 static int loopback_idx[8] = {
2633 2, 0, 1, 3, 4, 5, 1, 4
2634 };
2635 switch (nid) {
2636 case AD1988_PIN_CD_NID:
2637 return 6;
2638 default:
2639 return loopback_idx[ad1988_pin_idx(nid)];
2640 }
2641}
2642
2643static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2644{
2645 static int adc_idx[8] = {
2646 0, 1, 2, 8, 4, 3, 6, 7
2647 };
2648 switch (nid) {
2649 case AD1988_PIN_CD_NID:
2650 return 5;
2651 default:
2652 return adc_idx[ad1988_pin_idx(nid)];
2653 }
2654}
2655
2656/* fill in the dac_nids table from the parsed pin configuration */
2657static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2658 const struct auto_pin_cfg *cfg)
2659{
2660 struct ad198x_spec *spec = codec->spec;
2661 int i, idx;
2662
2663 spec->multiout.dac_nids = spec->private_dac_nids;
2664
2665 /* check the pins hardwired to audio widget */
2666 for (i = 0; i < cfg->line_outs; i++) {
2667 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2668 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2669 }
2670 spec->multiout.num_dacs = cfg->line_outs;
2671 return 0;
2672}
2673
2674/* add playback controls from the parsed DAC table */
2675static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2676 const struct auto_pin_cfg *cfg)
2677{
2678 char name[32];
2679 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2680 hda_nid_t nid;
2681 int i, err;
2682
2683 for (i = 0; i < cfg->line_outs; i++) {
2684 hda_nid_t dac = spec->multiout.dac_nids[i];
2685 if (! dac)
2686 continue;
2687 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2688 if (i == 2) {
2689 /* Center/LFE */
2690 err = add_control(spec, AD_CTL_WIDGET_VOL,
2691 "Center Playback Volume",
2692 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2693 if (err < 0)
2694 return err;
2695 err = add_control(spec, AD_CTL_WIDGET_VOL,
2696 "LFE Playback Volume",
2697 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2698 if (err < 0)
2699 return err;
2700 err = add_control(spec, AD_CTL_BIND_MUTE,
2701 "Center Playback Switch",
2702 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2703 if (err < 0)
2704 return err;
2705 err = add_control(spec, AD_CTL_BIND_MUTE,
2706 "LFE Playback Switch",
2707 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2708 if (err < 0)
2709 return err;
2710 } else {
2711 sprintf(name, "%s Playback Volume", chname[i]);
2712 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2713 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2714 if (err < 0)
2715 return err;
2716 sprintf(name, "%s Playback Switch", chname[i]);
2717 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2718 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2719 if (err < 0)
2720 return err;
2721 }
2722 }
2723 return 0;
2724}
2725
2726/* add playback controls for speaker and HP outputs */
2727static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2728 const char *pfx)
2729{
2730 struct ad198x_spec *spec = codec->spec;
2731 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002732 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002733 char name[32];
2734
2735 if (! pin)
2736 return 0;
2737
2738 idx = ad1988_pin_idx(pin);
2739 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002740 /* check whether the corresponding DAC was already taken */
2741 for (i = 0; i < spec->autocfg.line_outs; i++) {
2742 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2743 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2744 if (dac == nid)
2745 break;
2746 }
2747 if (i >= spec->autocfg.line_outs) {
2748 /* specify the DAC as the extra output */
2749 if (!spec->multiout.hp_nid)
2750 spec->multiout.hp_nid = nid;
2751 else
2752 spec->multiout.extra_out_nid[0] = nid;
2753 /* control HP volume/switch on the output mixer amp */
2754 sprintf(name, "%s Playback Volume", pfx);
2755 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2756 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2757 if (err < 0)
2758 return err;
2759 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002760 nid = ad1988_mixer_nids[idx];
2761 sprintf(name, "%s Playback Switch", pfx);
2762 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2763 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2764 return err;
2765 return 0;
2766}
2767
2768/* create input playback/capture controls for the given pin */
2769static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2770 const char *ctlname, int boost)
2771{
2772 char name[32];
2773 int err, idx;
2774
2775 sprintf(name, "%s Playback Volume", ctlname);
2776 idx = ad1988_pin_to_loopback_idx(pin);
2777 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2778 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2779 return err;
2780 sprintf(name, "%s Playback Switch", ctlname);
2781 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2782 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2783 return err;
2784 if (boost) {
2785 hda_nid_t bnid;
2786 idx = ad1988_pin_idx(pin);
2787 bnid = ad1988_boost_nids[idx];
2788 if (bnid) {
2789 sprintf(name, "%s Boost", ctlname);
2790 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2791 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2792
2793 }
2794 }
2795 return 0;
2796}
2797
2798/* create playback/capture controls for input pins */
2799static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2800 const struct auto_pin_cfg *cfg)
2801{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002802 struct hda_input_mux *imux = &spec->private_imux;
2803 int i, err;
2804
2805 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002806 err = new_analog_input(spec, cfg->input_pins[i],
2807 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002808 i <= AUTO_PIN_FRONT_MIC);
2809 if (err < 0)
2810 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002811 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002812 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2813 imux->num_items++;
2814 }
2815 imux->items[imux->num_items].label = "Mix";
2816 imux->items[imux->num_items].index = 9;
2817 imux->num_items++;
2818
2819 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2820 "Analog Mix Playback Volume",
2821 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2822 return err;
2823 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2824 "Analog Mix Playback Switch",
2825 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2826 return err;
2827
2828 return 0;
2829}
2830
2831static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2832 hda_nid_t nid, int pin_type,
2833 int dac_idx)
2834{
2835 /* set as output */
2836 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2837 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2838 switch (nid) {
2839 case 0x11: /* port-A - DAC 04 */
2840 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2841 break;
2842 case 0x14: /* port-B - DAC 06 */
2843 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2844 break;
2845 case 0x15: /* port-C - DAC 05 */
2846 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2847 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002848 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002849 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2850 break;
2851 case 0x13: /* mono - DAC 04 */
2852 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2853 break;
2854 }
2855}
2856
2857static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2858{
2859 struct ad198x_spec *spec = codec->spec;
2860 int i;
2861
2862 for (i = 0; i < spec->autocfg.line_outs; i++) {
2863 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2864 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2865 }
2866}
2867
2868static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2869{
2870 struct ad198x_spec *spec = codec->spec;
2871 hda_nid_t pin;
2872
Takashi Iwai82bc9552006-03-21 11:24:42 +01002873 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002874 if (pin) /* connect to front */
2875 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002876 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002877 if (pin) /* connect to front */
2878 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2879}
2880
2881static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2882{
2883 struct ad198x_spec *spec = codec->spec;
2884 int i, idx;
2885
2886 for (i = 0; i < AUTO_PIN_LAST; i++) {
2887 hda_nid_t nid = spec->autocfg.input_pins[i];
2888 if (! nid)
2889 continue;
2890 switch (nid) {
2891 case 0x15: /* port-C */
2892 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2893 break;
2894 case 0x17: /* port-E */
2895 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2896 break;
2897 }
2898 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2899 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2900 if (nid != AD1988_PIN_CD_NID)
2901 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2902 AMP_OUT_MUTE);
2903 idx = ad1988_pin_idx(nid);
2904 if (ad1988_boost_nids[idx])
2905 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2906 AC_VERB_SET_AMP_GAIN_MUTE,
2907 AMP_OUT_ZERO);
2908 }
2909}
2910
2911/* parse the BIOS configuration and set up the alc_spec */
2912/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2913static int ad1988_parse_auto_config(struct hda_codec *codec)
2914{
2915 struct ad198x_spec *spec = codec->spec;
2916 int err;
2917
Kailang Yangdf694da2005-12-05 19:42:22 +01002918 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002919 return err;
2920 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2921 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002922 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002923 return 0; /* can't find valid BIOS pin config */
2924 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002925 (err = ad1988_auto_create_extra_out(codec,
2926 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002927 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002928 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002929 "Headphone")) < 0 ||
2930 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2931 return err;
2932
2933 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2934
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002935 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002936 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2937 if (spec->autocfg.dig_in_pin)
2938 spec->dig_in_nid = AD1988_SPDIF_IN;
2939
Takashi Iwai603c4012008-07-30 15:01:44 +02002940 if (spec->kctls.list)
2941 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002942
2943 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2944
2945 spec->input_mux = &spec->private_imux;
2946
2947 return 1;
2948}
2949
2950/* init callback for auto-configuration model -- overriding the default init */
2951static int ad1988_auto_init(struct hda_codec *codec)
2952{
2953 ad198x_init(codec);
2954 ad1988_auto_init_multi_out(codec);
2955 ad1988_auto_init_extra_out(codec);
2956 ad1988_auto_init_analog_input(codec);
2957 return 0;
2958}
2959
2960
2961/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002962 */
2963
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002964static const char *ad1988_models[AD1988_MODEL_LAST] = {
2965 [AD1988_6STACK] = "6stack",
2966 [AD1988_6STACK_DIG] = "6stack-dig",
2967 [AD1988_3STACK] = "3stack",
2968 [AD1988_3STACK_DIG] = "3stack-dig",
2969 [AD1988_LAPTOP] = "laptop",
2970 [AD1988_LAPTOP_DIG] = "laptop-dig",
2971 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002972};
2973
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002974static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01002975 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01002976 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02002977 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07002978 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002979 {}
2980};
2981
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002982static int patch_ad1988(struct hda_codec *codec)
2983{
2984 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01002985 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002986
2987 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2988 if (spec == NULL)
2989 return -ENOMEM;
2990
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002991 codec->spec = spec;
2992
Takashi Iwai1a806f42006-07-03 15:58:16 +02002993 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002994 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2995
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002996 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002997 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002998 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02002999 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3000 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003001 board_config = AD1988_AUTO;
3002 }
3003
3004 if (board_config == AD1988_AUTO) {
3005 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003006 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003007 if (err < 0) {
3008 ad198x_free(codec);
3009 return err;
3010 } else if (! err) {
3011 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3012 board_config = AD1988_6STACK;
3013 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003014 }
3015
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003016 err = snd_hda_attach_beep_device(codec, 0x10);
3017 if (err < 0) {
3018 ad198x_free(codec);
3019 return err;
3020 }
3021 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3022
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003023 switch (board_config) {
3024 case AD1988_6STACK:
3025 case AD1988_6STACK_DIG:
3026 spec->multiout.max_channels = 8;
3027 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003028 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003029 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3030 else
3031 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003032 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003033 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003034 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003035 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3036 else
3037 spec->mixers[0] = ad1988_6stack_mixers1;
3038 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003039 spec->num_init_verbs = 1;
3040 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3041 if (board_config == AD1988_6STACK_DIG) {
3042 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3043 spec->dig_in_nid = AD1988_SPDIF_IN;
3044 }
3045 break;
3046 case AD1988_3STACK:
3047 case AD1988_3STACK_DIG:
3048 spec->multiout.max_channels = 6;
3049 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003050 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003051 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3052 else
3053 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003054 spec->input_mux = &ad1988_6stack_capture_source;
3055 spec->channel_mode = ad1988_3stack_modes;
3056 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003057 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003058 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003059 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3060 else
3061 spec->mixers[0] = ad1988_3stack_mixers1;
3062 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003063 spec->num_init_verbs = 1;
3064 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3065 if (board_config == AD1988_3STACK_DIG)
3066 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3067 break;
3068 case AD1988_LAPTOP:
3069 case AD1988_LAPTOP_DIG:
3070 spec->multiout.max_channels = 2;
3071 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003072 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003073 spec->input_mux = &ad1988_laptop_capture_source;
3074 spec->num_mixers = 1;
3075 spec->mixers[0] = ad1988_laptop_mixers;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01003076 spec->inv_eapd = 1; /* inverted EAPD */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003077 spec->num_init_verbs = 1;
3078 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3079 if (board_config == AD1988_LAPTOP_DIG)
3080 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3081 break;
3082 }
3083
Takashi Iwaid32410b12005-11-24 16:06:23 +01003084 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3085 spec->adc_nids = ad1988_adc_nids;
3086 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003087 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3088 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3089 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003090 if (codec->vendor_id >= 0x11d4989a) {
3091 spec->mixers[spec->num_mixers++] =
3092 ad1989_spdif_out_mixers;
3093 spec->init_verbs[spec->num_init_verbs++] =
3094 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003095 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003096 } else {
3097 spec->mixers[spec->num_mixers++] =
3098 ad1988_spdif_out_mixers;
3099 spec->init_verbs[spec->num_init_verbs++] =
3100 ad1988_spdif_init_verbs;
3101 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003102 }
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003103 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003104 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3105
3106 codec->patch_ops = ad198x_patch_ops;
3107 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003108 case AD1988_AUTO:
3109 codec->patch_ops.init = ad1988_auto_init;
3110 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003111 case AD1988_LAPTOP:
3112 case AD1988_LAPTOP_DIG:
3113 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3114 break;
3115 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003116#ifdef CONFIG_SND_HDA_POWER_SAVE
3117 spec->loopback.amplist = ad1988_loopbacks;
3118#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003119 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003120
3121 return 0;
3122}
3123
3124
3125/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003126 * AD1884 / AD1984
3127 *
3128 * port-B - front line/mic-in
3129 * port-E - aux in/out
3130 * port-F - aux in/out
3131 * port-C - rear line/mic-in
3132 * port-D - rear line/hp-out
3133 * port-A - front line/hp-out
3134 *
3135 * AD1984 = AD1884 + two digital mic-ins
3136 *
3137 * FIXME:
3138 * For simplicity, we share the single DAC for both HP and line-outs
3139 * right now. The inidividual playbacks could be easily implemented,
3140 * but no build-up framework is given, so far.
3141 */
3142
3143static hda_nid_t ad1884_dac_nids[1] = {
3144 0x04,
3145};
3146
3147static hda_nid_t ad1884_adc_nids[2] = {
3148 0x08, 0x09,
3149};
3150
3151static hda_nid_t ad1884_capsrc_nids[2] = {
3152 0x0c, 0x0d,
3153};
3154
3155#define AD1884_SPDIF_OUT 0x02
3156
3157static struct hda_input_mux ad1884_capture_source = {
3158 .num_items = 4,
3159 .items = {
3160 { "Front Mic", 0x0 },
3161 { "Mic", 0x1 },
3162 { "CD", 0x2 },
3163 { "Mix", 0x3 },
3164 },
3165};
3166
3167static struct snd_kcontrol_new ad1884_base_mixers[] = {
3168 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3169 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3170 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3171 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3172 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3173 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3174 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3175 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3176 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3177 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3178 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3179 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003180 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3181 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3182 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3183 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3184 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3185 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3186 {
3187 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3188 /* The multiple "Capture Source" controls confuse alsamixer
3189 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003190 */
3191 /* .name = "Capture Source", */
3192 .name = "Input Source",
3193 .count = 2,
3194 .info = ad198x_mux_enum_info,
3195 .get = ad198x_mux_enum_get,
3196 .put = ad198x_mux_enum_put,
3197 },
3198 /* SPDIF controls */
3199 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3200 {
3201 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3202 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3203 /* identical with ad1983 */
3204 .info = ad1983_spdif_route_info,
3205 .get = ad1983_spdif_route_get,
3206 .put = ad1983_spdif_route_put,
3207 },
3208 { } /* end */
3209};
3210
3211static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3212 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3213 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3214 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003215 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003216 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003217 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003218 { } /* end */
3219};
3220
3221/*
3222 * initialization verbs
3223 */
3224static struct hda_verb ad1884_init_verbs[] = {
3225 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003226 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3227 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003228 /* Port-A (HP) mixer */
3229 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3230 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3231 /* Port-A pin */
3232 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3233 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3234 /* HP selector - select DAC2 */
3235 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3236 /* Port-D (Line-out) mixer */
3237 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3238 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3239 /* Port-D pin */
3240 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3241 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3242 /* Mono-out mixer */
3243 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3244 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3245 /* Mono-out pin */
3246 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3247 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3248 /* Mono selector */
3249 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3250 /* Port-B (front mic) pin */
3251 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003252 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003253 /* Port-C (rear mic) pin */
3254 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003255 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003256 /* Analog mixer; mute as default */
3257 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3258 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3259 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3260 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3261 /* Analog Mix output amp */
3262 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3263 /* SPDIF output selector */
3264 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3265 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3266 { } /* end */
3267};
3268
Takashi Iwaicb53c622007-08-10 17:21:45 +02003269#ifdef CONFIG_SND_HDA_POWER_SAVE
3270static struct hda_amp_list ad1884_loopbacks[] = {
3271 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3272 { 0x20, HDA_INPUT, 1 }, /* Mic */
3273 { 0x20, HDA_INPUT, 2 }, /* CD */
3274 { 0x20, HDA_INPUT, 4 }, /* Docking */
3275 { } /* end */
3276};
3277#endif
3278
Takashi Iwai2134ea42008-01-10 16:53:55 +01003279static const char *ad1884_slave_vols[] = {
3280 "PCM Playback Volume",
3281 "Mic Playback Volume",
3282 "Mono Playback Volume",
3283 "Front Mic Playback Volume",
3284 "Mic Playback Volume",
3285 "CD Playback Volume",
3286 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003287 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003288 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003289 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003290 NULL
3291};
3292
Takashi Iwai2bac6472007-05-18 18:21:41 +02003293static int patch_ad1884(struct hda_codec *codec)
3294{
3295 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003296 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003297
3298 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3299 if (spec == NULL)
3300 return -ENOMEM;
3301
Takashi Iwai2bac6472007-05-18 18:21:41 +02003302 codec->spec = spec;
3303
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003304 err = snd_hda_attach_beep_device(codec, 0x10);
3305 if (err < 0) {
3306 ad198x_free(codec);
3307 return err;
3308 }
3309 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3310
Takashi Iwai2bac6472007-05-18 18:21:41 +02003311 spec->multiout.max_channels = 2;
3312 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3313 spec->multiout.dac_nids = ad1884_dac_nids;
3314 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3315 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3316 spec->adc_nids = ad1884_adc_nids;
3317 spec->capsrc_nids = ad1884_capsrc_nids;
3318 spec->input_mux = &ad1884_capture_source;
3319 spec->num_mixers = 1;
3320 spec->mixers[0] = ad1884_base_mixers;
3321 spec->num_init_verbs = 1;
3322 spec->init_verbs[0] = ad1884_init_verbs;
3323 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003324#ifdef CONFIG_SND_HDA_POWER_SAVE
3325 spec->loopback.amplist = ad1884_loopbacks;
3326#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003327 spec->vmaster_nid = 0x04;
3328 /* we need to cover all playback volumes */
3329 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003330
3331 codec->patch_ops = ad198x_patch_ops;
3332
3333 return 0;
3334}
3335
3336/*
3337 * Lenovo Thinkpad T61/X61
3338 */
3339static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003340 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003341 .items = {
3342 { "Mic", 0x0 },
3343 { "Internal Mic", 0x1 },
3344 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003345 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003346 },
3347};
3348
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003349
3350/*
3351 * Dell Precision T3400
3352 */
3353static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3354 .num_items = 3,
3355 .items = {
3356 { "Front Mic", 0x0 },
3357 { "Line-In", 0x1 },
3358 { "Mix", 0x3 },
3359 },
3360};
3361
3362
Takashi Iwai2bac6472007-05-18 18:21:41 +02003363static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3364 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3365 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3366 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3367 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3368 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3369 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3370 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3371 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3372 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3373 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003374 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3375 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003376 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003377 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3378 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3379 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3380 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3381 {
3382 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3383 /* The multiple "Capture Source" controls confuse alsamixer
3384 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003385 */
3386 /* .name = "Capture Source", */
3387 .name = "Input Source",
3388 .count = 2,
3389 .info = ad198x_mux_enum_info,
3390 .get = ad198x_mux_enum_get,
3391 .put = ad198x_mux_enum_put,
3392 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003393 /* SPDIF controls */
3394 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3395 {
3396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3397 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3398 /* identical with ad1983 */
3399 .info = ad1983_spdif_route_info,
3400 .get = ad1983_spdif_route_get,
3401 .put = ad1983_spdif_route_put,
3402 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003403 { } /* end */
3404};
3405
3406/* additional verbs */
3407static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3408 /* Port-E (docking station mic) pin */
3409 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3410 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3411 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003412 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003413 /* Analog mixer - docking mic; mute as default */
3414 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003415 /* enable EAPD bit */
3416 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003417 { } /* end */
3418};
3419
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003420/*
3421 * Dell Precision T3400
3422 */
3423static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3424 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3425 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3426 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3427 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3428 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3429 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3430 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3431 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3432 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003433 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3434 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3435 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3436 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3437 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3438 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3439 {
3440 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3441 /* The multiple "Capture Source" controls confuse alsamixer
3442 * So call somewhat different..
3443 */
3444 /* .name = "Capture Source", */
3445 .name = "Input Source",
3446 .count = 2,
3447 .info = ad198x_mux_enum_info,
3448 .get = ad198x_mux_enum_get,
3449 .put = ad198x_mux_enum_put,
3450 },
3451 { } /* end */
3452};
3453
Takashi Iwai2bac6472007-05-18 18:21:41 +02003454/* Digial MIC ADC NID 0x05 + 0x06 */
3455static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3456 struct hda_codec *codec,
3457 unsigned int stream_tag,
3458 unsigned int format,
3459 struct snd_pcm_substream *substream)
3460{
3461 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3462 stream_tag, 0, format);
3463 return 0;
3464}
3465
3466static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3467 struct hda_codec *codec,
3468 struct snd_pcm_substream *substream)
3469{
Takashi Iwai888afa12008-03-18 09:57:50 +01003470 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003471 return 0;
3472}
3473
3474static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3475 .substreams = 2,
3476 .channels_min = 2,
3477 .channels_max = 2,
3478 .nid = 0x05,
3479 .ops = {
3480 .prepare = ad1984_pcm_dmic_prepare,
3481 .cleanup = ad1984_pcm_dmic_cleanup
3482 },
3483};
3484
3485static int ad1984_build_pcms(struct hda_codec *codec)
3486{
3487 struct ad198x_spec *spec = codec->spec;
3488 struct hda_pcm *info;
3489 int err;
3490
3491 err = ad198x_build_pcms(codec);
3492 if (err < 0)
3493 return err;
3494
3495 info = spec->pcm_rec + codec->num_pcms;
3496 codec->num_pcms++;
3497 info->name = "AD1984 Digital Mic";
3498 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3499 return 0;
3500}
3501
3502/* models */
3503enum {
3504 AD1984_BASIC,
3505 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003506 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003507 AD1984_MODELS
3508};
3509
3510static const char *ad1984_models[AD1984_MODELS] = {
3511 [AD1984_BASIC] = "basic",
3512 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003513 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003514};
3515
3516static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3517 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003518 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003519 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003520 {}
3521};
3522
3523static int patch_ad1984(struct hda_codec *codec)
3524{
3525 struct ad198x_spec *spec;
3526 int board_config, err;
3527
3528 err = patch_ad1884(codec);
3529 if (err < 0)
3530 return err;
3531 spec = codec->spec;
3532 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3533 ad1984_models, ad1984_cfg_tbl);
3534 switch (board_config) {
3535 case AD1984_BASIC:
3536 /* additional digital mics */
3537 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3538 codec->patch_ops.build_pcms = ad1984_build_pcms;
3539 break;
3540 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003541 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003542 spec->input_mux = &ad1984_thinkpad_capture_source;
3543 spec->mixers[0] = ad1984_thinkpad_mixers;
3544 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3545 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003546 case AD1984_DELL_DESKTOP:
3547 spec->multiout.dig_out_nid = 0;
3548 spec->input_mux = &ad1984_dell_desktop_capture_source;
3549 spec->mixers[0] = ad1984_dell_desktop_mixers;
3550 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003551 }
3552 return 0;
3553}
3554
3555
3556/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003557 * AD1883 / AD1884A / AD1984A / AD1984B
3558 *
3559 * port-B (0x14) - front mic-in
3560 * port-E (0x1c) - rear mic-in
3561 * port-F (0x16) - CD / ext out
3562 * port-C (0x15) - rear line-in
3563 * port-D (0x12) - rear line-out
3564 * port-A (0x11) - front hp-out
3565 *
3566 * AD1984A = AD1884A + digital-mic
3567 * AD1883 = equivalent with AD1984A
3568 * AD1984B = AD1984A + extra SPDIF-out
3569 *
3570 * FIXME:
3571 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3572 */
3573
3574static hda_nid_t ad1884a_dac_nids[1] = {
3575 0x03,
3576};
3577
3578#define ad1884a_adc_nids ad1884_adc_nids
3579#define ad1884a_capsrc_nids ad1884_capsrc_nids
3580
3581#define AD1884A_SPDIF_OUT 0x02
3582
3583static struct hda_input_mux ad1884a_capture_source = {
3584 .num_items = 5,
3585 .items = {
3586 { "Front Mic", 0x0 },
3587 { "Mic", 0x4 },
3588 { "Line", 0x1 },
3589 { "CD", 0x2 },
3590 { "Mix", 0x3 },
3591 },
3592};
3593
3594static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3595 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3596 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3597 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3598 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3599 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3600 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3601 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3602 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3603 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3604 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3605 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3606 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3607 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3608 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3609 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3610 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003611 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3612 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3613 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3614 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3615 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3616 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3617 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3618 {
3619 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3620 /* The multiple "Capture Source" controls confuse alsamixer
3621 * So call somewhat different..
3622 */
3623 /* .name = "Capture Source", */
3624 .name = "Input Source",
3625 .count = 2,
3626 .info = ad198x_mux_enum_info,
3627 .get = ad198x_mux_enum_get,
3628 .put = ad198x_mux_enum_put,
3629 },
3630 /* SPDIF controls */
3631 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3632 {
3633 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3634 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3635 /* identical with ad1983 */
3636 .info = ad1983_spdif_route_info,
3637 .get = ad1983_spdif_route_get,
3638 .put = ad1983_spdif_route_put,
3639 },
3640 { } /* end */
3641};
3642
3643/*
3644 * initialization verbs
3645 */
3646static struct hda_verb ad1884a_init_verbs[] = {
3647 /* DACs; unmute as default */
3648 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3649 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3650 /* Port-A (HP) mixer - route only from analog mixer */
3651 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3652 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3653 /* Port-A pin */
3654 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3655 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3656 /* Port-D (Line-out) mixer - route only from analog mixer */
3657 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3658 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3659 /* Port-D pin */
3660 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3661 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3662 /* Mono-out mixer - route only from analog mixer */
3663 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3664 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3665 /* Mono-out pin */
3666 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3667 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3668 /* Port-B (front mic) pin */
3669 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003670 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003671 /* Port-C (rear line-in) pin */
3672 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003673 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003674 /* Port-E (rear mic) pin */
3675 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3676 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3677 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3678 /* Port-F (CD) pin */
3679 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3680 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3681 /* Analog mixer; mute as default */
3682 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3683 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3684 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3685 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3686 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3687 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3688 /* Analog Mix output amp */
3689 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3690 /* capture sources */
3691 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3692 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3693 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3694 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3695 /* SPDIF output amp */
3696 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3697 { } /* end */
3698};
3699
3700#ifdef CONFIG_SND_HDA_POWER_SAVE
3701static struct hda_amp_list ad1884a_loopbacks[] = {
3702 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3703 { 0x20, HDA_INPUT, 1 }, /* Mic */
3704 { 0x20, HDA_INPUT, 2 }, /* CD */
3705 { 0x20, HDA_INPUT, 4 }, /* Docking */
3706 { } /* end */
3707};
3708#endif
3709
3710/*
3711 * Laptop model
3712 *
3713 * Port A: Headphone jack
3714 * Port B: MIC jack
3715 * Port C: Internal MIC
3716 * Port D: Dock Line Out (if enabled)
3717 * Port E: Dock Line In (if enabled)
3718 * Port F: Internal speakers
3719 */
3720
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003721static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3722 struct snd_ctl_elem_value *ucontrol)
3723{
3724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3725 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3726 int mute = (!ucontrol->value.integer.value[0] &&
3727 !ucontrol->value.integer.value[1]);
3728 /* toggle GPIO1 according to the mute state */
3729 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3730 mute ? 0x02 : 0x0);
3731 return ret;
3732}
Takashi Iwaic5059252008-02-16 09:43:56 +01003733
3734static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3735 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003736 {
3737 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3738 .name = "Master Playback Switch",
3739 .info = snd_hda_mixer_amp_switch_info,
3740 .get = snd_hda_mixer_amp_switch_get,
3741 .put = ad1884a_mobile_master_sw_put,
3742 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3743 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003744 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3745 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3746 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3747 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3748 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3749 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3750 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3751 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3752 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003753 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3755 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3756 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3757 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003758 { } /* end */
3759};
3760
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003761static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3762 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db17e2009-07-02 16:10:23 +02003763 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3764 {
3765 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3766 .name = "Master Playback Switch",
3767 .info = snd_hda_mixer_amp_switch_info,
3768 .get = snd_hda_mixer_amp_switch_get,
3769 .put = ad1884a_mobile_master_sw_put,
3770 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3771 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003772 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3773 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003774 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3775 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003776 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3777 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003778 { } /* end */
3779};
3780
Takashi Iwaic5059252008-02-16 09:43:56 +01003781/* mute internal speaker if HP is plugged */
3782static void ad1884a_hp_automute(struct hda_codec *codec)
3783{
3784 unsigned int present;
3785
Takashi Iwaid56757a2009-11-18 08:00:14 +01003786 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01003787 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3788 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3789 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3790 present ? 0x00 : 0x02);
3791}
3792
Takashi Iwai269ef192008-05-30 15:32:15 +02003793/* switch to external mic if plugged */
3794static void ad1884a_hp_automic(struct hda_codec *codec)
3795{
3796 unsigned int present;
3797
Takashi Iwaid56757a2009-11-18 08:00:14 +01003798 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02003799 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3800 present ? 0 : 1);
3801}
3802
Takashi Iwaic5059252008-02-16 09:43:56 +01003803#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02003804#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01003805
3806/* unsolicited event for HP jack sensing */
3807static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3808{
Takashi Iwai269ef192008-05-30 15:32:15 +02003809 switch (res >> 26) {
3810 case AD1884A_HP_EVENT:
3811 ad1884a_hp_automute(codec);
3812 break;
3813 case AD1884A_MIC_EVENT:
3814 ad1884a_hp_automic(codec);
3815 break;
3816 }
Takashi Iwaic5059252008-02-16 09:43:56 +01003817}
3818
3819/* initialize jack-sensing, too */
3820static int ad1884a_hp_init(struct hda_codec *codec)
3821{
3822 ad198x_init(codec);
3823 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02003824 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01003825 return 0;
3826}
3827
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003828/* mute internal speaker if HP or docking HP is plugged */
3829static void ad1884a_laptop_automute(struct hda_codec *codec)
3830{
3831 unsigned int present;
3832
Takashi Iwaid56757a2009-11-18 08:00:14 +01003833 present = snd_hda_jack_detect(codec, 0x11);
3834 if (!present)
3835 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003836 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3837 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3838 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3839 present ? 0x00 : 0x02);
3840}
3841
3842/* switch to external mic if plugged */
3843static void ad1884a_laptop_automic(struct hda_codec *codec)
3844{
3845 unsigned int idx;
3846
Takashi Iwaid56757a2009-11-18 08:00:14 +01003847 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003848 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01003849 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003850 idx = 4;
3851 else
3852 idx = 1;
3853 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3854}
3855
3856/* unsolicited event for HP jack sensing */
3857static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3858 unsigned int res)
3859{
3860 switch (res >> 26) {
3861 case AD1884A_HP_EVENT:
3862 ad1884a_laptop_automute(codec);
3863 break;
3864 case AD1884A_MIC_EVENT:
3865 ad1884a_laptop_automic(codec);
3866 break;
3867 }
3868}
3869
3870/* initialize jack-sensing, too */
3871static int ad1884a_laptop_init(struct hda_codec *codec)
3872{
3873 ad198x_init(codec);
3874 ad1884a_laptop_automute(codec);
3875 ad1884a_laptop_automic(codec);
3876 return 0;
3877}
3878
Takashi Iwaic5059252008-02-16 09:43:56 +01003879/* additional verbs for laptop model */
3880static struct hda_verb ad1884a_laptop_verbs[] = {
3881 /* Port-A (HP) pin - always unmuted */
3882 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3883 /* Port-F (int speaker) mixer - route only from analog mixer */
3884 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3885 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08003886 /* Port-F (int speaker) pin */
3887 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01003888 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08003889 /* required for compaq 6530s/6531s speaker output */
3890 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003891 /* Port-C pin - internal mic-in */
3892 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3893 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3894 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02003895 /* Port-D (docking line-out) pin - default unmuted */
3896 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01003897 /* analog mix */
3898 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3899 /* unsolicited event for pin-sense */
3900 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003901 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003902 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003903 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02003904 /* allow to touch GPIO1 (for mute control) */
3905 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3906 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3907 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01003908 { } /* end */
3909};
3910
Takashi Iwai73156132009-04-23 08:24:48 +02003911static struct hda_verb ad1884a_mobile_verbs[] = {
3912 /* DACs; unmute as default */
3913 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3914 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3915 /* Port-A (HP) mixer - route only from analog mixer */
3916 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3917 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3918 /* Port-A pin */
3919 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3920 /* Port-A (HP) pin - always unmuted */
3921 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3922 /* Port-B (mic jack) pin */
3923 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3924 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3925 /* Port-C (int mic) pin */
3926 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3927 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3928 /* Port-F (int speaker) mixer - route only from analog mixer */
3929 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3930 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3931 /* Port-F pin */
3932 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3933 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3934 /* Analog mixer; mute as default */
3935 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3936 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3937 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3938 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3939 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3940 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3941 /* Analog Mix output amp */
3942 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3943 /* capture sources */
3944 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3945 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3946 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3947 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3948 /* unsolicited event for pin-sense */
3949 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3950 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db17e2009-07-02 16:10:23 +02003951 /* allow to touch GPIO1 (for mute control) */
3952 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3953 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3954 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02003955 { } /* end */
3956};
3957
Takashi Iwaic5059252008-02-16 09:43:56 +01003958/*
Takashi Iwaif0813742008-03-18 12:13:03 +01003959 * Thinkpad X300
3960 * 0x11 - HP
3961 * 0x12 - speaker
3962 * 0x14 - mic-in
3963 * 0x17 - built-in mic
3964 */
3965
3966static struct hda_verb ad1984a_thinkpad_verbs[] = {
3967 /* HP unmute */
3968 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3969 /* analog mix */
3970 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3971 /* turn on EAPD */
3972 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3973 /* unsolicited event for pin-sense */
3974 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3975 /* internal mic - dmic */
3976 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02003977 /* set magic COEFs for dmic */
3978 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3979 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01003980 { } /* end */
3981};
3982
3983static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3984 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3985 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3986 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3987 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3988 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3989 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01003990 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3991 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3992 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3993 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3994 {
3995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3996 .name = "Capture Source",
3997 .info = ad198x_mux_enum_info,
3998 .get = ad198x_mux_enum_get,
3999 .put = ad198x_mux_enum_put,
4000 },
4001 { } /* end */
4002};
4003
4004static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4005 .num_items = 3,
4006 .items = {
4007 { "Mic", 0x0 },
4008 { "Internal Mic", 0x5 },
4009 { "Mix", 0x3 },
4010 },
4011};
4012
4013/* mute internal speaker if HP is plugged */
4014static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4015{
4016 unsigned int present;
4017
Takashi Iwaid56757a2009-11-18 08:00:14 +01004018 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004019 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4020 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4021}
4022
4023/* unsolicited event for HP jack sensing */
4024static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4025 unsigned int res)
4026{
4027 if ((res >> 26) != AD1884A_HP_EVENT)
4028 return;
4029 ad1984a_thinkpad_automute(codec);
4030}
4031
4032/* initialize jack-sensing, too */
4033static int ad1984a_thinkpad_init(struct hda_codec *codec)
4034{
4035 ad198x_init(codec);
4036 ad1984a_thinkpad_automute(codec);
4037 return 0;
4038}
4039
4040/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004041 * HP Touchsmart
4042 * port-A (0x11) - front hp-out
4043 * port-B (0x14) - unused
4044 * port-C (0x15) - unused
4045 * port-D (0x12) - rear line out
4046 * port-E (0x1c) - front mic-in
4047 * port-F (0x16) - Internal speakers
4048 * digital-mic (0x17) - Internal mic
4049 */
4050
4051static struct hda_verb ad1984a_touchsmart_verbs[] = {
4052 /* DACs; unmute as default */
4053 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4054 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4055 /* Port-A (HP) mixer - route only from analog mixer */
4056 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4057 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4058 /* Port-A pin */
4059 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4060 /* Port-A (HP) pin - always unmuted */
4061 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4062 /* Port-E (int speaker) mixer - route only from analog mixer */
4063 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4064 /* Port-E pin */
4065 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4066 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4067 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4068 /* Port-F (int speaker) mixer - route only from analog mixer */
4069 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4070 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4071 /* Port-F pin */
4072 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4073 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4074 /* Analog mixer; mute as default */
4075 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4076 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4077 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4078 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4079 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4080 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4081 /* Analog Mix output amp */
4082 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4083 /* capture sources */
4084 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4085 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4086 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4087 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4088 /* unsolicited event for pin-sense */
4089 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4090 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4091 /* allow to touch GPIO1 (for mute control) */
4092 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4093 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4094 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4095 /* internal mic - dmic */
4096 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4097 /* set magic COEFs for dmic */
4098 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4099 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4100 { } /* end */
4101};
4102
4103static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4104 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4105/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4106 {
4107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4108 .name = "Master Playback Switch",
4109 .info = snd_hda_mixer_amp_switch_info,
4110 .get = snd_hda_mixer_amp_switch_get,
4111 .put = ad1884a_mobile_master_sw_put,
4112 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4113 },
4114 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4115 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4116 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4117 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4118 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4119 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4120 { } /* end */
4121};
4122
4123/* switch to external mic if plugged */
4124static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4125{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004126 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004127 snd_hda_codec_write(codec, 0x0c, 0,
4128 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004129 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004130 snd_hda_codec_write(codec, 0x0c, 0,
4131 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004132}
4133
4134
4135/* unsolicited event for HP jack sensing */
4136static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4137 unsigned int res)
4138{
4139 switch (res >> 26) {
4140 case AD1884A_HP_EVENT:
4141 ad1884a_hp_automute(codec);
4142 break;
4143 case AD1884A_MIC_EVENT:
4144 ad1984a_touchsmart_automic(codec);
4145 break;
4146 }
4147}
4148
4149/* initialize jack-sensing, too */
4150static int ad1984a_touchsmart_init(struct hda_codec *codec)
4151{
4152 ad198x_init(codec);
4153 ad1884a_hp_automute(codec);
4154 ad1984a_touchsmart_automic(codec);
4155 return 0;
4156}
4157
4158
4159/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004160 */
4161
4162enum {
4163 AD1884A_DESKTOP,
4164 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004165 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004166 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004167 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004168 AD1884A_MODELS
4169};
4170
4171static const char *ad1884a_models[AD1884A_MODELS] = {
4172 [AD1884A_DESKTOP] = "desktop",
4173 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004174 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004175 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004176 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004177};
4178
4179static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4180 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004181 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004182 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004183 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004184 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004185 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4186 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004187 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004188 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004189 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004190 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004191};
4192
4193static int patch_ad1884a(struct hda_codec *codec)
4194{
4195 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004196 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004197
4198 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4199 if (spec == NULL)
4200 return -ENOMEM;
4201
Takashi Iwaic5059252008-02-16 09:43:56 +01004202 codec->spec = spec;
4203
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004204 err = snd_hda_attach_beep_device(codec, 0x10);
4205 if (err < 0) {
4206 ad198x_free(codec);
4207 return err;
4208 }
4209 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4210
Takashi Iwaic5059252008-02-16 09:43:56 +01004211 spec->multiout.max_channels = 2;
4212 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4213 spec->multiout.dac_nids = ad1884a_dac_nids;
4214 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4215 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4216 spec->adc_nids = ad1884a_adc_nids;
4217 spec->capsrc_nids = ad1884a_capsrc_nids;
4218 spec->input_mux = &ad1884a_capture_source;
4219 spec->num_mixers = 1;
4220 spec->mixers[0] = ad1884a_base_mixers;
4221 spec->num_init_verbs = 1;
4222 spec->init_verbs[0] = ad1884a_init_verbs;
4223 spec->spdif_route = 0;
4224#ifdef CONFIG_SND_HDA_POWER_SAVE
4225 spec->loopback.amplist = ad1884a_loopbacks;
4226#endif
4227 codec->patch_ops = ad198x_patch_ops;
4228
4229 /* override some parameters */
4230 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004231 ad1884a_models,
4232 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004233 switch (board_config) {
4234 case AD1884A_LAPTOP:
4235 spec->mixers[0] = ad1884a_laptop_mixers;
4236 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4237 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004238 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4239 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004240 /* set the upper-limit for mixer amp to 0dB for avoiding the
4241 * possible damage by overloading
4242 */
4243 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4244 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4245 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4246 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4247 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004248 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004249 case AD1884A_MOBILE:
4250 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004251 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004252 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004253 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4254 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004255 /* set the upper-limit for mixer amp to 0dB for avoiding the
4256 * possible damage by overloading
4257 */
4258 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4259 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4260 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4261 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4262 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004263 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004264 case AD1884A_THINKPAD:
4265 spec->mixers[0] = ad1984a_thinkpad_mixers;
4266 spec->init_verbs[spec->num_init_verbs++] =
4267 ad1984a_thinkpad_verbs;
4268 spec->multiout.dig_out_nid = 0;
4269 spec->input_mux = &ad1984a_thinkpad_capture_source;
4270 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4271 codec->patch_ops.init = ad1984a_thinkpad_init;
4272 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004273 case AD1984A_TOUCHSMART:
4274 spec->mixers[0] = ad1984a_touchsmart_mixers;
4275 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4276 spec->multiout.dig_out_nid = 0;
4277 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4278 codec->patch_ops.init = ad1984a_touchsmart_init;
4279 /* set the upper-limit for mixer amp to 0dB for avoiding the
4280 * possible damage by overloading
4281 */
4282 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4283 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4284 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4285 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4286 (1 << AC_AMPCAP_MUTE_SHIFT));
4287 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004288 }
4289
4290 return 0;
4291}
4292
4293
4294/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004295 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004296 *
4297 * port-A - front hp-out
4298 * port-B - front mic-in
4299 * port-C - rear line-in, shared surr-out (3stack)
4300 * port-D - rear line-out
4301 * port-E - rear mic-in, shared clfe-out (3stack)
4302 * port-F - rear surr-out (6stack)
4303 * port-G - rear clfe-out (6stack)
4304 */
4305
4306static hda_nid_t ad1882_dac_nids[3] = {
4307 0x04, 0x03, 0x05
4308};
4309
4310static hda_nid_t ad1882_adc_nids[2] = {
4311 0x08, 0x09,
4312};
4313
4314static hda_nid_t ad1882_capsrc_nids[2] = {
4315 0x0c, 0x0d,
4316};
4317
4318#define AD1882_SPDIF_OUT 0x02
4319
4320/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4321static struct hda_input_mux ad1882_capture_source = {
4322 .num_items = 5,
4323 .items = {
4324 { "Front Mic", 0x1 },
4325 { "Mic", 0x4 },
4326 { "Line", 0x2 },
4327 { "CD", 0x3 },
4328 { "Mix", 0x7 },
4329 },
4330};
4331
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004332/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4333static struct hda_input_mux ad1882a_capture_source = {
4334 .num_items = 5,
4335 .items = {
4336 { "Front Mic", 0x1 },
4337 { "Mic", 0x4},
4338 { "Line", 0x2 },
4339 { "Digital Mic", 0x06 },
4340 { "Mix", 0x7 },
4341 },
4342};
4343
Takashi Iwai0ac85512007-06-20 15:46:13 +02004344static struct snd_kcontrol_new ad1882_base_mixers[] = {
4345 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4346 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4347 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4348 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4349 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4350 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4351 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4352 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004353
Takashi Iwai0ac85512007-06-20 15:46:13 +02004354 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4355 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4356 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4357 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4358 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4359 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4360 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4361 {
4362 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4363 /* The multiple "Capture Source" controls confuse alsamixer
4364 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004365 */
4366 /* .name = "Capture Source", */
4367 .name = "Input Source",
4368 .count = 2,
4369 .info = ad198x_mux_enum_info,
4370 .get = ad198x_mux_enum_get,
4371 .put = ad198x_mux_enum_put,
4372 },
4373 /* SPDIF controls */
4374 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4375 {
4376 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4377 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4378 /* identical with ad1983 */
4379 .info = ad1983_spdif_route_info,
4380 .get = ad1983_spdif_route_get,
4381 .put = ad1983_spdif_route_put,
4382 },
4383 { } /* end */
4384};
4385
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004386static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4387 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4388 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4389 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4390 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4391 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4392 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4393 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4394 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004395 { } /* end */
4396};
4397
4398static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4399 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4400 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4401 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4402 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4403 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4404 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4405 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4406 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004407 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4408 { } /* end */
4409};
4410
Takashi Iwai0ac85512007-06-20 15:46:13 +02004411static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4412 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4413 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4414 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4415 {
4416 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4417 .name = "Channel Mode",
4418 .info = ad198x_ch_mode_info,
4419 .get = ad198x_ch_mode_get,
4420 .put = ad198x_ch_mode_put,
4421 },
4422 { } /* end */
4423};
4424
4425static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4426 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4427 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4428 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4429 { } /* end */
4430};
4431
4432static struct hda_verb ad1882_ch2_init[] = {
4433 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4434 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4435 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4436 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4437 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4438 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4439 { } /* end */
4440};
4441
4442static struct hda_verb ad1882_ch4_init[] = {
4443 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4444 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4445 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4446 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4447 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4448 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4449 { } /* end */
4450};
4451
4452static struct hda_verb ad1882_ch6_init[] = {
4453 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4454 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4455 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4456 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4457 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4458 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4459 { } /* end */
4460};
4461
4462static struct hda_channel_mode ad1882_modes[3] = {
4463 { 2, ad1882_ch2_init },
4464 { 4, ad1882_ch4_init },
4465 { 6, ad1882_ch6_init },
4466};
4467
4468/*
4469 * initialization verbs
4470 */
4471static struct hda_verb ad1882_init_verbs[] = {
4472 /* DACs; mute as default */
4473 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4474 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4475 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4476 /* Port-A (HP) mixer */
4477 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4478 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4479 /* Port-A pin */
4480 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4481 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4482 /* HP selector - select DAC2 */
4483 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4484 /* Port-D (Line-out) mixer */
4485 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4486 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4487 /* Port-D pin */
4488 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4489 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4490 /* Mono-out mixer */
4491 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4492 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4493 /* Mono-out pin */
4494 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4495 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4496 /* Port-B (front mic) pin */
4497 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4498 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4499 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4500 /* Port-C (line-in) pin */
4501 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4502 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4503 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4504 /* Port-C mixer - mute as input */
4505 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4506 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4507 /* Port-E (mic-in) pin */
4508 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4509 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4510 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4511 /* Port-E mixer - mute as input */
4512 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4513 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4514 /* Port-F (surround) */
4515 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4516 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4517 /* Port-G (CLFE) */
4518 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4519 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4520 /* Analog mixer; mute as default */
4521 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4522 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4523 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4524 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4525 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4526 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4527 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4528 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4529 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4530 /* Analog Mix output amp */
4531 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4532 /* SPDIF output selector */
4533 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4534 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4535 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4536 { } /* end */
4537};
4538
Takashi Iwaicb53c622007-08-10 17:21:45 +02004539#ifdef CONFIG_SND_HDA_POWER_SAVE
4540static struct hda_amp_list ad1882_loopbacks[] = {
4541 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4542 { 0x20, HDA_INPUT, 1 }, /* Mic */
4543 { 0x20, HDA_INPUT, 4 }, /* Line */
4544 { 0x20, HDA_INPUT, 6 }, /* CD */
4545 { } /* end */
4546};
4547#endif
4548
Takashi Iwai0ac85512007-06-20 15:46:13 +02004549/* models */
4550enum {
4551 AD1882_3STACK,
4552 AD1882_6STACK,
4553 AD1882_MODELS
4554};
4555
4556static const char *ad1882_models[AD1986A_MODELS] = {
4557 [AD1882_3STACK] = "3stack",
4558 [AD1882_6STACK] = "6stack",
4559};
4560
4561
4562static int patch_ad1882(struct hda_codec *codec)
4563{
4564 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004565 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004566
4567 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4568 if (spec == NULL)
4569 return -ENOMEM;
4570
Takashi Iwai0ac85512007-06-20 15:46:13 +02004571 codec->spec = spec;
4572
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004573 err = snd_hda_attach_beep_device(codec, 0x10);
4574 if (err < 0) {
4575 ad198x_free(codec);
4576 return err;
4577 }
4578 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4579
Takashi Iwai0ac85512007-06-20 15:46:13 +02004580 spec->multiout.max_channels = 6;
4581 spec->multiout.num_dacs = 3;
4582 spec->multiout.dac_nids = ad1882_dac_nids;
4583 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4584 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4585 spec->adc_nids = ad1882_adc_nids;
4586 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004587 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004588 spec->input_mux = &ad1882_capture_source;
4589 else
4590 spec->input_mux = &ad1882a_capture_source;
4591 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004592 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004593 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004594 spec->mixers[1] = ad1882_loopback_mixers;
4595 else
4596 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004597 spec->num_init_verbs = 1;
4598 spec->init_verbs[0] = ad1882_init_verbs;
4599 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004600#ifdef CONFIG_SND_HDA_POWER_SAVE
4601 spec->loopback.amplist = ad1882_loopbacks;
4602#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004603 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004604
4605 codec->patch_ops = ad198x_patch_ops;
4606
4607 /* override some parameters */
4608 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4609 ad1882_models, NULL);
4610 switch (board_config) {
4611 default:
4612 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004613 spec->num_mixers = 3;
4614 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004615 spec->channel_mode = ad1882_modes;
4616 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4617 spec->need_dac_fix = 1;
4618 spec->multiout.max_channels = 2;
4619 spec->multiout.num_dacs = 1;
4620 break;
4621 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004622 spec->num_mixers = 3;
4623 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004624 break;
4625 }
4626 return 0;
4627}
4628
4629
4630/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 * patch entries
4632 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004633static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004634 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004635 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004636 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004637 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004638 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4639 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004640 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4641 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004642 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004644 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004645 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004646 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004647 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4648 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 {} /* terminator */
4650};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004651
4652MODULE_ALIAS("snd-hda-codec-id:11d4*");
4653
4654MODULE_LICENSE("GPL");
4655MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4656
4657static struct hda_codec_preset_list analog_list = {
4658 .preset = snd_hda_preset_analog,
4659 .owner = THIS_MODULE,
4660};
4661
4662static int __init patch_analog_init(void)
4663{
4664 return snd_hda_add_codec_preset(&analog_list);
4665}
4666
4667static void __exit patch_analog_exit(void)
4668{
4669 snd_hda_delete_codec_preset(&analog_list);
4670}
4671
4672module_init(patch_analog_init)
4673module_exit(patch_analog_exit)