blob: 8a1064bdf4c6deb2ab6e38def220eef4c26ef252 [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 Iwai03c405a2009-06-24 14:10:15 +020075 unsigned int inv_jack_detect:1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +020076
Takashi Iwaicb53c622007-08-10 17:21:45 +020077#ifdef CONFIG_SND_HDA_POWER_SAVE
78 struct hda_loopback_check loopback;
79#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010080 /* for virtual master */
81 hda_nid_t vmaster_nid;
Takashi Iwai2134ea42008-01-10 16:53:55 +010082 const char **slave_vols;
83 const char **slave_sws;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020086/*
87 * input MUX handling (common part)
88 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010089static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020090{
91 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
92 struct ad198x_spec *spec = codec->spec;
93
94 return snd_hda_input_mux_info(spec->input_mux, uinfo);
95}
96
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010097static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020098{
99 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
100 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100101 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200102
Takashi Iwai985be542005-11-02 18:26:49 +0100103 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200104 return 0;
105}
106
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100107static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200108{
109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
110 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100111 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200112
113 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100114 spec->capsrc_nids[adc_idx],
115 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200116}
117
118/*
119 * initialization (common callbacks)
120 */
121static int ad198x_init(struct hda_codec *codec)
122{
123 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100124 int i;
125
126 for (i = 0; i < spec->num_init_verbs; i++)
127 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200128 return 0;
129}
130
Takashi Iwai2134ea42008-01-10 16:53:55 +0100131static const char *ad_slave_vols[] = {
132 "Front Playback Volume",
133 "Surround Playback Volume",
134 "Center Playback Volume",
135 "LFE Playback Volume",
136 "Side Playback Volume",
137 "Headphone Playback Volume",
138 "Mono Playback Volume",
Takashi Iwai628ed132008-01-25 11:56:57 +0100139 "Speaker Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100140 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100141 NULL
142};
143
144static const char *ad_slave_sws[] = {
145 "Front Playback Switch",
146 "Surround Playback Switch",
147 "Center Playback Switch",
148 "LFE Playback Switch",
149 "Side Playback Switch",
150 "Headphone Playback Switch",
151 "Mono Playback Switch",
Takashi Iwai628ed132008-01-25 11:56:57 +0100152 "Speaker Playback Switch",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100153 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100154 NULL
155};
156
Takashi Iwai603c4012008-07-30 15:01:44 +0200157static void ad198x_free_kctls(struct hda_codec *codec);
158
Takashi Iwai67d634c2009-11-16 15:35:59 +0100159#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100160/* additional beep mixers; the actual parameters are overwritten at build */
161static struct snd_kcontrol_new ad_beep_mixer[] = {
162 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +0200163 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100164 { } /* end */
165};
166
167#define set_beep_amp(spec, nid, idx, dir) \
168 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100169#else
170#define set_beep_amp(spec, nid, idx, dir) /* NOP */
171#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100172
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200173static int ad198x_build_controls(struct hda_codec *codec)
174{
175 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100176 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200177 int err;
178
Takashi Iwai985be542005-11-02 18:26:49 +0100179 for (i = 0; i < spec->num_mixers; i++) {
180 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
181 if (err < 0)
182 return err;
183 }
184 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200185 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100186 if (err < 0)
187 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100188 err = snd_hda_create_spdif_share_sw(codec,
189 &spec->multiout);
190 if (err < 0)
191 return err;
192 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100193 }
194 if (spec->dig_in_nid) {
195 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
196 if (err < 0)
197 return err;
198 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100200 /* create beep controls if needed */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100201#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100202 if (spec->beep_amp) {
203 struct snd_kcontrol_new *knew;
204 for (knew = ad_beep_mixer; knew->name; knew++) {
205 struct snd_kcontrol *kctl;
206 kctl = snd_ctl_new1(knew, codec);
207 if (!kctl)
208 return -ENOMEM;
209 kctl->private_value = spec->beep_amp;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100210 err = snd_hda_ctl_add(codec,
211 get_amp_nid_(spec->beep_amp),
212 kctl);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100213 if (err < 0)
214 return err;
215 }
216 }
Takashi Iwai67d634c2009-11-16 15:35:59 +0100217#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100218
Takashi Iwai2134ea42008-01-10 16:53:55 +0100219 /* if we have no master control, let's create it */
220 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100221 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100222 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100223 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100224 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100225 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100226 (spec->slave_vols ?
227 spec->slave_vols : ad_slave_vols));
228 if (err < 0)
229 return err;
230 }
231 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
232 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
233 NULL,
234 (spec->slave_sws ?
235 spec->slave_sws : ad_slave_sws));
236 if (err < 0)
237 return err;
238 }
239
Takashi Iwai603c4012008-07-30 15:01:44 +0200240 ad198x_free_kctls(codec); /* no longer needed */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200241 return 0;
242}
243
Takashi Iwaicb53c622007-08-10 17:21:45 +0200244#ifdef CONFIG_SND_HDA_POWER_SAVE
245static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
246{
247 struct ad198x_spec *spec = codec->spec;
248 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
249}
250#endif
251
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200252/*
253 * Analog playback callbacks
254 */
255static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
256 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100257 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200258{
259 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100260 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
261 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200262}
263
264static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
265 struct hda_codec *codec,
266 unsigned int stream_tag,
267 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100268 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200269{
270 struct ad198x_spec *spec = codec->spec;
271 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
272 format, substream);
273}
274
275static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
276 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100277 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200278{
279 struct ad198x_spec *spec = codec->spec;
280 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
281}
282
283/*
284 * Digital out
285 */
286static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
287 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100288 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200289{
290 struct ad198x_spec *spec = codec->spec;
291 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
292}
293
294static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100296 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200297{
298 struct ad198x_spec *spec = codec->spec;
299 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
300}
301
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200302static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
303 struct hda_codec *codec,
304 unsigned int stream_tag,
305 unsigned int format,
306 struct snd_pcm_substream *substream)
307{
308 struct ad198x_spec *spec = codec->spec;
309 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
310 format, substream);
311}
312
Takashi Iwai9411e212009-02-13 11:32:28 +0100313static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
314 struct hda_codec *codec,
315 struct snd_pcm_substream *substream)
316{
317 struct ad198x_spec *spec = codec->spec;
318 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
319}
320
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200321/*
322 * Analog capture
323 */
324static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
325 struct hda_codec *codec,
326 unsigned int stream_tag,
327 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100328 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200329{
330 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100331 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
332 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200333 return 0;
334}
335
336static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
337 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100338 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200339{
340 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100341 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200342 return 0;
343}
344
345
346/*
347 */
348static struct hda_pcm_stream ad198x_pcm_analog_playback = {
349 .substreams = 1,
350 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100351 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200352 .nid = 0, /* fill later */
353 .ops = {
354 .open = ad198x_playback_pcm_open,
355 .prepare = ad198x_playback_pcm_prepare,
356 .cleanup = ad198x_playback_pcm_cleanup
357 },
358};
359
360static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100361 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200362 .channels_min = 2,
363 .channels_max = 2,
364 .nid = 0, /* fill later */
365 .ops = {
366 .prepare = ad198x_capture_pcm_prepare,
367 .cleanup = ad198x_capture_pcm_cleanup
368 },
369};
370
371static struct hda_pcm_stream ad198x_pcm_digital_playback = {
372 .substreams = 1,
373 .channels_min = 2,
374 .channels_max = 2,
375 .nid = 0, /* fill later */
376 .ops = {
377 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200378 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100379 .prepare = ad198x_dig_playback_pcm_prepare,
380 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200381 },
382};
383
Takashi Iwai985be542005-11-02 18:26:49 +0100384static struct hda_pcm_stream ad198x_pcm_digital_capture = {
385 .substreams = 1,
386 .channels_min = 2,
387 .channels_max = 2,
388 /* NID is set in alc_build_pcms */
389};
390
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200391static int ad198x_build_pcms(struct hda_codec *codec)
392{
393 struct ad198x_spec *spec = codec->spec;
394 struct hda_pcm *info = spec->pcm_rec;
395
396 codec->num_pcms = 1;
397 codec->pcm_info = info;
398
399 info->name = "AD198x Analog";
400 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
401 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
402 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
403 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100404 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
405 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200406
407 if (spec->multiout.dig_out_nid) {
408 info++;
409 codec->num_pcms++;
410 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100411 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200412 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
413 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100414 if (spec->dig_in_nid) {
415 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
416 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
417 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200418 }
419
420 return 0;
421}
422
Takashi Iwai603c4012008-07-30 15:01:44 +0200423static void ad198x_free_kctls(struct hda_codec *codec)
424{
425 struct ad198x_spec *spec = codec->spec;
426
427 if (spec->kctls.list) {
428 struct snd_kcontrol_new *kctl = spec->kctls.list;
429 int i;
430 for (i = 0; i < spec->kctls.used; i++)
431 kfree(kctl[i].name);
432 }
433 snd_array_free(&spec->kctls);
434}
435
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200436static void ad198x_free(struct hda_codec *codec)
437{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100438 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100439
Takashi Iwai603c4012008-07-30 15:01:44 +0200440 if (!spec)
441 return;
442
443 ad198x_free_kctls(codec);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100444 kfree(spec);
445 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200446}
447
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200448static struct hda_codec_ops ad198x_patch_ops = {
449 .build_controls = ad198x_build_controls,
450 .build_pcms = ad198x_build_pcms,
451 .init = ad198x_init,
452 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200453#ifdef CONFIG_SND_HDA_POWER_SAVE
454 .check_power_status = ad198x_check_power_status,
455#endif
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200456};
457
458
459/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100460 * EAPD control
461 * the private value = nid | (invert << 8)
462 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200463#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100464
465static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
466 struct snd_ctl_elem_value *ucontrol)
467{
468 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469 struct ad198x_spec *spec = codec->spec;
470 int invert = (kcontrol->private_value >> 8) & 1;
471 if (invert)
472 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;
483 int invert = (kcontrol->private_value >> 8) & 1;
484 hda_nid_t nid = kcontrol->private_value & 0xff;
485 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100486 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwai18a815d2006-03-01 19:54:39 +0100487 if (invert)
488 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200489 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100490 return 0;
491 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200492 snd_hda_codec_write_cache(codec, nid,
493 0, AC_VERB_SET_EAPD_BTLENABLE,
494 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100495 return 1;
496}
497
Takashi Iwai9230d212006-03-13 13:49:49 +0100498static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
499 struct snd_ctl_elem_info *uinfo);
500static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
501 struct snd_ctl_elem_value *ucontrol);
502static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
503 struct snd_ctl_elem_value *ucontrol);
504
505
Takashi Iwai18a815d2006-03-01 19:54:39 +0100506/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200507 * AD1986A specific
508 */
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#define AD1986A_SPDIF_OUT 0x02
511#define AD1986A_FRONT_DAC 0x03
512#define AD1986A_SURR_DAC 0x04
513#define AD1986A_CLFE_DAC 0x05
514#define AD1986A_ADC 0x06
515
516static hda_nid_t ad1986a_dac_nids[3] = {
517 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
518};
Takashi Iwai985be542005-11-02 18:26:49 +0100519static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100520static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522static struct hda_input_mux ad1986a_capture_source = {
523 .num_items = 7,
524 .items = {
525 { "Mic", 0x0 },
526 { "CD", 0x1 },
527 { "Aux", 0x3 },
528 { "Line", 0x4 },
529 { "Mix", 0x5 },
530 { "Mono", 0x6 },
531 { "Phone", 0x7 },
532 },
533};
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Takashi Iwai532d5382007-07-27 19:02:40 +0200536static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
537 .ops = &snd_hda_bind_vol,
538 .values = {
539 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
540 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
541 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
542 0
543 },
544};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Takashi Iwai532d5382007-07-27 19:02:40 +0200546static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
547 .ops = &snd_hda_bind_sw,
548 .values = {
549 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
550 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
552 0
553 },
554};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 * mixers
558 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100559static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200560 /*
561 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
562 */
563 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
564 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
566 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
567 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
568 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
570 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
572 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
575 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
576 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
577 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
578 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
579 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
580 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
581 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
582 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100583 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
585 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
586 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
587 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
588 {
589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
590 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200591 .info = ad198x_mux_enum_info,
592 .get = ad198x_mux_enum_get,
593 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 },
595 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
596 { } /* end */
597};
598
Takashi Iwai9230d212006-03-13 13:49:49 +0100599/* additional mixers for 3stack mode */
600static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
601 {
602 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
603 .name = "Channel Mode",
604 .info = ad198x_ch_mode_info,
605 .get = ad198x_ch_mode_get,
606 .put = ad198x_ch_mode_put,
607 },
608 { } /* end */
609};
610
611/* laptop model - 2ch only */
612static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
613
Takashi Iwai20a45e82007-08-15 22:20:45 +0200614/* master controls both pins 0x1a and 0x1b */
615static struct hda_bind_ctls ad1986a_laptop_master_vol = {
616 .ops = &snd_hda_bind_vol,
617 .values = {
618 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
619 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
620 0,
621 },
622};
623
624static struct hda_bind_ctls ad1986a_laptop_master_sw = {
625 .ops = &snd_hda_bind_sw,
626 .values = {
627 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
628 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
629 0,
630 },
631};
632
Takashi Iwai9230d212006-03-13 13:49:49 +0100633static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
634 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
635 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200636 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
637 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100638 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
639 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
640 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
641 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
642 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
643 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
644 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
645 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100646 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100647 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100648 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
649 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
650 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
651 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
652 {
653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
654 .name = "Capture Source",
655 .info = ad198x_mux_enum_info,
656 .get = ad198x_mux_enum_get,
657 .put = ad198x_mux_enum_put,
658 },
659 { } /* end */
660};
661
Takashi Iwai825aa9722006-03-17 10:50:49 +0100662/* laptop-eapd model - 2ch only */
663
Takashi Iwai825aa9722006-03-17 10:50:49 +0100664static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
665 .num_items = 3,
666 .items = {
667 { "Mic", 0x0 },
668 { "Internal Mic", 0x4 },
669 { "Mix", 0x5 },
670 },
671};
672
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100673static struct hda_input_mux ad1986a_automic_capture_source = {
674 .num_items = 2,
675 .items = {
676 { "Mic", 0x0 },
677 { "Mix", 0x5 },
678 },
679};
680
Takashi Iwai16d11a82009-06-24 14:07:53 +0200681static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200682 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
683 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200684 { } /* end */
685};
686
687static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa9722006-03-17 10:50:49 +0100688 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
689 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100690 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
691 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
692 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
693 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
694 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
695 {
696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
697 .name = "Capture Source",
698 .info = ad198x_mux_enum_info,
699 .get = ad198x_mux_enum_get,
700 .put = ad198x_mux_enum_put,
701 },
702 {
703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
704 .name = "External Amplifier",
705 .info = ad198x_eapd_info,
706 .get = ad198x_eapd_get,
707 .put = ad198x_eapd_put,
708 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
709 },
710 { } /* end */
711};
712
Takashi Iwai16d11a82009-06-24 14:07:53 +0200713static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
714 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
715 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa9722006-03-17 10:50:49 +0100716 { } /* end */
717};
718
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100719/* re-connect the mic boost input according to the jack sensing */
720static void ad1986a_automic(struct hda_codec *codec)
721{
722 unsigned int present;
723 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
724 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
725 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
726 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
727}
728
729#define AD1986A_MIC_EVENT 0x36
730
731static void ad1986a_automic_unsol_event(struct hda_codec *codec,
732 unsigned int res)
733{
734 if ((res >> 26) != AD1986A_MIC_EVENT)
735 return;
736 ad1986a_automic(codec);
737}
738
739static int ad1986a_automic_init(struct hda_codec *codec)
740{
741 ad198x_init(codec);
742 ad1986a_automic(codec);
743 return 0;
744}
745
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200746/* laptop-automute - 2ch only */
747
748static void ad1986a_update_hp(struct hda_codec *codec)
749{
750 struct ad198x_spec *spec = codec->spec;
751 unsigned int mute;
752
753 if (spec->jack_present)
754 mute = HDA_AMP_MUTE; /* mute internal speaker */
755 else
756 /* unmute internal speaker if necessary */
757 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
758 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
759 HDA_AMP_MUTE, mute);
760}
761
762static void ad1986a_hp_automute(struct hda_codec *codec)
763{
764 struct ad198x_spec *spec = codec->spec;
765 unsigned int present;
766
767 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200768 spec->jack_present = !!(present & 0x80000000);
769 if (spec->inv_jack_detect)
770 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200771 ad1986a_update_hp(codec);
772}
773
774#define AD1986A_HP_EVENT 0x37
775
776static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
777{
778 if ((res >> 26) != AD1986A_HP_EVENT)
779 return;
780 ad1986a_hp_automute(codec);
781}
782
783static int ad1986a_hp_init(struct hda_codec *codec)
784{
785 ad198x_init(codec);
786 ad1986a_hp_automute(codec);
787 return 0;
788}
789
790/* bind hp and internal speaker mute (with plug check) */
791static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
792 struct snd_ctl_elem_value *ucontrol)
793{
794 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
795 long *valp = ucontrol->value.integer.value;
796 int change;
797
798 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
799 HDA_AMP_MUTE,
800 valp[0] ? 0 : HDA_AMP_MUTE);
801 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
802 HDA_AMP_MUTE,
803 valp[1] ? 0 : HDA_AMP_MUTE);
804 if (change)
805 ad1986a_update_hp(codec);
806 return change;
807}
808
Takashi Iwai16d11a82009-06-24 14:07:53 +0200809static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200810 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
811 {
812 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813 .name = "Master Playback Switch",
814 .info = snd_hda_mixer_amp_switch_info,
815 .get = snd_hda_mixer_amp_switch_get,
816 .put = ad1986a_hp_master_sw_put,
817 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
818 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200819 { } /* end */
820};
821
Takashi Iwai16d11a82009-06-24 14:07:53 +0200822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823/*
824 * initialization verbs
825 */
826static struct hda_verb ad1986a_init_verbs[] = {
827 /* Front, Surround, CLFE DAC; mute as default */
828 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
829 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
830 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
831 /* Downmix - off */
832 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
833 /* HP, Line-Out, Surround, CLFE selectors */
834 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
835 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
836 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
837 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
838 /* Mono selector */
839 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
840 /* Mic selector: Mic 1/2 pin */
841 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
842 /* Line-in selector: Line-in */
843 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
844 /* Mic 1/2 swap */
845 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
846 /* Record selector: mic */
847 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
848 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
849 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
851 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
852 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
853 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
854 /* PC beep */
855 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
856 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
857 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
859 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
860 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
861 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200862 /* HP Pin */
863 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
864 /* Front, Surround, CLFE Pins */
865 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
866 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
867 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
868 /* Mono Pin */
869 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
870 /* Mic Pin */
871 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
872 /* Line, Aux, CD, Beep-In Pin */
873 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
874 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
875 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
876 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
877 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 { } /* end */
879};
880
Takashi Iwai9230d212006-03-13 13:49:49 +0100881static struct hda_verb ad1986a_ch2_init[] = {
882 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200883 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
884 /* Line-in selectors */
885 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100886 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200887 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
888 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
889 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100890 { } /* end */
891};
892
893static struct hda_verb ad1986a_ch4_init[] = {
894 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200895 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
896 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100897 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200898 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
899 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100900 { } /* end */
901};
902
903static struct hda_verb ad1986a_ch6_init[] = {
904 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200905 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
906 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100907 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200908 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
909 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100910 { } /* end */
911};
912
913static struct hda_channel_mode ad1986a_modes[3] = {
914 { 2, ad1986a_ch2_init },
915 { 4, ad1986a_ch4_init },
916 { 6, ad1986a_ch6_init },
917};
918
Takashi Iwai825aa9722006-03-17 10:50:49 +0100919/* eapd initialization */
920static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100921 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa9722006-03-17 10:50:49 +0100922 {}
923};
924
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100925static struct hda_verb ad1986a_automic_verbs[] = {
926 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
927 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
928 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
929 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
930 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
931 {}
932};
933
Tobin Davisf36090f2007-01-08 11:07:12 +0100934/* Ultra initialization */
935static struct hda_verb ad1986a_ultra_init[] = {
936 /* eapd initialization */
937 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
938 /* CLFE -> Mic in */
939 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
940 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
941 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
942 { } /* end */
943};
944
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200945/* pin sensing on HP jack */
946static struct hda_verb ad1986a_hp_init_verbs[] = {
947 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
948 {}
949};
950
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200951static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
952 unsigned int res)
953{
954 switch (res >> 26) {
955 case AD1986A_HP_EVENT:
956 ad1986a_hp_automute(codec);
957 break;
958 case AD1986A_MIC_EVENT:
959 ad1986a_automic(codec);
960 break;
961 }
962}
963
964static int ad1986a_samsung_p50_init(struct hda_codec *codec)
965{
966 ad198x_init(codec);
967 ad1986a_hp_automute(codec);
968 ad1986a_automic(codec);
969 return 0;
970}
971
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200972
Takashi Iwai9230d212006-03-13 13:49:49 +0100973/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100974enum {
975 AD1986A_6STACK,
976 AD1986A_3STACK,
977 AD1986A_LAPTOP,
978 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200979 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +0100980 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +0100981 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200982 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100983 AD1986A_MODELS
984};
Takashi Iwai9230d212006-03-13 13:49:49 +0100985
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100986static const char *ad1986a_models[AD1986A_MODELS] = {
987 [AD1986A_6STACK] = "6stack",
988 [AD1986A_3STACK] = "3stack",
989 [AD1986A_LAPTOP] = "laptop",
990 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200991 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +0100992 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +0100993 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200994 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100995};
996
997static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
998 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100999 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001000 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001001 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001002 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1003 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1004 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1005 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001006 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001007 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001008 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1009 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1010 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1011 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1012 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001013 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Takashi Iwai7db756f2007-12-24 14:36:09 +01001014 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
Tobin Davis18768992007-03-12 22:20:51 +01001015 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001016 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001017 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001018 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001019 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001020 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001021 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001022 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001023 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001024 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001025 {}
1026};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Takashi Iwaicb53c622007-08-10 17:21:45 +02001028#ifdef CONFIG_SND_HDA_POWER_SAVE
1029static struct hda_amp_list ad1986a_loopbacks[] = {
1030 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1031 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1032 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1033 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1034 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1035 { } /* end */
1036};
1037#endif
1038
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001039static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1040{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001041 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001042 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1043}
1044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045static int patch_ad1986a(struct hda_codec *codec)
1046{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001047 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001048 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001050 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (spec == NULL)
1052 return -ENOMEM;
1053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 codec->spec = spec;
1055
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001056 err = snd_hda_attach_beep_device(codec, 0x19);
1057 if (err < 0) {
1058 ad198x_free(codec);
1059 return err;
1060 }
1061 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 spec->multiout.max_channels = 6;
1064 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1065 spec->multiout.dac_nids = ad1986a_dac_nids;
1066 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001067 spec->num_adc_nids = 1;
1068 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001069 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001070 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001071 spec->num_mixers = 1;
1072 spec->mixers[0] = ad1986a_mixers;
1073 spec->num_init_verbs = 1;
1074 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001075#ifdef CONFIG_SND_HDA_POWER_SAVE
1076 spec->loopback.amplist = ad1986a_loopbacks;
1077#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001078 spec->vmaster_nid = 0x1b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001080 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Takashi Iwai9230d212006-03-13 13:49:49 +01001082 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001083 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1084 ad1986a_models,
1085 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001086 switch (board_config) {
1087 case AD1986A_3STACK:
1088 spec->num_mixers = 2;
1089 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001090 spec->num_init_verbs = 2;
1091 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001092 spec->channel_mode = ad1986a_modes;
1093 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001094 spec->need_dac_fix = 1;
1095 spec->multiout.max_channels = 2;
1096 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001097 break;
1098 case AD1986A_LAPTOP:
1099 spec->mixers[0] = ad1986a_laptop_mixers;
1100 spec->multiout.max_channels = 2;
1101 spec->multiout.num_dacs = 1;
1102 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1103 break;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001104 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001105 spec->num_mixers = 3;
1106 spec->mixers[0] = ad1986a_laptop_master_mixers;
1107 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1108 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001109 spec->num_init_verbs = 2;
1110 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1111 spec->multiout.max_channels = 2;
1112 spec->multiout.num_dacs = 1;
1113 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1114 if (!is_jack_available(codec, 0x25))
1115 spec->multiout.dig_out_nid = 0;
1116 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1117 break;
1118 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001119 spec->num_mixers = 2;
1120 spec->mixers[0] = ad1986a_laptop_master_mixers;
1121 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001122 spec->num_init_verbs = 3;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001123 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001124 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001125 spec->multiout.max_channels = 2;
1126 spec->multiout.num_dacs = 1;
1127 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001128 if (!is_jack_available(codec, 0x25))
1129 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001130 spec->input_mux = &ad1986a_automic_capture_source;
1131 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1132 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001133 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001134 case AD1986A_SAMSUNG_P50:
1135 spec->num_mixers = 2;
1136 spec->mixers[0] = ad1986a_automute_master_mixers;
1137 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1138 spec->num_init_verbs = 4;
1139 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1140 spec->init_verbs[2] = ad1986a_automic_verbs;
1141 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1142 spec->multiout.max_channels = 2;
1143 spec->multiout.num_dacs = 1;
1144 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1145 if (!is_jack_available(codec, 0x25))
1146 spec->multiout.dig_out_nid = 0;
1147 spec->input_mux = &ad1986a_automic_capture_source;
1148 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1149 codec->patch_ops.init = ad1986a_samsung_p50_init;
1150 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001151 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001152 spec->num_mixers = 3;
1153 spec->mixers[0] = ad1986a_automute_master_mixers;
1154 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1155 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001156 spec->num_init_verbs = 3;
1157 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1158 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1159 spec->multiout.max_channels = 2;
1160 spec->multiout.num_dacs = 1;
1161 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001162 if (!is_jack_available(codec, 0x25))
1163 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001164 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1165 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1166 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001167 /* Lenovo N100 seems to report the reversed bit
1168 * for HP jack-sensing
1169 */
1170 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001171 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001172 case AD1986A_ULTRA:
1173 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1174 spec->num_init_verbs = 2;
1175 spec->init_verbs[1] = ad1986a_ultra_init;
1176 spec->multiout.max_channels = 2;
1177 spec->multiout.num_dacs = 1;
1178 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1179 spec->multiout.dig_out_nid = 0;
1180 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001181 }
1182
Takashi Iwaid29240c2007-10-26 12:35:56 +02001183 /* AD1986A has a hardware problem that it can't share a stream
1184 * with multiple output pins. The copy of front to surrounds
1185 * causes noisy or silent outputs at a certain timing, e.g.
1186 * changing the volume.
1187 * So, let's disable the shared stream.
1188 */
1189 spec->multiout.no_share_stream = 1;
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 return 0;
1192}
1193
1194/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001195 * AD1983 specific
1196 */
1197
1198#define AD1983_SPDIF_OUT 0x02
1199#define AD1983_DAC 0x03
1200#define AD1983_ADC 0x04
1201
1202static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001203static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001204static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001205
1206static struct hda_input_mux ad1983_capture_source = {
1207 .num_items = 4,
1208 .items = {
1209 { "Mic", 0x0 },
1210 { "Line", 0x1 },
1211 { "Mix", 0x2 },
1212 { "Mix Mono", 0x3 },
1213 },
1214};
1215
1216/*
1217 * SPDIF playback route
1218 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001219static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001220{
1221 static char *texts[] = { "PCM", "ADC" };
1222
1223 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1224 uinfo->count = 1;
1225 uinfo->value.enumerated.items = 2;
1226 if (uinfo->value.enumerated.item > 1)
1227 uinfo->value.enumerated.item = 1;
1228 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1229 return 0;
1230}
1231
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001232static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001233{
1234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1235 struct ad198x_spec *spec = codec->spec;
1236
1237 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1238 return 0;
1239}
1240
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001241static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001242{
1243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1244 struct ad198x_spec *spec = codec->spec;
1245
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001246 if (ucontrol->value.enumerated.item[0] > 1)
1247 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001248 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1249 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001250 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1251 AC_VERB_SET_CONNECT_SEL,
1252 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001253 return 1;
1254 }
1255 return 0;
1256}
1257
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001258static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001259 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1261 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1262 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1269 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001271 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1272 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1274 {
1275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1276 .name = "Capture Source",
1277 .info = ad198x_mux_enum_info,
1278 .get = ad198x_mux_enum_get,
1279 .put = ad198x_mux_enum_put,
1280 },
1281 {
1282 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001283 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001284 .info = ad1983_spdif_route_info,
1285 .get = ad1983_spdif_route_get,
1286 .put = ad1983_spdif_route_put,
1287 },
1288 { } /* end */
1289};
1290
1291static struct hda_verb ad1983_init_verbs[] = {
1292 /* Front, HP, Mono; mute as default */
1293 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1294 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1295 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1296 /* Beep, PCM, Mic, Line-In: mute */
1297 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1298 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1299 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1300 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1301 /* Front, HP selectors; from Mix */
1302 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1303 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1304 /* Mono selector; from Mix */
1305 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1306 /* Mic selector; Mic */
1307 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1308 /* Line-in selector: Line-in */
1309 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1310 /* Mic boost: 0dB */
1311 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1312 /* Record selector: mic */
1313 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1314 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1315 /* SPDIF route: PCM */
1316 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1317 /* Front Pin */
1318 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1319 /* HP Pin */
1320 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1321 /* Mono Pin */
1322 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1323 /* Mic Pin */
1324 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1325 /* Line Pin */
1326 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1327 { } /* end */
1328};
1329
Takashi Iwaicb53c622007-08-10 17:21:45 +02001330#ifdef CONFIG_SND_HDA_POWER_SAVE
1331static struct hda_amp_list ad1983_loopbacks[] = {
1332 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1333 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1334 { } /* end */
1335};
1336#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001337
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001338static int patch_ad1983(struct hda_codec *codec)
1339{
1340 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001341 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001342
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001344 if (spec == NULL)
1345 return -ENOMEM;
1346
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001347 codec->spec = spec;
1348
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001349 err = snd_hda_attach_beep_device(codec, 0x10);
1350 if (err < 0) {
1351 ad198x_free(codec);
1352 return err;
1353 }
1354 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1355
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001356 spec->multiout.max_channels = 2;
1357 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1358 spec->multiout.dac_nids = ad1983_dac_nids;
1359 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001360 spec->num_adc_nids = 1;
1361 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001362 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001363 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001364 spec->num_mixers = 1;
1365 spec->mixers[0] = ad1983_mixers;
1366 spec->num_init_verbs = 1;
1367 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001368 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001369#ifdef CONFIG_SND_HDA_POWER_SAVE
1370 spec->loopback.amplist = ad1983_loopbacks;
1371#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001372 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001373
1374 codec->patch_ops = ad198x_patch_ops;
1375
1376 return 0;
1377}
1378
1379
1380/*
1381 * AD1981 HD specific
1382 */
1383
1384#define AD1981_SPDIF_OUT 0x02
1385#define AD1981_DAC 0x03
1386#define AD1981_ADC 0x04
1387
1388static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001389static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001390static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001391
1392/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1393static struct hda_input_mux ad1981_capture_source = {
1394 .num_items = 7,
1395 .items = {
1396 { "Front Mic", 0x0 },
1397 { "Line", 0x1 },
1398 { "Mix", 0x2 },
1399 { "Mix Mono", 0x3 },
1400 { "CD", 0x4 },
1401 { "Mic", 0x6 },
1402 { "Aux", 0x7 },
1403 },
1404};
1405
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001406static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001407 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1423 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1424 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001425 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1426 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1427 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1428 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1429 {
1430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431 .name = "Capture Source",
1432 .info = ad198x_mux_enum_info,
1433 .get = ad198x_mux_enum_get,
1434 .put = ad198x_mux_enum_put,
1435 },
1436 /* identical with AD1983 */
1437 {
1438 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001439 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001440 .info = ad1983_spdif_route_info,
1441 .get = ad1983_spdif_route_get,
1442 .put = ad1983_spdif_route_put,
1443 },
1444 { } /* end */
1445};
1446
1447static struct hda_verb ad1981_init_verbs[] = {
1448 /* Front, HP, Mono; mute as default */
1449 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1450 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1451 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1452 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1453 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1455 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1458 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1459 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1460 /* Front, HP selectors; from Mix */
1461 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1462 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1463 /* Mono selector; from Mix */
1464 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1465 /* Mic Mixer; select Front Mic */
1466 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1467 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1468 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001469 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1470 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001471 /* Record selector: Front mic */
1472 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1473 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1474 /* SPDIF route: PCM */
1475 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1476 /* Front Pin */
1477 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1478 /* HP Pin */
1479 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1480 /* Mono Pin */
1481 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1482 /* Front & Rear Mic Pins */
1483 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1484 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1485 /* Line Pin */
1486 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1487 /* Digital Beep */
1488 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1489 /* Line-Out as Input: disabled */
1490 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1491 { } /* end */
1492};
1493
Takashi Iwaicb53c622007-08-10 17:21:45 +02001494#ifdef CONFIG_SND_HDA_POWER_SAVE
1495static struct hda_amp_list ad1981_loopbacks[] = {
1496 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1497 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1498 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1499 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1500 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1501 { } /* end */
1502};
1503#endif
1504
Takashi Iwai18a815d2006-03-01 19:54:39 +01001505/*
1506 * Patch for HP nx6320
1507 *
Tobin Davis18768992007-03-12 22:20:51 +01001508 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001509 * speaker output enabled _and_ mute-LED off.
1510 */
1511
1512#define AD1981_HP_EVENT 0x37
1513#define AD1981_MIC_EVENT 0x38
1514
1515static struct hda_verb ad1981_hp_init_verbs[] = {
1516 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1517 /* pin sensing on HP and Mic jacks */
1518 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1519 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1520 {}
1521};
1522
1523/* turn on/off EAPD (+ mute HP) as a master switch */
1524static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1525 struct snd_ctl_elem_value *ucontrol)
1526{
1527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1528 struct ad198x_spec *spec = codec->spec;
1529
1530 if (! ad198x_eapd_put(kcontrol, ucontrol))
1531 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001532 /* change speaker pin appropriately */
1533 snd_hda_codec_write(codec, 0x05, 0,
1534 AC_VERB_SET_PIN_WIDGET_CONTROL,
1535 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001536 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001537 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1538 HDA_AMP_MUTE,
1539 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001540 return 1;
1541}
1542
1543/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001544static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1545 .ops = &snd_hda_bind_vol,
1546 .values = {
1547 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1548 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1549 0
1550 },
1551};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001552
1553/* mute internal speaker if HP is plugged */
1554static void ad1981_hp_automute(struct hda_codec *codec)
1555{
1556 unsigned int present;
1557
1558 present = snd_hda_codec_read(codec, 0x06, 0,
1559 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Takashi Iwai47fd8302007-08-10 17:11:07 +02001560 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1561 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001562}
1563
1564/* toggle input of built-in and mic jack appropriately */
1565static void ad1981_hp_automic(struct hda_codec *codec)
1566{
1567 static struct hda_verb mic_jack_on[] = {
1568 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1569 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1570 {}
1571 };
1572 static struct hda_verb mic_jack_off[] = {
1573 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1574 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1575 {}
1576 };
1577 unsigned int present;
1578
1579 present = snd_hda_codec_read(codec, 0x08, 0,
1580 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1581 if (present)
1582 snd_hda_sequence_write(codec, mic_jack_on);
1583 else
1584 snd_hda_sequence_write(codec, mic_jack_off);
1585}
1586
1587/* unsolicited event for HP jack sensing */
1588static void ad1981_hp_unsol_event(struct hda_codec *codec,
1589 unsigned int res)
1590{
1591 res >>= 26;
1592 switch (res) {
1593 case AD1981_HP_EVENT:
1594 ad1981_hp_automute(codec);
1595 break;
1596 case AD1981_MIC_EVENT:
1597 ad1981_hp_automic(codec);
1598 break;
1599 }
1600}
1601
1602static struct hda_input_mux ad1981_hp_capture_source = {
1603 .num_items = 3,
1604 .items = {
1605 { "Mic", 0x0 },
1606 { "Docking-Station", 0x1 },
1607 { "Mix", 0x2 },
1608 },
1609};
1610
1611static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001612 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001613 {
1614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1615 .name = "Master Playback Switch",
1616 .info = ad198x_eapd_info,
1617 .get = ad198x_eapd_get,
1618 .put = ad1981_hp_master_sw_put,
1619 .private_value = 0x05,
1620 },
1621 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1622 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1623#if 0
1624 /* FIXME: analog mic/line loopback doesn't work with my tests...
1625 * (although recording is OK)
1626 */
1627 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1629 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1630 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1632 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1633 /* FIXME: does this laptop have analog CD connection? */
1634 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1635 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1636#endif
1637 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1638 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1639 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1640 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1641 {
1642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1643 .name = "Capture Source",
1644 .info = ad198x_mux_enum_info,
1645 .get = ad198x_mux_enum_get,
1646 .put = ad198x_mux_enum_put,
1647 },
1648 { } /* end */
1649};
1650
1651/* initialize jack-sensing, too */
1652static int ad1981_hp_init(struct hda_codec *codec)
1653{
1654 ad198x_init(codec);
1655 ad1981_hp_automute(codec);
1656 ad1981_hp_automic(codec);
1657 return 0;
1658}
1659
Tobin Davis18768992007-03-12 22:20:51 +01001660/* configuration for Toshiba Laptops */
1661static struct hda_verb ad1981_toshiba_init_verbs[] = {
1662 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1663 /* pin sensing on HP and Mic jacks */
1664 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1665 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1666 {}
1667};
1668
1669static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1670 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1671 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1672 { }
1673};
1674
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001675/* configuration for Lenovo Thinkpad T60 */
1676static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1677 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1678 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1681 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1682 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1683 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1684 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1685 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1686 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1687 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1688 {
1689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1690 .name = "Capture Source",
1691 .info = ad198x_mux_enum_info,
1692 .get = ad198x_mux_enum_get,
1693 .put = ad198x_mux_enum_put,
1694 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001695 /* identical with AD1983 */
1696 {
1697 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1698 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1699 .info = ad1983_spdif_route_info,
1700 .get = ad1983_spdif_route_get,
1701 .put = ad1983_spdif_route_put,
1702 },
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001703 { } /* end */
1704};
1705
1706static struct hda_input_mux ad1981_thinkpad_capture_source = {
1707 .num_items = 3,
1708 .items = {
1709 { "Mic", 0x0 },
1710 { "Mix", 0x2 },
1711 { "CD", 0x4 },
1712 },
1713};
1714
Takashi Iwai18a815d2006-03-01 19:54:39 +01001715/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001716enum {
1717 AD1981_BASIC,
1718 AD1981_HP,
1719 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001720 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001721 AD1981_MODELS
1722};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001723
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001724static const char *ad1981_models[AD1981_MODELS] = {
1725 [AD1981_HP] = "hp",
1726 [AD1981_THINKPAD] = "thinkpad",
1727 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001728 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001729};
1730
1731static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001732 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001733 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001734 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001735 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001736 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001737 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001738 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001739 /* HP nx6320 (reversed SSID, H/W bug) */
1740 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001741 {}
1742};
1743
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001744static int patch_ad1981(struct hda_codec *codec)
1745{
1746 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001747 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001748
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001749 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001750 if (spec == NULL)
1751 return -ENOMEM;
1752
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001753 codec->spec = spec;
1754
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001755 err = snd_hda_attach_beep_device(codec, 0x10);
1756 if (err < 0) {
1757 ad198x_free(codec);
1758 return err;
1759 }
1760 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1761
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001762 spec->multiout.max_channels = 2;
1763 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1764 spec->multiout.dac_nids = ad1981_dac_nids;
1765 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001766 spec->num_adc_nids = 1;
1767 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001768 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001769 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001770 spec->num_mixers = 1;
1771 spec->mixers[0] = ad1981_mixers;
1772 spec->num_init_verbs = 1;
1773 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001774 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001775#ifdef CONFIG_SND_HDA_POWER_SAVE
1776 spec->loopback.amplist = ad1981_loopbacks;
1777#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001778 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001779
1780 codec->patch_ops = ad198x_patch_ops;
1781
Takashi Iwai18a815d2006-03-01 19:54:39 +01001782 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001783 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1784 ad1981_models,
1785 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001786 switch (board_config) {
1787 case AD1981_HP:
1788 spec->mixers[0] = ad1981_hp_mixers;
1789 spec->num_init_verbs = 2;
1790 spec->init_verbs[1] = ad1981_hp_init_verbs;
1791 spec->multiout.dig_out_nid = 0;
1792 spec->input_mux = &ad1981_hp_capture_source;
1793
1794 codec->patch_ops.init = ad1981_hp_init;
1795 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1796 break;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001797 case AD1981_THINKPAD:
1798 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001799 spec->input_mux = &ad1981_thinkpad_capture_source;
1800 break;
Tobin Davis18768992007-03-12 22:20:51 +01001801 case AD1981_TOSHIBA:
1802 spec->mixers[0] = ad1981_hp_mixers;
1803 spec->mixers[1] = ad1981_toshiba_mixers;
1804 spec->num_init_verbs = 2;
1805 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1806 spec->multiout.dig_out_nid = 0;
1807 spec->input_mux = &ad1981_hp_capture_source;
1808 codec->patch_ops.init = ad1981_hp_init;
1809 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1810 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001811 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001812 return 0;
1813}
1814
1815
1816/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001817 * AD1988
1818 *
1819 * Output pins and routes
1820 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001821 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001822 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1823 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1824 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1825 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1826 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1827 * port-F 0x16 (mute) <- 0x2a <- 06
1828 * port-G 0x24 (mute) <- 0x27 <- 05
1829 * port-H 0x25 (mute) <- 0x28 <- 0a
1830 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1831 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001832 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1833 * (*) 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 +01001834 *
1835 * Input pins and routes
1836 *
1837 * pin boost mix input # / adc input #
1838 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1839 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1840 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1841 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1842 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1843 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1844 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1845 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1846 *
1847 *
1848 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001849 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001850 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001851 *
1852 * Inputs of Analog Mix (0x20)
1853 * 0:Port-B (front mic)
1854 * 1:Port-C/G/H (line-in)
1855 * 2:Port-A
1856 * 3:Port-D (line-in/2)
1857 * 4:Port-E/G/H (mic-in)
1858 * 5:Port-F (mic2-in)
1859 * 6:CD
1860 * 7:Beep
1861 *
1862 * ADC selection
1863 * 0:Port-A
1864 * 1:Port-B (front mic-in)
1865 * 2:Port-C (line-in)
1866 * 3:Port-F (mic2-in)
1867 * 4:Port-E (mic-in)
1868 * 5:CD
1869 * 6:Port-G
1870 * 7:Port-H
1871 * 8:Port-D (line-in/2)
1872 * 9:Mix
1873 *
1874 * Proposed pin assignments by the datasheet
1875 *
1876 * 6-stack
1877 * Port-A front headphone
1878 * B front mic-in
1879 * C rear line-in
1880 * D rear front-out
1881 * E rear mic-in
1882 * F rear surround
1883 * G rear CLFE
1884 * H rear side
1885 *
1886 * 3-stack
1887 * Port-A front headphone
1888 * B front mic
1889 * C rear line-in/surround
1890 * D rear front-out
1891 * E rear mic-in/CLFE
1892 *
1893 * laptop
1894 * Port-A headphone
1895 * B mic-in
1896 * C docking station
1897 * D internal speaker (with EAPD)
1898 * E/F quad mic array
1899 */
1900
1901
1902/* models */
1903enum {
1904 AD1988_6STACK,
1905 AD1988_6STACK_DIG,
1906 AD1988_3STACK,
1907 AD1988_3STACK_DIG,
1908 AD1988_LAPTOP,
1909 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001910 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001911 AD1988_MODEL_LAST,
1912};
1913
Takashi Iwaid32410b12005-11-24 16:06:23 +01001914/* reivision id to check workarounds */
1915#define AD1988A_REV2 0x100200
1916
Takashi Iwai1a806f42006-07-03 15:58:16 +02001917#define is_rev2(codec) \
1918 ((codec)->vendor_id == 0x11d41988 && \
1919 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001920
1921/*
1922 * mixers
1923 */
1924
Takashi Iwaid32410b12005-11-24 16:06:23 +01001925static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001926 0x04, 0x06, 0x05, 0x0a
1927};
1928
Takashi Iwaid32410b12005-11-24 16:06:23 +01001929static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001930 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001931};
1932
1933/* for AD1988A revision-2, DAC2-4 are swapped */
1934static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1935 0x04, 0x05, 0x0a, 0x06
1936};
1937
1938static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001939 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001940};
1941
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001942static hda_nid_t ad1988_adc_nids[3] = {
1943 0x08, 0x09, 0x0f
1944};
1945
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001946static hda_nid_t ad1988_capsrc_nids[3] = {
1947 0x0c, 0x0d, 0x0e
1948};
1949
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001950#define AD1988_SPDIF_OUT 0x02
1951#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001952#define AD1988_SPDIF_IN 0x07
1953
Takashi Iwai3a08e302009-02-13 11:37:08 +01001954static hda_nid_t ad1989b_slave_dig_outs[] = {
1955 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001956};
1957
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001958static struct hda_input_mux ad1988_6stack_capture_source = {
1959 .num_items = 5,
1960 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001961 { "Front Mic", 0x1 }, /* port-B */
1962 { "Line", 0x2 }, /* port-C */
1963 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001964 { "CD", 0x5 },
1965 { "Mix", 0x9 },
1966 },
1967};
1968
1969static struct hda_input_mux ad1988_laptop_capture_source = {
1970 .num_items = 3,
1971 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001972 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001973 { "CD", 0x5 },
1974 { "Mix", 0x9 },
1975 },
1976};
1977
1978/*
1979 */
1980static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1981 struct snd_ctl_elem_info *uinfo)
1982{
1983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1984 struct ad198x_spec *spec = codec->spec;
1985 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1986 spec->num_channel_mode);
1987}
1988
1989static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1990 struct snd_ctl_elem_value *ucontrol)
1991{
1992 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1993 struct ad198x_spec *spec = codec->spec;
1994 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1995 spec->num_channel_mode, spec->multiout.max_channels);
1996}
1997
1998static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1999 struct snd_ctl_elem_value *ucontrol)
2000{
2001 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2002 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002003 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2004 spec->num_channel_mode,
2005 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002006 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002007 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002008 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002009}
2010
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002011/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002012static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002013 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2014 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2015 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2016 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2017 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002018 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002019};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002020
Takashi Iwaid32410b12005-11-24 16:06:23 +01002021static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2022 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2023 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2024 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2025 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2026 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002027 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002028};
2029
2030static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002031 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2032 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2033 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2034 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2035 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2036 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2037 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2038
2039 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2040 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2041 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2042 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2043 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2044 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2045 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2046 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2047
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002048 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002049 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2050
2051 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2052 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2053
2054 { } /* end */
2055};
2056
2057/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002058static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002059 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002060 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002061 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2062 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002063 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002064};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002065
Takashi Iwaid32410b12005-11-24 16:06:23 +01002066static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2067 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002068 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2069 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2070 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002071 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002072};
2073
2074static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002075 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002076 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2077 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2078 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002079 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2080 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2081
2082 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2083 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2084 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2085 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2086 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2087 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2088 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2089 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2090
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002091 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002092 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2093
2094 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2095 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2096 {
2097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2098 .name = "Channel Mode",
2099 .info = ad198x_ch_mode_info,
2100 .get = ad198x_ch_mode_get,
2101 .put = ad198x_ch_mode_put,
2102 },
2103
2104 { } /* end */
2105};
2106
2107/* laptop mode */
2108static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2109 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2110 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2111 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2112
2113 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2114 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2115 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2116 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2117 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2118 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2119
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002120 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002121 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2122
2123 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2124
2125 {
2126 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2127 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01002128 .info = ad198x_eapd_info,
2129 .get = ad198x_eapd_get,
2130 .put = ad198x_eapd_put,
2131 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002132 },
2133
2134 { } /* end */
2135};
2136
2137/* capture */
2138static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2139 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2140 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2141 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2142 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2143 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2144 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2145 {
2146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2147 /* The multiple "Capture Source" controls confuse alsamixer
2148 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002149 */
2150 /* .name = "Capture Source", */
2151 .name = "Input Source",
2152 .count = 3,
2153 .info = ad198x_mux_enum_info,
2154 .get = ad198x_mux_enum_get,
2155 .put = ad198x_mux_enum_put,
2156 },
2157 { } /* end */
2158};
2159
2160static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2161 struct snd_ctl_elem_info *uinfo)
2162{
2163 static char *texts[] = {
2164 "PCM", "ADC1", "ADC2", "ADC3"
2165 };
2166 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2167 uinfo->count = 1;
2168 uinfo->value.enumerated.items = 4;
2169 if (uinfo->value.enumerated.item >= 4)
2170 uinfo->value.enumerated.item = 3;
2171 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2172 return 0;
2173}
2174
2175static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2176 struct snd_ctl_elem_value *ucontrol)
2177{
2178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2179 unsigned int sel;
2180
Takashi Iwaibddcf542007-07-24 18:04:05 +02002181 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2182 AC_AMP_GET_INPUT);
2183 if (!(sel & 0x80))
2184 ucontrol->value.enumerated.item[0] = 0;
2185 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002186 sel = snd_hda_codec_read(codec, 0x0b, 0,
2187 AC_VERB_GET_CONNECT_SEL, 0);
2188 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002189 sel++;
2190 else
2191 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002192 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002193 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002194 return 0;
2195}
2196
2197static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2198 struct snd_ctl_elem_value *ucontrol)
2199{
2200 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002201 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002202 int change;
2203
Takashi Iwai35b26722007-05-05 12:17:17 +02002204 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002205 if (val > 3)
2206 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002207 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002208 sel = snd_hda_codec_read(codec, 0x1d, 0,
2209 AC_VERB_GET_AMP_GAIN_MUTE,
2210 AC_AMP_GET_INPUT);
2211 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002212 if (change) {
2213 snd_hda_codec_write_cache(codec, 0x1d, 0,
2214 AC_VERB_SET_AMP_GAIN_MUTE,
2215 AMP_IN_UNMUTE(0));
2216 snd_hda_codec_write_cache(codec, 0x1d, 0,
2217 AC_VERB_SET_AMP_GAIN_MUTE,
2218 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002219 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002220 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002221 sel = snd_hda_codec_read(codec, 0x1d, 0,
2222 AC_VERB_GET_AMP_GAIN_MUTE,
2223 AC_AMP_GET_INPUT | 0x01);
2224 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002225 if (change) {
2226 snd_hda_codec_write_cache(codec, 0x1d, 0,
2227 AC_VERB_SET_AMP_GAIN_MUTE,
2228 AMP_IN_MUTE(0));
2229 snd_hda_codec_write_cache(codec, 0x1d, 0,
2230 AC_VERB_SET_AMP_GAIN_MUTE,
2231 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002232 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002233 sel = snd_hda_codec_read(codec, 0x0b, 0,
2234 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2235 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002236 if (change)
2237 snd_hda_codec_write_cache(codec, 0x0b, 0,
2238 AC_VERB_SET_CONNECT_SEL,
2239 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002240 }
2241 return change;
2242}
2243
2244static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2245 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2246 {
2247 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2248 .name = "IEC958 Playback Source",
2249 .info = ad1988_spdif_playback_source_info,
2250 .get = ad1988_spdif_playback_source_get,
2251 .put = ad1988_spdif_playback_source_put,
2252 },
2253 { } /* end */
2254};
2255
2256static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2257 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2258 { } /* end */
2259};
2260
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002261static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2262 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002263 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002264 { } /* end */
2265};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002266
2267/*
2268 * initialization verbs
2269 */
2270
2271/*
2272 * for 6-stack (+dig)
2273 */
2274static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002275 /* Front, Surround, CLFE, side DAC; unmute as default */
2276 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2277 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2278 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2279 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002280 /* Port-A front headphon path */
2281 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2282 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2283 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2284 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2285 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2286 /* Port-D line-out path */
2287 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2288 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2289 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291 /* Port-F surround path */
2292 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2293 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2294 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2295 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2296 /* Port-G CLFE path */
2297 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2298 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2299 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2300 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2301 /* Port-H side path */
2302 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2303 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2304 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2305 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2306 /* Mono out path */
2307 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2308 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2309 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2310 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2311 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2312 /* Port-B front mic-in path */
2313 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2314 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2315 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2316 /* Port-C line-in path */
2317 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2318 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2319 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2320 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2321 /* Port-E mic-in path */
2322 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2324 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2325 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002326 /* Analog CD Input */
2327 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002328 /* Analog Mix output amp */
2329 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002330
2331 { }
2332};
2333
2334static struct hda_verb ad1988_capture_init_verbs[] = {
2335 /* mute analog mix */
2336 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2337 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2338 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2339 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2340 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2341 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2342 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2343 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2344 /* select ADCs - front-mic */
2345 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2346 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2347 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002348
2349 { }
2350};
2351
2352static struct hda_verb ad1988_spdif_init_verbs[] = {
2353 /* SPDIF out sel */
2354 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2355 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2356 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002357 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002358 /* SPDIF out pin */
2359 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002360
2361 { }
2362};
2363
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002364/* AD1989 has no ADC -> SPDIF route */
2365static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002366 /* SPDIF-1 out pin */
2367 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002368 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002369 /* SPDIF-2/HDMI out pin */
2370 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2371 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002372 { }
2373};
2374
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002375/*
2376 * verbs for 3stack (+dig)
2377 */
2378static struct hda_verb ad1988_3stack_ch2_init[] = {
2379 /* set port-C to line-in */
2380 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2381 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2382 /* set port-E to mic-in */
2383 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2384 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2385 { } /* end */
2386};
2387
2388static struct hda_verb ad1988_3stack_ch6_init[] = {
2389 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002390 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002391 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002392 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002393 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002394 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002395 { } /* end */
2396};
2397
2398static struct hda_channel_mode ad1988_3stack_modes[2] = {
2399 { 2, ad1988_3stack_ch2_init },
2400 { 6, ad1988_3stack_ch6_init },
2401};
2402
2403static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002404 /* Front, Surround, CLFE, side DAC; unmute as default */
2405 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2406 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2407 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2408 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002409 /* Port-A front headphon path */
2410 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2411 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2412 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2413 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2414 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2415 /* Port-D line-out path */
2416 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2417 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2418 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2419 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2420 /* Mono out path */
2421 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2422 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2423 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2424 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2425 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2426 /* Port-B front mic-in path */
2427 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2428 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2429 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002430 /* Port-C line-in/surround path - 6ch mode as default */
2431 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2432 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002433 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002434 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002435 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002436 /* Port-E mic-in/CLFE path - 6ch mode as default */
2437 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2438 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002439 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002440 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002441 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2442 /* mute analog mix */
2443 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2444 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2445 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2446 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2447 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2448 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2449 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2450 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2451 /* select ADCs - front-mic */
2452 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2453 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2454 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002455 /* Analog Mix output amp */
2456 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002457 { }
2458};
2459
2460/*
2461 * verbs for laptop mode (+dig)
2462 */
2463static struct hda_verb ad1988_laptop_hp_on[] = {
2464 /* unmute port-A and mute port-D */
2465 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2466 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2467 { } /* end */
2468};
2469static struct hda_verb ad1988_laptop_hp_off[] = {
2470 /* mute port-A and unmute port-D */
2471 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2472 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2473 { } /* end */
2474};
2475
2476#define AD1988_HP_EVENT 0x01
2477
2478static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002479 /* Front, Surround, CLFE, side DAC; unmute as default */
2480 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2481 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2482 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002484 /* Port-A front headphon path */
2485 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2486 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2487 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2488 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2490 /* unsolicited event for pin-sense */
2491 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2492 /* Port-D line-out path + EAPD */
2493 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2494 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2495 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2496 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2497 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2498 /* Mono out path */
2499 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2500 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2501 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2502 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2503 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2504 /* Port-B mic-in path */
2505 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2506 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2507 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2508 /* Port-C docking station - try to output */
2509 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2510 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2511 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2512 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2513 /* mute analog mix */
2514 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2515 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2516 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2517 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2518 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2519 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2520 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2521 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2522 /* select ADCs - mic */
2523 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2524 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2525 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002526 /* Analog Mix output amp */
2527 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002528 { }
2529};
2530
2531static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2532{
2533 if ((res >> 26) != AD1988_HP_EVENT)
2534 return;
2535 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2536 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2537 else
2538 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2539}
2540
Takashi Iwaicb53c622007-08-10 17:21:45 +02002541#ifdef CONFIG_SND_HDA_POWER_SAVE
2542static struct hda_amp_list ad1988_loopbacks[] = {
2543 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2544 { 0x20, HDA_INPUT, 1 }, /* Line */
2545 { 0x20, HDA_INPUT, 4 }, /* Mic */
2546 { 0x20, HDA_INPUT, 6 }, /* CD */
2547 { } /* end */
2548};
2549#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002550
2551/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002552 * Automatic parse of I/O pins from the BIOS configuration
2553 */
2554
Takashi Iwaid32410b12005-11-24 16:06:23 +01002555enum {
2556 AD_CTL_WIDGET_VOL,
2557 AD_CTL_WIDGET_MUTE,
2558 AD_CTL_BIND_MUTE,
2559};
2560static struct snd_kcontrol_new ad1988_control_templates[] = {
2561 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2562 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2563 HDA_BIND_MUTE(NULL, 0, 0, 0),
2564};
2565
2566/* add dynamic controls */
2567static int add_control(struct ad198x_spec *spec, int type, const char *name,
2568 unsigned long val)
2569{
2570 struct snd_kcontrol_new *knew;
2571
Takashi Iwai603c4012008-07-30 15:01:44 +02002572 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2573 knew = snd_array_new(&spec->kctls);
2574 if (!knew)
2575 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002576 *knew = ad1988_control_templates[type];
2577 knew->name = kstrdup(name, GFP_KERNEL);
2578 if (! knew->name)
2579 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002580 if (get_amp_nid_(val))
Takashi Iwai9c96fa52009-11-16 11:25:33 +01002581 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002582 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002583 return 0;
2584}
2585
2586#define AD1988_PIN_CD_NID 0x18
2587#define AD1988_PIN_BEEP_NID 0x10
2588
2589static hda_nid_t ad1988_mixer_nids[8] = {
2590 /* A B C D E F G H */
2591 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2592};
2593
2594static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2595{
2596 static hda_nid_t idx_to_dac[8] = {
2597 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002598 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002599 };
2600 static hda_nid_t idx_to_dac_rev2[8] = {
2601 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002602 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002603 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002604 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002605 return idx_to_dac_rev2[idx];
2606 else
2607 return idx_to_dac[idx];
2608}
2609
2610static hda_nid_t ad1988_boost_nids[8] = {
2611 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2612};
2613
2614static int ad1988_pin_idx(hda_nid_t nid)
2615{
2616 static hda_nid_t ad1988_io_pins[8] = {
2617 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2618 };
2619 int i;
2620 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2621 if (ad1988_io_pins[i] == nid)
2622 return i;
2623 return 0; /* should be -1 */
2624}
2625
2626static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2627{
2628 static int loopback_idx[8] = {
2629 2, 0, 1, 3, 4, 5, 1, 4
2630 };
2631 switch (nid) {
2632 case AD1988_PIN_CD_NID:
2633 return 6;
2634 default:
2635 return loopback_idx[ad1988_pin_idx(nid)];
2636 }
2637}
2638
2639static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2640{
2641 static int adc_idx[8] = {
2642 0, 1, 2, 8, 4, 3, 6, 7
2643 };
2644 switch (nid) {
2645 case AD1988_PIN_CD_NID:
2646 return 5;
2647 default:
2648 return adc_idx[ad1988_pin_idx(nid)];
2649 }
2650}
2651
2652/* fill in the dac_nids table from the parsed pin configuration */
2653static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2654 const struct auto_pin_cfg *cfg)
2655{
2656 struct ad198x_spec *spec = codec->spec;
2657 int i, idx;
2658
2659 spec->multiout.dac_nids = spec->private_dac_nids;
2660
2661 /* check the pins hardwired to audio widget */
2662 for (i = 0; i < cfg->line_outs; i++) {
2663 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2664 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2665 }
2666 spec->multiout.num_dacs = cfg->line_outs;
2667 return 0;
2668}
2669
2670/* add playback controls from the parsed DAC table */
2671static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2672 const struct auto_pin_cfg *cfg)
2673{
2674 char name[32];
2675 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2676 hda_nid_t nid;
2677 int i, err;
2678
2679 for (i = 0; i < cfg->line_outs; i++) {
2680 hda_nid_t dac = spec->multiout.dac_nids[i];
2681 if (! dac)
2682 continue;
2683 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2684 if (i == 2) {
2685 /* Center/LFE */
2686 err = add_control(spec, AD_CTL_WIDGET_VOL,
2687 "Center Playback Volume",
2688 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2689 if (err < 0)
2690 return err;
2691 err = add_control(spec, AD_CTL_WIDGET_VOL,
2692 "LFE Playback Volume",
2693 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2694 if (err < 0)
2695 return err;
2696 err = add_control(spec, AD_CTL_BIND_MUTE,
2697 "Center Playback Switch",
2698 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2699 if (err < 0)
2700 return err;
2701 err = add_control(spec, AD_CTL_BIND_MUTE,
2702 "LFE Playback Switch",
2703 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2704 if (err < 0)
2705 return err;
2706 } else {
2707 sprintf(name, "%s Playback Volume", chname[i]);
2708 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2709 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2710 if (err < 0)
2711 return err;
2712 sprintf(name, "%s Playback Switch", chname[i]);
2713 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2714 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2715 if (err < 0)
2716 return err;
2717 }
2718 }
2719 return 0;
2720}
2721
2722/* add playback controls for speaker and HP outputs */
2723static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2724 const char *pfx)
2725{
2726 struct ad198x_spec *spec = codec->spec;
2727 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002728 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002729 char name[32];
2730
2731 if (! pin)
2732 return 0;
2733
2734 idx = ad1988_pin_idx(pin);
2735 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002736 /* check whether the corresponding DAC was already taken */
2737 for (i = 0; i < spec->autocfg.line_outs; i++) {
2738 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2739 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2740 if (dac == nid)
2741 break;
2742 }
2743 if (i >= spec->autocfg.line_outs) {
2744 /* specify the DAC as the extra output */
2745 if (!spec->multiout.hp_nid)
2746 spec->multiout.hp_nid = nid;
2747 else
2748 spec->multiout.extra_out_nid[0] = nid;
2749 /* control HP volume/switch on the output mixer amp */
2750 sprintf(name, "%s Playback Volume", pfx);
2751 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2752 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2753 if (err < 0)
2754 return err;
2755 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002756 nid = ad1988_mixer_nids[idx];
2757 sprintf(name, "%s Playback Switch", pfx);
2758 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2759 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2760 return err;
2761 return 0;
2762}
2763
2764/* create input playback/capture controls for the given pin */
2765static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2766 const char *ctlname, int boost)
2767{
2768 char name[32];
2769 int err, idx;
2770
2771 sprintf(name, "%s Playback Volume", ctlname);
2772 idx = ad1988_pin_to_loopback_idx(pin);
2773 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2774 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2775 return err;
2776 sprintf(name, "%s Playback Switch", ctlname);
2777 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2778 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2779 return err;
2780 if (boost) {
2781 hda_nid_t bnid;
2782 idx = ad1988_pin_idx(pin);
2783 bnid = ad1988_boost_nids[idx];
2784 if (bnid) {
2785 sprintf(name, "%s Boost", ctlname);
2786 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2787 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2788
2789 }
2790 }
2791 return 0;
2792}
2793
2794/* create playback/capture controls for input pins */
2795static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2796 const struct auto_pin_cfg *cfg)
2797{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002798 struct hda_input_mux *imux = &spec->private_imux;
2799 int i, err;
2800
2801 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002802 err = new_analog_input(spec, cfg->input_pins[i],
2803 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002804 i <= AUTO_PIN_FRONT_MIC);
2805 if (err < 0)
2806 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002807 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002808 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2809 imux->num_items++;
2810 }
2811 imux->items[imux->num_items].label = "Mix";
2812 imux->items[imux->num_items].index = 9;
2813 imux->num_items++;
2814
2815 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2816 "Analog Mix Playback Volume",
2817 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2818 return err;
2819 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2820 "Analog Mix Playback Switch",
2821 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2822 return err;
2823
2824 return 0;
2825}
2826
2827static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2828 hda_nid_t nid, int pin_type,
2829 int dac_idx)
2830{
2831 /* set as output */
2832 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2833 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2834 switch (nid) {
2835 case 0x11: /* port-A - DAC 04 */
2836 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2837 break;
2838 case 0x14: /* port-B - DAC 06 */
2839 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2840 break;
2841 case 0x15: /* port-C - DAC 05 */
2842 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2843 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002844 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002845 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2846 break;
2847 case 0x13: /* mono - DAC 04 */
2848 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2849 break;
2850 }
2851}
2852
2853static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2854{
2855 struct ad198x_spec *spec = codec->spec;
2856 int i;
2857
2858 for (i = 0; i < spec->autocfg.line_outs; i++) {
2859 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2860 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2861 }
2862}
2863
2864static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2865{
2866 struct ad198x_spec *spec = codec->spec;
2867 hda_nid_t pin;
2868
Takashi Iwai82bc9552006-03-21 11:24:42 +01002869 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002870 if (pin) /* connect to front */
2871 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002872 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002873 if (pin) /* connect to front */
2874 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2875}
2876
2877static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2878{
2879 struct ad198x_spec *spec = codec->spec;
2880 int i, idx;
2881
2882 for (i = 0; i < AUTO_PIN_LAST; i++) {
2883 hda_nid_t nid = spec->autocfg.input_pins[i];
2884 if (! nid)
2885 continue;
2886 switch (nid) {
2887 case 0x15: /* port-C */
2888 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2889 break;
2890 case 0x17: /* port-E */
2891 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2892 break;
2893 }
2894 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2895 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2896 if (nid != AD1988_PIN_CD_NID)
2897 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2898 AMP_OUT_MUTE);
2899 idx = ad1988_pin_idx(nid);
2900 if (ad1988_boost_nids[idx])
2901 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2902 AC_VERB_SET_AMP_GAIN_MUTE,
2903 AMP_OUT_ZERO);
2904 }
2905}
2906
2907/* parse the BIOS configuration and set up the alc_spec */
2908/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2909static int ad1988_parse_auto_config(struct hda_codec *codec)
2910{
2911 struct ad198x_spec *spec = codec->spec;
2912 int err;
2913
Kailang Yangdf694da2005-12-05 19:42:22 +01002914 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002915 return err;
2916 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2917 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002918 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002919 return 0; /* can't find valid BIOS pin config */
2920 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002921 (err = ad1988_auto_create_extra_out(codec,
2922 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002923 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002924 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002925 "Headphone")) < 0 ||
2926 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2927 return err;
2928
2929 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2930
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002931 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002932 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2933 if (spec->autocfg.dig_in_pin)
2934 spec->dig_in_nid = AD1988_SPDIF_IN;
2935
Takashi Iwai603c4012008-07-30 15:01:44 +02002936 if (spec->kctls.list)
2937 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002938
2939 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2940
2941 spec->input_mux = &spec->private_imux;
2942
2943 return 1;
2944}
2945
2946/* init callback for auto-configuration model -- overriding the default init */
2947static int ad1988_auto_init(struct hda_codec *codec)
2948{
2949 ad198x_init(codec);
2950 ad1988_auto_init_multi_out(codec);
2951 ad1988_auto_init_extra_out(codec);
2952 ad1988_auto_init_analog_input(codec);
2953 return 0;
2954}
2955
2956
2957/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002958 */
2959
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002960static const char *ad1988_models[AD1988_MODEL_LAST] = {
2961 [AD1988_6STACK] = "6stack",
2962 [AD1988_6STACK_DIG] = "6stack-dig",
2963 [AD1988_3STACK] = "3stack",
2964 [AD1988_3STACK_DIG] = "3stack-dig",
2965 [AD1988_LAPTOP] = "laptop",
2966 [AD1988_LAPTOP_DIG] = "laptop-dig",
2967 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002968};
2969
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002970static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01002971 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01002972 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02002973 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07002974 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002975 {}
2976};
2977
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002978static int patch_ad1988(struct hda_codec *codec)
2979{
2980 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01002981 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002982
2983 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2984 if (spec == NULL)
2985 return -ENOMEM;
2986
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002987 codec->spec = spec;
2988
Takashi Iwai1a806f42006-07-03 15:58:16 +02002989 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002990 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2991
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002992 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002993 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002994 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02002995 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
2996 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002997 board_config = AD1988_AUTO;
2998 }
2999
3000 if (board_config == AD1988_AUTO) {
3001 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003002 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003003 if (err < 0) {
3004 ad198x_free(codec);
3005 return err;
3006 } else if (! err) {
3007 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3008 board_config = AD1988_6STACK;
3009 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003010 }
3011
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003012 err = snd_hda_attach_beep_device(codec, 0x10);
3013 if (err < 0) {
3014 ad198x_free(codec);
3015 return err;
3016 }
3017 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3018
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003019 switch (board_config) {
3020 case AD1988_6STACK:
3021 case AD1988_6STACK_DIG:
3022 spec->multiout.max_channels = 8;
3023 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003024 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003025 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3026 else
3027 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003028 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003029 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003030 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003031 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3032 else
3033 spec->mixers[0] = ad1988_6stack_mixers1;
3034 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003035 spec->num_init_verbs = 1;
3036 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3037 if (board_config == AD1988_6STACK_DIG) {
3038 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3039 spec->dig_in_nid = AD1988_SPDIF_IN;
3040 }
3041 break;
3042 case AD1988_3STACK:
3043 case AD1988_3STACK_DIG:
3044 spec->multiout.max_channels = 6;
3045 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003046 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003047 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3048 else
3049 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003050 spec->input_mux = &ad1988_6stack_capture_source;
3051 spec->channel_mode = ad1988_3stack_modes;
3052 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003053 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003054 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003055 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3056 else
3057 spec->mixers[0] = ad1988_3stack_mixers1;
3058 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003059 spec->num_init_verbs = 1;
3060 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3061 if (board_config == AD1988_3STACK_DIG)
3062 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3063 break;
3064 case AD1988_LAPTOP:
3065 case AD1988_LAPTOP_DIG:
3066 spec->multiout.max_channels = 2;
3067 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003068 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003069 spec->input_mux = &ad1988_laptop_capture_source;
3070 spec->num_mixers = 1;
3071 spec->mixers[0] = ad1988_laptop_mixers;
3072 spec->num_init_verbs = 1;
3073 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3074 if (board_config == AD1988_LAPTOP_DIG)
3075 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3076 break;
3077 }
3078
Takashi Iwaid32410b12005-11-24 16:06:23 +01003079 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3080 spec->adc_nids = ad1988_adc_nids;
3081 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003082 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3083 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3084 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003085 if (codec->vendor_id >= 0x11d4989a) {
3086 spec->mixers[spec->num_mixers++] =
3087 ad1989_spdif_out_mixers;
3088 spec->init_verbs[spec->num_init_verbs++] =
3089 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003090 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003091 } else {
3092 spec->mixers[spec->num_mixers++] =
3093 ad1988_spdif_out_mixers;
3094 spec->init_verbs[spec->num_init_verbs++] =
3095 ad1988_spdif_init_verbs;
3096 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003097 }
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003098 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003099 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3100
3101 codec->patch_ops = ad198x_patch_ops;
3102 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003103 case AD1988_AUTO:
3104 codec->patch_ops.init = ad1988_auto_init;
3105 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003106 case AD1988_LAPTOP:
3107 case AD1988_LAPTOP_DIG:
3108 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3109 break;
3110 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003111#ifdef CONFIG_SND_HDA_POWER_SAVE
3112 spec->loopback.amplist = ad1988_loopbacks;
3113#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003114 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003115
3116 return 0;
3117}
3118
3119
3120/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003121 * AD1884 / AD1984
3122 *
3123 * port-B - front line/mic-in
3124 * port-E - aux in/out
3125 * port-F - aux in/out
3126 * port-C - rear line/mic-in
3127 * port-D - rear line/hp-out
3128 * port-A - front line/hp-out
3129 *
3130 * AD1984 = AD1884 + two digital mic-ins
3131 *
3132 * FIXME:
3133 * For simplicity, we share the single DAC for both HP and line-outs
3134 * right now. The inidividual playbacks could be easily implemented,
3135 * but no build-up framework is given, so far.
3136 */
3137
3138static hda_nid_t ad1884_dac_nids[1] = {
3139 0x04,
3140};
3141
3142static hda_nid_t ad1884_adc_nids[2] = {
3143 0x08, 0x09,
3144};
3145
3146static hda_nid_t ad1884_capsrc_nids[2] = {
3147 0x0c, 0x0d,
3148};
3149
3150#define AD1884_SPDIF_OUT 0x02
3151
3152static struct hda_input_mux ad1884_capture_source = {
3153 .num_items = 4,
3154 .items = {
3155 { "Front Mic", 0x0 },
3156 { "Mic", 0x1 },
3157 { "CD", 0x2 },
3158 { "Mix", 0x3 },
3159 },
3160};
3161
3162static struct snd_kcontrol_new ad1884_base_mixers[] = {
3163 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3164 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3165 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3166 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3167 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3168 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3169 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3170 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3171 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3172 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3173 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3174 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003175 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3176 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3177 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3178 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3179 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3180 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3181 {
3182 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3183 /* The multiple "Capture Source" controls confuse alsamixer
3184 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003185 */
3186 /* .name = "Capture Source", */
3187 .name = "Input Source",
3188 .count = 2,
3189 .info = ad198x_mux_enum_info,
3190 .get = ad198x_mux_enum_get,
3191 .put = ad198x_mux_enum_put,
3192 },
3193 /* SPDIF controls */
3194 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3195 {
3196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3197 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3198 /* identical with ad1983 */
3199 .info = ad1983_spdif_route_info,
3200 .get = ad1983_spdif_route_get,
3201 .put = ad1983_spdif_route_put,
3202 },
3203 { } /* end */
3204};
3205
3206static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3207 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3208 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3209 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003210 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003211 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003212 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003213 { } /* end */
3214};
3215
3216/*
3217 * initialization verbs
3218 */
3219static struct hda_verb ad1884_init_verbs[] = {
3220 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003221 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3222 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003223 /* Port-A (HP) mixer */
3224 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3225 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3226 /* Port-A pin */
3227 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3228 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3229 /* HP selector - select DAC2 */
3230 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3231 /* Port-D (Line-out) mixer */
3232 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3233 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3234 /* Port-D pin */
3235 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3236 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3237 /* Mono-out mixer */
3238 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3239 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3240 /* Mono-out pin */
3241 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3242 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3243 /* Mono selector */
3244 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3245 /* Port-B (front mic) pin */
3246 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003247 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003248 /* Port-C (rear mic) pin */
3249 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003250 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003251 /* Analog mixer; mute as default */
3252 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3253 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3254 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3255 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3256 /* Analog Mix output amp */
3257 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3258 /* SPDIF output selector */
3259 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3260 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3261 { } /* end */
3262};
3263
Takashi Iwaicb53c622007-08-10 17:21:45 +02003264#ifdef CONFIG_SND_HDA_POWER_SAVE
3265static struct hda_amp_list ad1884_loopbacks[] = {
3266 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3267 { 0x20, HDA_INPUT, 1 }, /* Mic */
3268 { 0x20, HDA_INPUT, 2 }, /* CD */
3269 { 0x20, HDA_INPUT, 4 }, /* Docking */
3270 { } /* end */
3271};
3272#endif
3273
Takashi Iwai2134ea42008-01-10 16:53:55 +01003274static const char *ad1884_slave_vols[] = {
3275 "PCM Playback Volume",
3276 "Mic Playback Volume",
3277 "Mono Playback Volume",
3278 "Front Mic Playback Volume",
3279 "Mic Playback Volume",
3280 "CD Playback Volume",
3281 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003282 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003283 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003284 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003285 NULL
3286};
3287
Takashi Iwai2bac6472007-05-18 18:21:41 +02003288static int patch_ad1884(struct hda_codec *codec)
3289{
3290 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003291 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003292
3293 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3294 if (spec == NULL)
3295 return -ENOMEM;
3296
Takashi Iwai2bac6472007-05-18 18:21:41 +02003297 codec->spec = spec;
3298
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003299 err = snd_hda_attach_beep_device(codec, 0x10);
3300 if (err < 0) {
3301 ad198x_free(codec);
3302 return err;
3303 }
3304 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3305
Takashi Iwai2bac6472007-05-18 18:21:41 +02003306 spec->multiout.max_channels = 2;
3307 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3308 spec->multiout.dac_nids = ad1884_dac_nids;
3309 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3310 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3311 spec->adc_nids = ad1884_adc_nids;
3312 spec->capsrc_nids = ad1884_capsrc_nids;
3313 spec->input_mux = &ad1884_capture_source;
3314 spec->num_mixers = 1;
3315 spec->mixers[0] = ad1884_base_mixers;
3316 spec->num_init_verbs = 1;
3317 spec->init_verbs[0] = ad1884_init_verbs;
3318 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003319#ifdef CONFIG_SND_HDA_POWER_SAVE
3320 spec->loopback.amplist = ad1884_loopbacks;
3321#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003322 spec->vmaster_nid = 0x04;
3323 /* we need to cover all playback volumes */
3324 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003325
3326 codec->patch_ops = ad198x_patch_ops;
3327
3328 return 0;
3329}
3330
3331/*
3332 * Lenovo Thinkpad T61/X61
3333 */
3334static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003335 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003336 .items = {
3337 { "Mic", 0x0 },
3338 { "Internal Mic", 0x1 },
3339 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003340 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003341 },
3342};
3343
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003344
3345/*
3346 * Dell Precision T3400
3347 */
3348static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3349 .num_items = 3,
3350 .items = {
3351 { "Front Mic", 0x0 },
3352 { "Line-In", 0x1 },
3353 { "Mix", 0x3 },
3354 },
3355};
3356
3357
Takashi Iwai2bac6472007-05-18 18:21:41 +02003358static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3359 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3360 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3361 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3362 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3363 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3364 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3365 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3366 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3367 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3368 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003369 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3370 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003371 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003372 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3373 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3374 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3375 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3376 {
3377 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3378 /* The multiple "Capture Source" controls confuse alsamixer
3379 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003380 */
3381 /* .name = "Capture Source", */
3382 .name = "Input Source",
3383 .count = 2,
3384 .info = ad198x_mux_enum_info,
3385 .get = ad198x_mux_enum_get,
3386 .put = ad198x_mux_enum_put,
3387 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003388 /* SPDIF controls */
3389 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3390 {
3391 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3392 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3393 /* identical with ad1983 */
3394 .info = ad1983_spdif_route_info,
3395 .get = ad1983_spdif_route_get,
3396 .put = ad1983_spdif_route_put,
3397 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003398 { } /* end */
3399};
3400
3401/* additional verbs */
3402static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3403 /* Port-E (docking station mic) pin */
3404 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3405 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3406 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003407 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003408 /* Analog mixer - docking mic; mute as default */
3409 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003410 /* enable EAPD bit */
3411 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003412 { } /* end */
3413};
3414
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003415/*
3416 * Dell Precision T3400
3417 */
3418static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3419 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3420 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3421 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3422 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3423 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3424 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3425 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3426 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3427 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003428 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3429 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3430 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3431 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3432 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3433 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3434 {
3435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3436 /* The multiple "Capture Source" controls confuse alsamixer
3437 * So call somewhat different..
3438 */
3439 /* .name = "Capture Source", */
3440 .name = "Input Source",
3441 .count = 2,
3442 .info = ad198x_mux_enum_info,
3443 .get = ad198x_mux_enum_get,
3444 .put = ad198x_mux_enum_put,
3445 },
3446 { } /* end */
3447};
3448
Takashi Iwai2bac6472007-05-18 18:21:41 +02003449/* Digial MIC ADC NID 0x05 + 0x06 */
3450static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3451 struct hda_codec *codec,
3452 unsigned int stream_tag,
3453 unsigned int format,
3454 struct snd_pcm_substream *substream)
3455{
3456 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3457 stream_tag, 0, format);
3458 return 0;
3459}
3460
3461static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3462 struct hda_codec *codec,
3463 struct snd_pcm_substream *substream)
3464{
Takashi Iwai888afa12008-03-18 09:57:50 +01003465 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003466 return 0;
3467}
3468
3469static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3470 .substreams = 2,
3471 .channels_min = 2,
3472 .channels_max = 2,
3473 .nid = 0x05,
3474 .ops = {
3475 .prepare = ad1984_pcm_dmic_prepare,
3476 .cleanup = ad1984_pcm_dmic_cleanup
3477 },
3478};
3479
3480static int ad1984_build_pcms(struct hda_codec *codec)
3481{
3482 struct ad198x_spec *spec = codec->spec;
3483 struct hda_pcm *info;
3484 int err;
3485
3486 err = ad198x_build_pcms(codec);
3487 if (err < 0)
3488 return err;
3489
3490 info = spec->pcm_rec + codec->num_pcms;
3491 codec->num_pcms++;
3492 info->name = "AD1984 Digital Mic";
3493 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3494 return 0;
3495}
3496
3497/* models */
3498enum {
3499 AD1984_BASIC,
3500 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003501 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003502 AD1984_MODELS
3503};
3504
3505static const char *ad1984_models[AD1984_MODELS] = {
3506 [AD1984_BASIC] = "basic",
3507 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003508 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003509};
3510
3511static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3512 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003513 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003514 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003515 {}
3516};
3517
3518static int patch_ad1984(struct hda_codec *codec)
3519{
3520 struct ad198x_spec *spec;
3521 int board_config, err;
3522
3523 err = patch_ad1884(codec);
3524 if (err < 0)
3525 return err;
3526 spec = codec->spec;
3527 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3528 ad1984_models, ad1984_cfg_tbl);
3529 switch (board_config) {
3530 case AD1984_BASIC:
3531 /* additional digital mics */
3532 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3533 codec->patch_ops.build_pcms = ad1984_build_pcms;
3534 break;
3535 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003536 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003537 spec->input_mux = &ad1984_thinkpad_capture_source;
3538 spec->mixers[0] = ad1984_thinkpad_mixers;
3539 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3540 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003541 case AD1984_DELL_DESKTOP:
3542 spec->multiout.dig_out_nid = 0;
3543 spec->input_mux = &ad1984_dell_desktop_capture_source;
3544 spec->mixers[0] = ad1984_dell_desktop_mixers;
3545 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003546 }
3547 return 0;
3548}
3549
3550
3551/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003552 * AD1883 / AD1884A / AD1984A / AD1984B
3553 *
3554 * port-B (0x14) - front mic-in
3555 * port-E (0x1c) - rear mic-in
3556 * port-F (0x16) - CD / ext out
3557 * port-C (0x15) - rear line-in
3558 * port-D (0x12) - rear line-out
3559 * port-A (0x11) - front hp-out
3560 *
3561 * AD1984A = AD1884A + digital-mic
3562 * AD1883 = equivalent with AD1984A
3563 * AD1984B = AD1984A + extra SPDIF-out
3564 *
3565 * FIXME:
3566 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3567 */
3568
3569static hda_nid_t ad1884a_dac_nids[1] = {
3570 0x03,
3571};
3572
3573#define ad1884a_adc_nids ad1884_adc_nids
3574#define ad1884a_capsrc_nids ad1884_capsrc_nids
3575
3576#define AD1884A_SPDIF_OUT 0x02
3577
3578static struct hda_input_mux ad1884a_capture_source = {
3579 .num_items = 5,
3580 .items = {
3581 { "Front Mic", 0x0 },
3582 { "Mic", 0x4 },
3583 { "Line", 0x1 },
3584 { "CD", 0x2 },
3585 { "Mix", 0x3 },
3586 },
3587};
3588
3589static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3590 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3591 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3592 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3593 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3594 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3595 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3596 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3597 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3598 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3599 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3600 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3601 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3602 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3603 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3604 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3605 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003606 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3607 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3608 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3609 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3610 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3611 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3612 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3613 {
3614 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3615 /* The multiple "Capture Source" controls confuse alsamixer
3616 * So call somewhat different..
3617 */
3618 /* .name = "Capture Source", */
3619 .name = "Input Source",
3620 .count = 2,
3621 .info = ad198x_mux_enum_info,
3622 .get = ad198x_mux_enum_get,
3623 .put = ad198x_mux_enum_put,
3624 },
3625 /* SPDIF controls */
3626 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3627 {
3628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3629 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3630 /* identical with ad1983 */
3631 .info = ad1983_spdif_route_info,
3632 .get = ad1983_spdif_route_get,
3633 .put = ad1983_spdif_route_put,
3634 },
3635 { } /* end */
3636};
3637
3638/*
3639 * initialization verbs
3640 */
3641static struct hda_verb ad1884a_init_verbs[] = {
3642 /* DACs; unmute as default */
3643 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3644 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3645 /* Port-A (HP) mixer - route only from analog mixer */
3646 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3647 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3648 /* Port-A pin */
3649 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3650 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3651 /* Port-D (Line-out) mixer - route only from analog mixer */
3652 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3653 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3654 /* Port-D pin */
3655 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3656 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3657 /* Mono-out mixer - route only from analog mixer */
3658 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3659 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3660 /* Mono-out pin */
3661 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3662 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3663 /* Port-B (front mic) pin */
3664 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003665 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003666 /* Port-C (rear line-in) pin */
3667 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003668 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003669 /* Port-E (rear mic) pin */
3670 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3671 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3672 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3673 /* Port-F (CD) pin */
3674 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3675 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3676 /* Analog mixer; mute as default */
3677 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3678 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3679 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3680 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3681 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3682 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3683 /* Analog Mix output amp */
3684 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3685 /* capture sources */
3686 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3687 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3688 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3689 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3690 /* SPDIF output amp */
3691 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3692 { } /* end */
3693};
3694
3695#ifdef CONFIG_SND_HDA_POWER_SAVE
3696static struct hda_amp_list ad1884a_loopbacks[] = {
3697 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3698 { 0x20, HDA_INPUT, 1 }, /* Mic */
3699 { 0x20, HDA_INPUT, 2 }, /* CD */
3700 { 0x20, HDA_INPUT, 4 }, /* Docking */
3701 { } /* end */
3702};
3703#endif
3704
3705/*
3706 * Laptop model
3707 *
3708 * Port A: Headphone jack
3709 * Port B: MIC jack
3710 * Port C: Internal MIC
3711 * Port D: Dock Line Out (if enabled)
3712 * Port E: Dock Line In (if enabled)
3713 * Port F: Internal speakers
3714 */
3715
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003716static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3717 struct snd_ctl_elem_value *ucontrol)
3718{
3719 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3720 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3721 int mute = (!ucontrol->value.integer.value[0] &&
3722 !ucontrol->value.integer.value[1]);
3723 /* toggle GPIO1 according to the mute state */
3724 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3725 mute ? 0x02 : 0x0);
3726 return ret;
3727}
Takashi Iwaic5059252008-02-16 09:43:56 +01003728
3729static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3730 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003731 {
3732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3733 .name = "Master Playback Switch",
3734 .info = snd_hda_mixer_amp_switch_info,
3735 .get = snd_hda_mixer_amp_switch_get,
3736 .put = ad1884a_mobile_master_sw_put,
3737 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3738 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003739 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3740 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3741 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3742 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3743 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3744 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3745 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3746 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3747 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003748 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3749 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3750 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003753 { } /* end */
3754};
3755
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003756static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3757 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db17e2009-07-02 16:10:23 +02003758 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3759 {
3760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3761 .name = "Master Playback Switch",
3762 .info = snd_hda_mixer_amp_switch_info,
3763 .get = snd_hda_mixer_amp_switch_get,
3764 .put = ad1884a_mobile_master_sw_put,
3765 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3766 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003767 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3768 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003769 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3770 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003771 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3772 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003773 { } /* end */
3774};
3775
Takashi Iwaic5059252008-02-16 09:43:56 +01003776/* mute internal speaker if HP is plugged */
3777static void ad1884a_hp_automute(struct hda_codec *codec)
3778{
3779 unsigned int present;
3780
3781 present = snd_hda_codec_read(codec, 0x11, 0,
3782 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3783 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3784 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3785 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3786 present ? 0x00 : 0x02);
3787}
3788
Takashi Iwai269ef192008-05-30 15:32:15 +02003789/* switch to external mic if plugged */
3790static void ad1884a_hp_automic(struct hda_codec *codec)
3791{
3792 unsigned int present;
3793
3794 present = snd_hda_codec_read(codec, 0x14, 0,
3795 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3796 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3797 present ? 0 : 1);
3798}
3799
Takashi Iwaic5059252008-02-16 09:43:56 +01003800#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02003801#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01003802
3803/* unsolicited event for HP jack sensing */
3804static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3805{
Takashi Iwai269ef192008-05-30 15:32:15 +02003806 switch (res >> 26) {
3807 case AD1884A_HP_EVENT:
3808 ad1884a_hp_automute(codec);
3809 break;
3810 case AD1884A_MIC_EVENT:
3811 ad1884a_hp_automic(codec);
3812 break;
3813 }
Takashi Iwaic5059252008-02-16 09:43:56 +01003814}
3815
3816/* initialize jack-sensing, too */
3817static int ad1884a_hp_init(struct hda_codec *codec)
3818{
3819 ad198x_init(codec);
3820 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02003821 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01003822 return 0;
3823}
3824
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003825/* mute internal speaker if HP or docking HP is plugged */
3826static void ad1884a_laptop_automute(struct hda_codec *codec)
3827{
3828 unsigned int present;
3829
3830 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0);
3831 present &= AC_PINSENSE_PRESENCE;
3832 if (!present) {
3833 present = snd_hda_codec_read(codec, 0x12, 0,
3834 AC_VERB_GET_PIN_SENSE, 0);
3835 present &= AC_PINSENSE_PRESENCE;
3836 }
3837 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3838 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3839 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3840 present ? 0x00 : 0x02);
3841}
3842
3843/* switch to external mic if plugged */
3844static void ad1884a_laptop_automic(struct hda_codec *codec)
3845{
3846 unsigned int idx;
3847
3848 if (snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0) &
3849 AC_PINSENSE_PRESENCE)
3850 idx = 0;
3851 else if (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) &
3852 AC_PINSENSE_PRESENCE)
3853 idx = 4;
3854 else
3855 idx = 1;
3856 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3857}
3858
3859/* unsolicited event for HP jack sensing */
3860static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3861 unsigned int res)
3862{
3863 switch (res >> 26) {
3864 case AD1884A_HP_EVENT:
3865 ad1884a_laptop_automute(codec);
3866 break;
3867 case AD1884A_MIC_EVENT:
3868 ad1884a_laptop_automic(codec);
3869 break;
3870 }
3871}
3872
3873/* initialize jack-sensing, too */
3874static int ad1884a_laptop_init(struct hda_codec *codec)
3875{
3876 ad198x_init(codec);
3877 ad1884a_laptop_automute(codec);
3878 ad1884a_laptop_automic(codec);
3879 return 0;
3880}
3881
Takashi Iwaic5059252008-02-16 09:43:56 +01003882/* additional verbs for laptop model */
3883static struct hda_verb ad1884a_laptop_verbs[] = {
3884 /* Port-A (HP) pin - always unmuted */
3885 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3886 /* Port-F (int speaker) mixer - route only from analog mixer */
3887 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3888 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08003889 /* Port-F (int speaker) pin */
3890 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01003891 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08003892 /* required for compaq 6530s/6531s speaker output */
3893 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003894 /* Port-C pin - internal mic-in */
3895 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3896 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3897 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02003898 /* Port-D (docking line-out) pin - default unmuted */
3899 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01003900 /* analog mix */
3901 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3902 /* unsolicited event for pin-sense */
3903 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003904 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003905 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003906 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02003907 /* allow to touch GPIO1 (for mute control) */
3908 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3909 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3910 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01003911 { } /* end */
3912};
3913
Takashi Iwai73156132009-04-23 08:24:48 +02003914static struct hda_verb ad1884a_mobile_verbs[] = {
3915 /* DACs; unmute as default */
3916 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3917 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3918 /* Port-A (HP) mixer - route only from analog mixer */
3919 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3920 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3921 /* Port-A pin */
3922 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3923 /* Port-A (HP) pin - always unmuted */
3924 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3925 /* Port-B (mic jack) pin */
3926 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3927 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3928 /* Port-C (int mic) pin */
3929 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3930 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3931 /* Port-F (int speaker) mixer - route only from analog mixer */
3932 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3933 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3934 /* Port-F pin */
3935 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3936 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3937 /* Analog mixer; mute as default */
3938 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3939 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3940 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3941 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3942 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3943 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3944 /* Analog Mix output amp */
3945 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3946 /* capture sources */
3947 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3948 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3949 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3950 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3951 /* unsolicited event for pin-sense */
3952 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3953 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db17e2009-07-02 16:10:23 +02003954 /* allow to touch GPIO1 (for mute control) */
3955 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3956 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3957 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02003958 { } /* end */
3959};
3960
Takashi Iwaic5059252008-02-16 09:43:56 +01003961/*
Takashi Iwaif0813742008-03-18 12:13:03 +01003962 * Thinkpad X300
3963 * 0x11 - HP
3964 * 0x12 - speaker
3965 * 0x14 - mic-in
3966 * 0x17 - built-in mic
3967 */
3968
3969static struct hda_verb ad1984a_thinkpad_verbs[] = {
3970 /* HP unmute */
3971 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3972 /* analog mix */
3973 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3974 /* turn on EAPD */
3975 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3976 /* unsolicited event for pin-sense */
3977 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3978 /* internal mic - dmic */
3979 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02003980 /* set magic COEFs for dmic */
3981 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3982 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01003983 { } /* end */
3984};
3985
3986static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3987 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3988 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3989 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3990 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3991 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3992 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01003993 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3994 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3995 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3996 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3997 {
3998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3999 .name = "Capture Source",
4000 .info = ad198x_mux_enum_info,
4001 .get = ad198x_mux_enum_get,
4002 .put = ad198x_mux_enum_put,
4003 },
4004 { } /* end */
4005};
4006
4007static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4008 .num_items = 3,
4009 .items = {
4010 { "Mic", 0x0 },
4011 { "Internal Mic", 0x5 },
4012 { "Mix", 0x3 },
4013 },
4014};
4015
4016/* mute internal speaker if HP is plugged */
4017static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4018{
4019 unsigned int present;
4020
4021 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
4022 & AC_PINSENSE_PRESENCE;
4023 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4024 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4025}
4026
4027/* unsolicited event for HP jack sensing */
4028static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4029 unsigned int res)
4030{
4031 if ((res >> 26) != AD1884A_HP_EVENT)
4032 return;
4033 ad1984a_thinkpad_automute(codec);
4034}
4035
4036/* initialize jack-sensing, too */
4037static int ad1984a_thinkpad_init(struct hda_codec *codec)
4038{
4039 ad198x_init(codec);
4040 ad1984a_thinkpad_automute(codec);
4041 return 0;
4042}
4043
4044/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004045 * HP Touchsmart
4046 * port-A (0x11) - front hp-out
4047 * port-B (0x14) - unused
4048 * port-C (0x15) - unused
4049 * port-D (0x12) - rear line out
4050 * port-E (0x1c) - front mic-in
4051 * port-F (0x16) - Internal speakers
4052 * digital-mic (0x17) - Internal mic
4053 */
4054
4055static struct hda_verb ad1984a_touchsmart_verbs[] = {
4056 /* DACs; unmute as default */
4057 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4058 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4059 /* Port-A (HP) mixer - route only from analog mixer */
4060 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4061 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4062 /* Port-A pin */
4063 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4064 /* Port-A (HP) pin - always unmuted */
4065 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4066 /* Port-E (int speaker) mixer - route only from analog mixer */
4067 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4068 /* Port-E pin */
4069 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4070 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4071 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4072 /* Port-F (int speaker) mixer - route only from analog mixer */
4073 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4074 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4075 /* Port-F pin */
4076 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4077 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4078 /* Analog mixer; mute as default */
4079 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4080 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4081 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4082 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4083 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4084 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4085 /* Analog Mix output amp */
4086 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4087 /* capture sources */
4088 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4089 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4090 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4091 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4092 /* unsolicited event for pin-sense */
4093 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4094 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4095 /* allow to touch GPIO1 (for mute control) */
4096 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4097 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4098 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4099 /* internal mic - dmic */
4100 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4101 /* set magic COEFs for dmic */
4102 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4103 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4104 { } /* end */
4105};
4106
4107static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4108 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4109/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4110 {
4111 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4112 .name = "Master Playback Switch",
4113 .info = snd_hda_mixer_amp_switch_info,
4114 .get = snd_hda_mixer_amp_switch_get,
4115 .put = ad1884a_mobile_master_sw_put,
4116 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4117 },
4118 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4119 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4120 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4121 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4122 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4123 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4124 { } /* end */
4125};
4126
4127/* switch to external mic if plugged */
4128static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4129{
4130 if (snd_hda_codec_read(codec, 0x1c, 0,
4131 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000) {
4132 snd_hda_codec_write(codec, 0x0c, 0,
4133 AC_VERB_SET_CONNECT_SEL, 0x4);
4134 } else {
4135 snd_hda_codec_write(codec, 0x0c, 0,
4136 AC_VERB_SET_CONNECT_SEL, 0x5);
4137 }
4138}
4139
4140
4141/* unsolicited event for HP jack sensing */
4142static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4143 unsigned int res)
4144{
4145 switch (res >> 26) {
4146 case AD1884A_HP_EVENT:
4147 ad1884a_hp_automute(codec);
4148 break;
4149 case AD1884A_MIC_EVENT:
4150 ad1984a_touchsmart_automic(codec);
4151 break;
4152 }
4153}
4154
4155/* initialize jack-sensing, too */
4156static int ad1984a_touchsmart_init(struct hda_codec *codec)
4157{
4158 ad198x_init(codec);
4159 ad1884a_hp_automute(codec);
4160 ad1984a_touchsmart_automic(codec);
4161 return 0;
4162}
4163
4164
4165/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004166 */
4167
4168enum {
4169 AD1884A_DESKTOP,
4170 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004171 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004172 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004173 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004174 AD1884A_MODELS
4175};
4176
4177static const char *ad1884a_models[AD1884A_MODELS] = {
4178 [AD1884A_DESKTOP] = "desktop",
4179 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004180 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004181 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004182 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004183};
4184
4185static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4186 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004187 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004188 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004189 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004190 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004191 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4192 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004193 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004194 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004195 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004196 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004197};
4198
4199static int patch_ad1884a(struct hda_codec *codec)
4200{
4201 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004202 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004203
4204 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4205 if (spec == NULL)
4206 return -ENOMEM;
4207
Takashi Iwaic5059252008-02-16 09:43:56 +01004208 codec->spec = spec;
4209
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004210 err = snd_hda_attach_beep_device(codec, 0x10);
4211 if (err < 0) {
4212 ad198x_free(codec);
4213 return err;
4214 }
4215 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4216
Takashi Iwaic5059252008-02-16 09:43:56 +01004217 spec->multiout.max_channels = 2;
4218 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4219 spec->multiout.dac_nids = ad1884a_dac_nids;
4220 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4221 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4222 spec->adc_nids = ad1884a_adc_nids;
4223 spec->capsrc_nids = ad1884a_capsrc_nids;
4224 spec->input_mux = &ad1884a_capture_source;
4225 spec->num_mixers = 1;
4226 spec->mixers[0] = ad1884a_base_mixers;
4227 spec->num_init_verbs = 1;
4228 spec->init_verbs[0] = ad1884a_init_verbs;
4229 spec->spdif_route = 0;
4230#ifdef CONFIG_SND_HDA_POWER_SAVE
4231 spec->loopback.amplist = ad1884a_loopbacks;
4232#endif
4233 codec->patch_ops = ad198x_patch_ops;
4234
4235 /* override some parameters */
4236 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004237 ad1884a_models,
4238 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004239 switch (board_config) {
4240 case AD1884A_LAPTOP:
4241 spec->mixers[0] = ad1884a_laptop_mixers;
4242 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4243 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004244 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4245 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004246 /* set the upper-limit for mixer amp to 0dB for avoiding the
4247 * possible damage by overloading
4248 */
4249 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4250 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4251 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4252 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4253 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004254 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004255 case AD1884A_MOBILE:
4256 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004257 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004258 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004259 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4260 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004261 /* set the upper-limit for mixer amp to 0dB for avoiding the
4262 * possible damage by overloading
4263 */
4264 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4265 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4266 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4267 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4268 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004269 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004270 case AD1884A_THINKPAD:
4271 spec->mixers[0] = ad1984a_thinkpad_mixers;
4272 spec->init_verbs[spec->num_init_verbs++] =
4273 ad1984a_thinkpad_verbs;
4274 spec->multiout.dig_out_nid = 0;
4275 spec->input_mux = &ad1984a_thinkpad_capture_source;
4276 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4277 codec->patch_ops.init = ad1984a_thinkpad_init;
4278 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004279 case AD1984A_TOUCHSMART:
4280 spec->mixers[0] = ad1984a_touchsmart_mixers;
4281 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4282 spec->multiout.dig_out_nid = 0;
4283 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4284 codec->patch_ops.init = ad1984a_touchsmart_init;
4285 /* set the upper-limit for mixer amp to 0dB for avoiding the
4286 * possible damage by overloading
4287 */
4288 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4289 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4290 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4291 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4292 (1 << AC_AMPCAP_MUTE_SHIFT));
4293 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004294 }
4295
4296 return 0;
4297}
4298
4299
4300/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004301 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004302 *
4303 * port-A - front hp-out
4304 * port-B - front mic-in
4305 * port-C - rear line-in, shared surr-out (3stack)
4306 * port-D - rear line-out
4307 * port-E - rear mic-in, shared clfe-out (3stack)
4308 * port-F - rear surr-out (6stack)
4309 * port-G - rear clfe-out (6stack)
4310 */
4311
4312static hda_nid_t ad1882_dac_nids[3] = {
4313 0x04, 0x03, 0x05
4314};
4315
4316static hda_nid_t ad1882_adc_nids[2] = {
4317 0x08, 0x09,
4318};
4319
4320static hda_nid_t ad1882_capsrc_nids[2] = {
4321 0x0c, 0x0d,
4322};
4323
4324#define AD1882_SPDIF_OUT 0x02
4325
4326/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4327static struct hda_input_mux ad1882_capture_source = {
4328 .num_items = 5,
4329 .items = {
4330 { "Front Mic", 0x1 },
4331 { "Mic", 0x4 },
4332 { "Line", 0x2 },
4333 { "CD", 0x3 },
4334 { "Mix", 0x7 },
4335 },
4336};
4337
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004338/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4339static struct hda_input_mux ad1882a_capture_source = {
4340 .num_items = 5,
4341 .items = {
4342 { "Front Mic", 0x1 },
4343 { "Mic", 0x4},
4344 { "Line", 0x2 },
4345 { "Digital Mic", 0x06 },
4346 { "Mix", 0x7 },
4347 },
4348};
4349
Takashi Iwai0ac85512007-06-20 15:46:13 +02004350static struct snd_kcontrol_new ad1882_base_mixers[] = {
4351 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4352 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4353 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4354 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4355 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4356 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4357 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4358 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004359
Takashi Iwai0ac85512007-06-20 15:46:13 +02004360 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4361 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4362 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4363 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4364 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4365 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4366 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4367 {
4368 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4369 /* The multiple "Capture Source" controls confuse alsamixer
4370 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004371 */
4372 /* .name = "Capture Source", */
4373 .name = "Input Source",
4374 .count = 2,
4375 .info = ad198x_mux_enum_info,
4376 .get = ad198x_mux_enum_get,
4377 .put = ad198x_mux_enum_put,
4378 },
4379 /* SPDIF controls */
4380 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4381 {
4382 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4383 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4384 /* identical with ad1983 */
4385 .info = ad1983_spdif_route_info,
4386 .get = ad1983_spdif_route_get,
4387 .put = ad1983_spdif_route_put,
4388 },
4389 { } /* end */
4390};
4391
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004392static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4393 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4394 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4395 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4396 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4397 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4398 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4399 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4400 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004401 { } /* end */
4402};
4403
4404static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4405 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4406 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4407 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4408 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4409 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4410 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4411 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4412 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004413 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4414 { } /* end */
4415};
4416
Takashi Iwai0ac85512007-06-20 15:46:13 +02004417static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4418 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4419 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4420 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4421 {
4422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4423 .name = "Channel Mode",
4424 .info = ad198x_ch_mode_info,
4425 .get = ad198x_ch_mode_get,
4426 .put = ad198x_ch_mode_put,
4427 },
4428 { } /* end */
4429};
4430
4431static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4432 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4433 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4434 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4435 { } /* end */
4436};
4437
4438static struct hda_verb ad1882_ch2_init[] = {
4439 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4440 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4441 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4442 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4443 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4444 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4445 { } /* end */
4446};
4447
4448static struct hda_verb ad1882_ch4_init[] = {
4449 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4450 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4451 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4452 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4453 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4454 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4455 { } /* end */
4456};
4457
4458static struct hda_verb ad1882_ch6_init[] = {
4459 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4460 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4461 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4462 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4463 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4464 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4465 { } /* end */
4466};
4467
4468static struct hda_channel_mode ad1882_modes[3] = {
4469 { 2, ad1882_ch2_init },
4470 { 4, ad1882_ch4_init },
4471 { 6, ad1882_ch6_init },
4472};
4473
4474/*
4475 * initialization verbs
4476 */
4477static struct hda_verb ad1882_init_verbs[] = {
4478 /* DACs; mute as default */
4479 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4480 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4481 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4482 /* Port-A (HP) mixer */
4483 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4484 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4485 /* Port-A pin */
4486 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4487 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4488 /* HP selector - select DAC2 */
4489 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4490 /* Port-D (Line-out) mixer */
4491 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4492 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4493 /* Port-D pin */
4494 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4495 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4496 /* Mono-out mixer */
4497 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4498 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4499 /* Mono-out pin */
4500 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4501 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4502 /* Port-B (front mic) pin */
4503 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4504 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4505 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4506 /* Port-C (line-in) pin */
4507 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4508 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4509 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4510 /* Port-C mixer - mute as input */
4511 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4512 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4513 /* Port-E (mic-in) pin */
4514 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4515 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4516 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4517 /* Port-E mixer - mute as input */
4518 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4519 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4520 /* Port-F (surround) */
4521 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4522 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4523 /* Port-G (CLFE) */
4524 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4525 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4526 /* Analog mixer; mute as default */
4527 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4528 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4529 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4530 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4531 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4532 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4533 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4534 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4535 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4536 /* Analog Mix output amp */
4537 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4538 /* SPDIF output selector */
4539 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4540 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4541 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4542 { } /* end */
4543};
4544
Takashi Iwaicb53c622007-08-10 17:21:45 +02004545#ifdef CONFIG_SND_HDA_POWER_SAVE
4546static struct hda_amp_list ad1882_loopbacks[] = {
4547 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4548 { 0x20, HDA_INPUT, 1 }, /* Mic */
4549 { 0x20, HDA_INPUT, 4 }, /* Line */
4550 { 0x20, HDA_INPUT, 6 }, /* CD */
4551 { } /* end */
4552};
4553#endif
4554
Takashi Iwai0ac85512007-06-20 15:46:13 +02004555/* models */
4556enum {
4557 AD1882_3STACK,
4558 AD1882_6STACK,
4559 AD1882_MODELS
4560};
4561
4562static const char *ad1882_models[AD1986A_MODELS] = {
4563 [AD1882_3STACK] = "3stack",
4564 [AD1882_6STACK] = "6stack",
4565};
4566
4567
4568static int patch_ad1882(struct hda_codec *codec)
4569{
4570 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004571 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004572
4573 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4574 if (spec == NULL)
4575 return -ENOMEM;
4576
Takashi Iwai0ac85512007-06-20 15:46:13 +02004577 codec->spec = spec;
4578
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004579 err = snd_hda_attach_beep_device(codec, 0x10);
4580 if (err < 0) {
4581 ad198x_free(codec);
4582 return err;
4583 }
4584 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4585
Takashi Iwai0ac85512007-06-20 15:46:13 +02004586 spec->multiout.max_channels = 6;
4587 spec->multiout.num_dacs = 3;
4588 spec->multiout.dac_nids = ad1882_dac_nids;
4589 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4590 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4591 spec->adc_nids = ad1882_adc_nids;
4592 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004593 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004594 spec->input_mux = &ad1882_capture_source;
4595 else
4596 spec->input_mux = &ad1882a_capture_source;
4597 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004598 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004599 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004600 spec->mixers[1] = ad1882_loopback_mixers;
4601 else
4602 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004603 spec->num_init_verbs = 1;
4604 spec->init_verbs[0] = ad1882_init_verbs;
4605 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004606#ifdef CONFIG_SND_HDA_POWER_SAVE
4607 spec->loopback.amplist = ad1882_loopbacks;
4608#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004609 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004610
4611 codec->patch_ops = ad198x_patch_ops;
4612
4613 /* override some parameters */
4614 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4615 ad1882_models, NULL);
4616 switch (board_config) {
4617 default:
4618 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004619 spec->num_mixers = 3;
4620 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004621 spec->channel_mode = ad1882_modes;
4622 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4623 spec->need_dac_fix = 1;
4624 spec->multiout.max_channels = 2;
4625 spec->multiout.num_dacs = 1;
4626 break;
4627 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004628 spec->num_mixers = 3;
4629 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004630 break;
4631 }
4632 return 0;
4633}
4634
4635
4636/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 * patch entries
4638 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004639static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004640 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004641 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004642 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004643 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004644 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4645 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004646 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4647 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004648 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004650 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004651 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004652 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004653 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4654 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 {} /* terminator */
4656};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004657
4658MODULE_ALIAS("snd-hda-codec-id:11d4*");
4659
4660MODULE_LICENSE("GPL");
4661MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4662
4663static struct hda_codec_preset_list analog_list = {
4664 .preset = snd_hda_preset_analog,
4665 .owner = THIS_MODULE,
4666};
4667
4668static int __init patch_analog_init(void)
4669{
4670 return snd_hda_add_codec_preset(&analog_list);
4671}
4672
4673static void __exit patch_analog_exit(void)
4674{
4675 snd_hda_delete_codec_preset(&analog_list);
4676}
4677
4678module_init(patch_analog_init)
4679module_exit(patch_analog_exit)