blob: 455a0494f907ad45771082adea3d0a428feee81e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02002 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Takashi Iwai2bac6472007-05-18 18:21:41 +02005 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010030#include "hda_beep.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010035 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020064 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010065
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020066 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010067
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +020070 struct snd_array kctls;
Takashi Iwaid32410b12005-11-24 16:06:23 +010071 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020072 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +020073
Takashi Iwai8ab78c72007-09-06 14:29:53 +020074 unsigned int jack_present :1;
Takashi 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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-11-17 14:57:47 +0100328 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200329{
330 struct ad198x_spec *spec = codec->spec;
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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwai825aa972006-03-17 10:50:49 +0100662/* laptop-eapd model - 2ch only */
663
Takashi Iwai825aa972006-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 Iwai825aa972006-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 Iwai825aa972006-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;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100723 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100724 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
725 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100726 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100727}
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;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200765
Takashi Iwaid56757a2009-11-18 08:00:14 +0100766 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200767 if (spec->inv_jack_detect)
768 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200769 ad1986a_update_hp(codec);
770}
771
772#define AD1986A_HP_EVENT 0x37
773
774static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
775{
776 if ((res >> 26) != AD1986A_HP_EVENT)
777 return;
778 ad1986a_hp_automute(codec);
779}
780
781static int ad1986a_hp_init(struct hda_codec *codec)
782{
783 ad198x_init(codec);
784 ad1986a_hp_automute(codec);
785 return 0;
786}
787
788/* bind hp and internal speaker mute (with plug check) */
789static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_value *ucontrol)
791{
792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
793 long *valp = ucontrol->value.integer.value;
794 int change;
795
796 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
797 HDA_AMP_MUTE,
798 valp[0] ? 0 : HDA_AMP_MUTE);
799 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
800 HDA_AMP_MUTE,
801 valp[1] ? 0 : HDA_AMP_MUTE);
802 if (change)
803 ad1986a_update_hp(codec);
804 return change;
805}
806
Takashi Iwai16d11a82009-06-24 14:07:53 +0200807static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200808 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
809 {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Master Playback Switch",
812 .info = snd_hda_mixer_amp_switch_info,
813 .get = snd_hda_mixer_amp_switch_get,
814 .put = ad1986a_hp_master_sw_put,
815 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
816 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200817 { } /* end */
818};
819
Takashi Iwai16d11a82009-06-24 14:07:53 +0200820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821/*
822 * initialization verbs
823 */
824static struct hda_verb ad1986a_init_verbs[] = {
825 /* Front, Surround, CLFE DAC; mute as default */
826 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
827 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
828 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
829 /* Downmix - off */
830 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
831 /* HP, Line-Out, Surround, CLFE selectors */
832 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
833 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
834 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
835 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
836 /* Mono selector */
837 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
838 /* Mic selector: Mic 1/2 pin */
839 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
840 /* Line-in selector: Line-in */
841 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
842 /* Mic 1/2 swap */
843 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
844 /* Record selector: mic */
845 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
846 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
847 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
848 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
849 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
851 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
852 /* PC beep */
853 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
854 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
855 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
856 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
857 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
858 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
859 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200860 /* HP Pin */
861 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
862 /* Front, Surround, CLFE Pins */
863 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
864 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
865 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
866 /* Mono Pin */
867 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
868 /* Mic Pin */
869 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
870 /* Line, Aux, CD, Beep-In Pin */
871 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
872 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
873 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
874 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
875 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 { } /* end */
877};
878
Takashi Iwai9230d212006-03-13 13:49:49 +0100879static struct hda_verb ad1986a_ch2_init[] = {
880 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200881 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
882 /* Line-in selectors */
883 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100884 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200885 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
886 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
887 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100888 { } /* end */
889};
890
891static struct hda_verb ad1986a_ch4_init[] = {
892 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200893 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
894 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100895 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200896 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
897 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100898 { } /* end */
899};
900
901static struct hda_verb ad1986a_ch6_init[] = {
902 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200903 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
904 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100905 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200906 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
907 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100908 { } /* end */
909};
910
911static struct hda_channel_mode ad1986a_modes[3] = {
912 { 2, ad1986a_ch2_init },
913 { 4, ad1986a_ch4_init },
914 { 6, ad1986a_ch6_init },
915};
916
Takashi Iwai825aa972006-03-17 10:50:49 +0100917/* eapd initialization */
918static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100919 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +0100920 {}
921};
922
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100923static struct hda_verb ad1986a_automic_verbs[] = {
924 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
925 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
926 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
927 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
928 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
929 {}
930};
931
Tobin Davisf36090f2007-01-08 11:07:12 +0100932/* Ultra initialization */
933static struct hda_verb ad1986a_ultra_init[] = {
934 /* eapd initialization */
935 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
936 /* CLFE -> Mic in */
937 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
938 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
939 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
940 { } /* end */
941};
942
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200943/* pin sensing on HP jack */
944static struct hda_verb ad1986a_hp_init_verbs[] = {
945 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
946 {}
947};
948
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200949static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
950 unsigned int res)
951{
952 switch (res >> 26) {
953 case AD1986A_HP_EVENT:
954 ad1986a_hp_automute(codec);
955 break;
956 case AD1986A_MIC_EVENT:
957 ad1986a_automic(codec);
958 break;
959 }
960}
961
962static int ad1986a_samsung_p50_init(struct hda_codec *codec)
963{
964 ad198x_init(codec);
965 ad1986a_hp_automute(codec);
966 ad1986a_automic(codec);
967 return 0;
968}
969
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200970
Takashi Iwai9230d212006-03-13 13:49:49 +0100971/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100972enum {
973 AD1986A_6STACK,
974 AD1986A_3STACK,
975 AD1986A_LAPTOP,
976 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200977 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +0100978 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +0100979 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200980 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100981 AD1986A_MODELS
982};
Takashi Iwai9230d212006-03-13 13:49:49 +0100983
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100984static const char *ad1986a_models[AD1986A_MODELS] = {
985 [AD1986A_6STACK] = "6stack",
986 [AD1986A_3STACK] = "3stack",
987 [AD1986A_LAPTOP] = "laptop",
988 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200989 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +0100990 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +0100991 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +0200992 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100993};
994
995static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
996 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100997 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100998 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100999 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001000 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1001 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1002 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1003 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001004 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001005 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001006 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1007 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1008 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1009 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1010 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001011 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Takashi Iwai7db756f2007-12-24 14:36:09 +01001012 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
Tobin Davis18768992007-03-12 22:20:51 +01001013 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001014 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001015 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001016 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001017 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001018 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001019 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001020 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001021 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001022 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001023 {}
1024};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Takashi Iwaicb53c622007-08-10 17:21:45 +02001026#ifdef CONFIG_SND_HDA_POWER_SAVE
1027static struct hda_amp_list ad1986a_loopbacks[] = {
1028 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1029 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1030 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1031 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1032 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1033 { } /* end */
1034};
1035#endif
1036
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001037static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1038{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001039 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001040 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1041}
1042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043static int patch_ad1986a(struct hda_codec *codec)
1044{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001045 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001046 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001048 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (spec == NULL)
1050 return -ENOMEM;
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 codec->spec = spec;
1053
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001054 err = snd_hda_attach_beep_device(codec, 0x19);
1055 if (err < 0) {
1056 ad198x_free(codec);
1057 return err;
1058 }
1059 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 spec->multiout.max_channels = 6;
1062 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1063 spec->multiout.dac_nids = ad1986a_dac_nids;
1064 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001065 spec->num_adc_nids = 1;
1066 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001067 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001068 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001069 spec->num_mixers = 1;
1070 spec->mixers[0] = ad1986a_mixers;
1071 spec->num_init_verbs = 1;
1072 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001073#ifdef CONFIG_SND_HDA_POWER_SAVE
1074 spec->loopback.amplist = ad1986a_loopbacks;
1075#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001076 spec->vmaster_nid = 0x1b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001078 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Takashi Iwai9230d212006-03-13 13:49:49 +01001080 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001081 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1082 ad1986a_models,
1083 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001084 switch (board_config) {
1085 case AD1986A_3STACK:
1086 spec->num_mixers = 2;
1087 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001088 spec->num_init_verbs = 2;
1089 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001090 spec->channel_mode = ad1986a_modes;
1091 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001092 spec->need_dac_fix = 1;
1093 spec->multiout.max_channels = 2;
1094 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001095 break;
1096 case AD1986A_LAPTOP:
1097 spec->mixers[0] = ad1986a_laptop_mixers;
1098 spec->multiout.max_channels = 2;
1099 spec->multiout.num_dacs = 1;
1100 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1101 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001102 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001103 spec->num_mixers = 3;
1104 spec->mixers[0] = ad1986a_laptop_master_mixers;
1105 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1106 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001107 spec->num_init_verbs = 2;
1108 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1109 spec->multiout.max_channels = 2;
1110 spec->multiout.num_dacs = 1;
1111 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1112 if (!is_jack_available(codec, 0x25))
1113 spec->multiout.dig_out_nid = 0;
1114 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1115 break;
1116 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001117 spec->num_mixers = 2;
1118 spec->mixers[0] = ad1986a_laptop_master_mixers;
1119 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001120 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001121 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001122 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001123 spec->multiout.max_channels = 2;
1124 spec->multiout.num_dacs = 1;
1125 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001126 if (!is_jack_available(codec, 0x25))
1127 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001128 spec->input_mux = &ad1986a_automic_capture_source;
1129 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1130 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001131 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001132 case AD1986A_SAMSUNG_P50:
1133 spec->num_mixers = 2;
1134 spec->mixers[0] = ad1986a_automute_master_mixers;
1135 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1136 spec->num_init_verbs = 4;
1137 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1138 spec->init_verbs[2] = ad1986a_automic_verbs;
1139 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1140 spec->multiout.max_channels = 2;
1141 spec->multiout.num_dacs = 1;
1142 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1143 if (!is_jack_available(codec, 0x25))
1144 spec->multiout.dig_out_nid = 0;
1145 spec->input_mux = &ad1986a_automic_capture_source;
1146 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1147 codec->patch_ops.init = ad1986a_samsung_p50_init;
1148 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001149 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001150 spec->num_mixers = 3;
1151 spec->mixers[0] = ad1986a_automute_master_mixers;
1152 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1153 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001154 spec->num_init_verbs = 3;
1155 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1156 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1157 spec->multiout.max_channels = 2;
1158 spec->multiout.num_dacs = 1;
1159 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001160 if (!is_jack_available(codec, 0x25))
1161 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001162 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1163 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1164 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001165 /* Lenovo N100 seems to report the reversed bit
1166 * for HP jack-sensing
1167 */
1168 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001169 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001170 case AD1986A_ULTRA:
1171 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1172 spec->num_init_verbs = 2;
1173 spec->init_verbs[1] = ad1986a_ultra_init;
1174 spec->multiout.max_channels = 2;
1175 spec->multiout.num_dacs = 1;
1176 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1177 spec->multiout.dig_out_nid = 0;
1178 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001179 }
1180
Takashi Iwaid29240c2007-10-26 12:35:56 +02001181 /* AD1986A has a hardware problem that it can't share a stream
1182 * with multiple output pins. The copy of front to surrounds
1183 * causes noisy or silent outputs at a certain timing, e.g.
1184 * changing the volume.
1185 * So, let's disable the shared stream.
1186 */
1187 spec->multiout.no_share_stream = 1;
1188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 return 0;
1190}
1191
1192/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001193 * AD1983 specific
1194 */
1195
1196#define AD1983_SPDIF_OUT 0x02
1197#define AD1983_DAC 0x03
1198#define AD1983_ADC 0x04
1199
1200static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001201static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001202static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001203
1204static struct hda_input_mux ad1983_capture_source = {
1205 .num_items = 4,
1206 .items = {
1207 { "Mic", 0x0 },
1208 { "Line", 0x1 },
1209 { "Mix", 0x2 },
1210 { "Mix Mono", 0x3 },
1211 },
1212};
1213
1214/*
1215 * SPDIF playback route
1216 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001217static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001218{
1219 static char *texts[] = { "PCM", "ADC" };
1220
1221 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1222 uinfo->count = 1;
1223 uinfo->value.enumerated.items = 2;
1224 if (uinfo->value.enumerated.item > 1)
1225 uinfo->value.enumerated.item = 1;
1226 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1227 return 0;
1228}
1229
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001230static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001231{
1232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1233 struct ad198x_spec *spec = codec->spec;
1234
1235 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1236 return 0;
1237}
1238
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001239static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001240{
1241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1242 struct ad198x_spec *spec = codec->spec;
1243
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001244 if (ucontrol->value.enumerated.item[0] > 1)
1245 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001246 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1247 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001248 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1249 AC_VERB_SET_CONNECT_SEL,
1250 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001251 return 1;
1252 }
1253 return 0;
1254}
1255
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001256static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001257 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1258 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1259 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1260 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1261 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1262 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1263 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1264 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1265 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1266 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1267 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1268 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001269 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1270 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1271 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1272 {
1273 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1274 .name = "Capture Source",
1275 .info = ad198x_mux_enum_info,
1276 .get = ad198x_mux_enum_get,
1277 .put = ad198x_mux_enum_put,
1278 },
1279 {
1280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001281 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001282 .info = ad1983_spdif_route_info,
1283 .get = ad1983_spdif_route_get,
1284 .put = ad1983_spdif_route_put,
1285 },
1286 { } /* end */
1287};
1288
1289static struct hda_verb ad1983_init_verbs[] = {
1290 /* Front, HP, Mono; mute as default */
1291 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1292 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1293 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1294 /* Beep, PCM, Mic, Line-In: mute */
1295 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1296 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1297 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1298 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1299 /* Front, HP selectors; from Mix */
1300 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1301 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1302 /* Mono selector; from Mix */
1303 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1304 /* Mic selector; Mic */
1305 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1306 /* Line-in selector: Line-in */
1307 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1308 /* Mic boost: 0dB */
1309 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1310 /* Record selector: mic */
1311 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1312 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1313 /* SPDIF route: PCM */
1314 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1315 /* Front Pin */
1316 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1317 /* HP Pin */
1318 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1319 /* Mono Pin */
1320 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1321 /* Mic Pin */
1322 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1323 /* Line Pin */
1324 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1325 { } /* end */
1326};
1327
Takashi Iwaicb53c622007-08-10 17:21:45 +02001328#ifdef CONFIG_SND_HDA_POWER_SAVE
1329static struct hda_amp_list ad1983_loopbacks[] = {
1330 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1331 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1332 { } /* end */
1333};
1334#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001335
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001336static int patch_ad1983(struct hda_codec *codec)
1337{
1338 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001339 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001340
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001341 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001342 if (spec == NULL)
1343 return -ENOMEM;
1344
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001345 codec->spec = spec;
1346
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001347 err = snd_hda_attach_beep_device(codec, 0x10);
1348 if (err < 0) {
1349 ad198x_free(codec);
1350 return err;
1351 }
1352 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1353
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001354 spec->multiout.max_channels = 2;
1355 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1356 spec->multiout.dac_nids = ad1983_dac_nids;
1357 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001358 spec->num_adc_nids = 1;
1359 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001360 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001361 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001362 spec->num_mixers = 1;
1363 spec->mixers[0] = ad1983_mixers;
1364 spec->num_init_verbs = 1;
1365 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001366 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001367#ifdef CONFIG_SND_HDA_POWER_SAVE
1368 spec->loopback.amplist = ad1983_loopbacks;
1369#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001370 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001371
1372 codec->patch_ops = ad198x_patch_ops;
1373
1374 return 0;
1375}
1376
1377
1378/*
1379 * AD1981 HD specific
1380 */
1381
1382#define AD1981_SPDIF_OUT 0x02
1383#define AD1981_DAC 0x03
1384#define AD1981_ADC 0x04
1385
1386static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001387static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001388static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001389
1390/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1391static struct hda_input_mux ad1981_capture_source = {
1392 .num_items = 7,
1393 .items = {
1394 { "Front Mic", 0x0 },
1395 { "Line", 0x1 },
1396 { "Mix", 0x2 },
1397 { "Mix Mono", 0x3 },
1398 { "CD", 0x4 },
1399 { "Mic", 0x6 },
1400 { "Aux", 0x7 },
1401 },
1402};
1403
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001404static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001405 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1406 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1407 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1408 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1409 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1410 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1411 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1412 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1413 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1414 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1415 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1416 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1417 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1418 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1419 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1420 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1421 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1422 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001423 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1424 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1425 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1426 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1427 {
1428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1429 .name = "Capture Source",
1430 .info = ad198x_mux_enum_info,
1431 .get = ad198x_mux_enum_get,
1432 .put = ad198x_mux_enum_put,
1433 },
1434 /* identical with AD1983 */
1435 {
1436 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001437 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001438 .info = ad1983_spdif_route_info,
1439 .get = ad1983_spdif_route_get,
1440 .put = ad1983_spdif_route_put,
1441 },
1442 { } /* end */
1443};
1444
1445static struct hda_verb ad1981_init_verbs[] = {
1446 /* Front, HP, Mono; mute as default */
1447 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1448 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1449 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1450 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1451 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1452 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1453 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1454 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1455 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1456 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1458 /* Front, HP selectors; from Mix */
1459 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1460 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1461 /* Mono selector; from Mix */
1462 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1463 /* Mic Mixer; select Front Mic */
1464 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1465 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1466 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001467 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1468 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001469 /* Record selector: Front mic */
1470 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1471 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1472 /* SPDIF route: PCM */
1473 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1474 /* Front Pin */
1475 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1476 /* HP Pin */
1477 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1478 /* Mono Pin */
1479 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1480 /* Front & Rear Mic Pins */
1481 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1482 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1483 /* Line Pin */
1484 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1485 /* Digital Beep */
1486 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1487 /* Line-Out as Input: disabled */
1488 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1489 { } /* end */
1490};
1491
Takashi Iwaicb53c622007-08-10 17:21:45 +02001492#ifdef CONFIG_SND_HDA_POWER_SAVE
1493static struct hda_amp_list ad1981_loopbacks[] = {
1494 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1495 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1496 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1497 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1498 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1499 { } /* end */
1500};
1501#endif
1502
Takashi Iwai18a815d2006-03-01 19:54:39 +01001503/*
1504 * Patch for HP nx6320
1505 *
Tobin Davis18768992007-03-12 22:20:51 +01001506 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001507 * speaker output enabled _and_ mute-LED off.
1508 */
1509
1510#define AD1981_HP_EVENT 0x37
1511#define AD1981_MIC_EVENT 0x38
1512
1513static struct hda_verb ad1981_hp_init_verbs[] = {
1514 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1515 /* pin sensing on HP and Mic jacks */
1516 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1517 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1518 {}
1519};
1520
1521/* turn on/off EAPD (+ mute HP) as a master switch */
1522static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1523 struct snd_ctl_elem_value *ucontrol)
1524{
1525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1526 struct ad198x_spec *spec = codec->spec;
1527
1528 if (! ad198x_eapd_put(kcontrol, ucontrol))
1529 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001530 /* change speaker pin appropriately */
1531 snd_hda_codec_write(codec, 0x05, 0,
1532 AC_VERB_SET_PIN_WIDGET_CONTROL,
1533 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001534 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001535 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1536 HDA_AMP_MUTE,
1537 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001538 return 1;
1539}
1540
1541/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001542static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1543 .ops = &snd_hda_bind_vol,
1544 .values = {
1545 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1546 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1547 0
1548 },
1549};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001550
1551/* mute internal speaker if HP is plugged */
1552static void ad1981_hp_automute(struct hda_codec *codec)
1553{
1554 unsigned int present;
1555
Takashi Iwaid56757a2009-11-18 08:00:14 +01001556 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001557 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1558 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001559}
1560
1561/* toggle input of built-in and mic jack appropriately */
1562static void ad1981_hp_automic(struct hda_codec *codec)
1563{
1564 static struct hda_verb mic_jack_on[] = {
1565 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1566 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1567 {}
1568 };
1569 static struct hda_verb mic_jack_off[] = {
1570 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1571 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1572 {}
1573 };
1574 unsigned int present;
1575
Takashi Iwaid56757a2009-11-18 08:00:14 +01001576 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001577 if (present)
1578 snd_hda_sequence_write(codec, mic_jack_on);
1579 else
1580 snd_hda_sequence_write(codec, mic_jack_off);
1581}
1582
1583/* unsolicited event for HP jack sensing */
1584static void ad1981_hp_unsol_event(struct hda_codec *codec,
1585 unsigned int res)
1586{
1587 res >>= 26;
1588 switch (res) {
1589 case AD1981_HP_EVENT:
1590 ad1981_hp_automute(codec);
1591 break;
1592 case AD1981_MIC_EVENT:
1593 ad1981_hp_automic(codec);
1594 break;
1595 }
1596}
1597
1598static struct hda_input_mux ad1981_hp_capture_source = {
1599 .num_items = 3,
1600 .items = {
1601 { "Mic", 0x0 },
1602 { "Docking-Station", 0x1 },
1603 { "Mix", 0x2 },
1604 },
1605};
1606
1607static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001608 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001609 {
1610 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1611 .name = "Master Playback Switch",
1612 .info = ad198x_eapd_info,
1613 .get = ad198x_eapd_get,
1614 .put = ad1981_hp_master_sw_put,
1615 .private_value = 0x05,
1616 },
1617 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1618 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1619#if 0
1620 /* FIXME: analog mic/line loopback doesn't work with my tests...
1621 * (although recording is OK)
1622 */
1623 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1624 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1625 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1626 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1627 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1628 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1629 /* FIXME: does this laptop have analog CD connection? */
1630 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1631 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1632#endif
1633 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1634 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1635 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1636 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1637 {
1638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1639 .name = "Capture Source",
1640 .info = ad198x_mux_enum_info,
1641 .get = ad198x_mux_enum_get,
1642 .put = ad198x_mux_enum_put,
1643 },
1644 { } /* end */
1645};
1646
1647/* initialize jack-sensing, too */
1648static int ad1981_hp_init(struct hda_codec *codec)
1649{
1650 ad198x_init(codec);
1651 ad1981_hp_automute(codec);
1652 ad1981_hp_automic(codec);
1653 return 0;
1654}
1655
Tobin Davis18768992007-03-12 22:20:51 +01001656/* configuration for Toshiba Laptops */
1657static struct hda_verb ad1981_toshiba_init_verbs[] = {
1658 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1659 /* pin sensing on HP and Mic jacks */
1660 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1661 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1662 {}
1663};
1664
1665static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1666 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1667 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1668 { }
1669};
1670
Takashi Iwai01686c52006-04-18 12:54:11 +02001671/* configuration for Lenovo Thinkpad T60 */
1672static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1673 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1674 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1675 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1676 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1677 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1678 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1679 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1681 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1682 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1683 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1684 {
1685 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1686 .name = "Capture Source",
1687 .info = ad198x_mux_enum_info,
1688 .get = ad198x_mux_enum_get,
1689 .put = ad198x_mux_enum_put,
1690 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001691 /* identical with AD1983 */
1692 {
1693 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1694 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1695 .info = ad1983_spdif_route_info,
1696 .get = ad1983_spdif_route_get,
1697 .put = ad1983_spdif_route_put,
1698 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001699 { } /* end */
1700};
1701
1702static struct hda_input_mux ad1981_thinkpad_capture_source = {
1703 .num_items = 3,
1704 .items = {
1705 { "Mic", 0x0 },
1706 { "Mix", 0x2 },
1707 { "CD", 0x4 },
1708 },
1709};
1710
Takashi Iwai18a815d2006-03-01 19:54:39 +01001711/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001712enum {
1713 AD1981_BASIC,
1714 AD1981_HP,
1715 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001716 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001717 AD1981_MODELS
1718};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001719
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001720static const char *ad1981_models[AD1981_MODELS] = {
1721 [AD1981_HP] = "hp",
1722 [AD1981_THINKPAD] = "thinkpad",
1723 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001724 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001725};
1726
1727static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001728 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001729 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001730 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001731 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001732 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c52006-04-18 12:54:11 +02001733 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001734 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001735 /* HP nx6320 (reversed SSID, H/W bug) */
1736 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001737 {}
1738};
1739
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001740static int patch_ad1981(struct hda_codec *codec)
1741{
1742 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001743 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001744
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001745 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001746 if (spec == NULL)
1747 return -ENOMEM;
1748
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001749 codec->spec = spec;
1750
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001751 err = snd_hda_attach_beep_device(codec, 0x10);
1752 if (err < 0) {
1753 ad198x_free(codec);
1754 return err;
1755 }
1756 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1757
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001758 spec->multiout.max_channels = 2;
1759 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1760 spec->multiout.dac_nids = ad1981_dac_nids;
1761 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001762 spec->num_adc_nids = 1;
1763 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001764 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001765 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001766 spec->num_mixers = 1;
1767 spec->mixers[0] = ad1981_mixers;
1768 spec->num_init_verbs = 1;
1769 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001770 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001771#ifdef CONFIG_SND_HDA_POWER_SAVE
1772 spec->loopback.amplist = ad1981_loopbacks;
1773#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001774 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001775
1776 codec->patch_ops = ad198x_patch_ops;
1777
Takashi Iwai18a815d2006-03-01 19:54:39 +01001778 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001779 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1780 ad1981_models,
1781 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001782 switch (board_config) {
1783 case AD1981_HP:
1784 spec->mixers[0] = ad1981_hp_mixers;
1785 spec->num_init_verbs = 2;
1786 spec->init_verbs[1] = ad1981_hp_init_verbs;
1787 spec->multiout.dig_out_nid = 0;
1788 spec->input_mux = &ad1981_hp_capture_source;
1789
1790 codec->patch_ops.init = ad1981_hp_init;
1791 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1792 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001793 case AD1981_THINKPAD:
1794 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001795 spec->input_mux = &ad1981_thinkpad_capture_source;
1796 break;
Tobin Davis18768992007-03-12 22:20:51 +01001797 case AD1981_TOSHIBA:
1798 spec->mixers[0] = ad1981_hp_mixers;
1799 spec->mixers[1] = ad1981_toshiba_mixers;
1800 spec->num_init_verbs = 2;
1801 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1802 spec->multiout.dig_out_nid = 0;
1803 spec->input_mux = &ad1981_hp_capture_source;
1804 codec->patch_ops.init = ad1981_hp_init;
1805 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1806 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001807 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001808 return 0;
1809}
1810
1811
1812/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001813 * AD1988
1814 *
1815 * Output pins and routes
1816 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001817 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001818 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1819 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1820 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1821 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1822 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1823 * port-F 0x16 (mute) <- 0x2a <- 06
1824 * port-G 0x24 (mute) <- 0x27 <- 05
1825 * port-H 0x25 (mute) <- 0x28 <- 0a
1826 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1827 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001828 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1829 * (*) 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 +01001830 *
1831 * Input pins and routes
1832 *
1833 * pin boost mix input # / adc input #
1834 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1835 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1836 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1837 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1838 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1839 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1840 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1841 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1842 *
1843 *
1844 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001845 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001846 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001847 *
1848 * Inputs of Analog Mix (0x20)
1849 * 0:Port-B (front mic)
1850 * 1:Port-C/G/H (line-in)
1851 * 2:Port-A
1852 * 3:Port-D (line-in/2)
1853 * 4:Port-E/G/H (mic-in)
1854 * 5:Port-F (mic2-in)
1855 * 6:CD
1856 * 7:Beep
1857 *
1858 * ADC selection
1859 * 0:Port-A
1860 * 1:Port-B (front mic-in)
1861 * 2:Port-C (line-in)
1862 * 3:Port-F (mic2-in)
1863 * 4:Port-E (mic-in)
1864 * 5:CD
1865 * 6:Port-G
1866 * 7:Port-H
1867 * 8:Port-D (line-in/2)
1868 * 9:Mix
1869 *
1870 * Proposed pin assignments by the datasheet
1871 *
1872 * 6-stack
1873 * Port-A front headphone
1874 * B front mic-in
1875 * C rear line-in
1876 * D rear front-out
1877 * E rear mic-in
1878 * F rear surround
1879 * G rear CLFE
1880 * H rear side
1881 *
1882 * 3-stack
1883 * Port-A front headphone
1884 * B front mic
1885 * C rear line-in/surround
1886 * D rear front-out
1887 * E rear mic-in/CLFE
1888 *
1889 * laptop
1890 * Port-A headphone
1891 * B mic-in
1892 * C docking station
1893 * D internal speaker (with EAPD)
1894 * E/F quad mic array
1895 */
1896
1897
1898/* models */
1899enum {
1900 AD1988_6STACK,
1901 AD1988_6STACK_DIG,
1902 AD1988_3STACK,
1903 AD1988_3STACK_DIG,
1904 AD1988_LAPTOP,
1905 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001906 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001907 AD1988_MODEL_LAST,
1908};
1909
Takashi Iwaid32410b12005-11-24 16:06:23 +01001910/* reivision id to check workarounds */
1911#define AD1988A_REV2 0x100200
1912
Takashi Iwai1a806f42006-07-03 15:58:16 +02001913#define is_rev2(codec) \
1914 ((codec)->vendor_id == 0x11d41988 && \
1915 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001916
1917/*
1918 * mixers
1919 */
1920
Takashi Iwaid32410b12005-11-24 16:06:23 +01001921static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001922 0x04, 0x06, 0x05, 0x0a
1923};
1924
Takashi Iwaid32410b12005-11-24 16:06:23 +01001925static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001926 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001927};
1928
1929/* for AD1988A revision-2, DAC2-4 are swapped */
1930static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1931 0x04, 0x05, 0x0a, 0x06
1932};
1933
1934static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001935 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001936};
1937
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001938static hda_nid_t ad1988_adc_nids[3] = {
1939 0x08, 0x09, 0x0f
1940};
1941
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001942static hda_nid_t ad1988_capsrc_nids[3] = {
1943 0x0c, 0x0d, 0x0e
1944};
1945
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001946#define AD1988_SPDIF_OUT 0x02
1947#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001948#define AD1988_SPDIF_IN 0x07
1949
Takashi Iwai3a08e302009-02-13 11:37:08 +01001950static hda_nid_t ad1989b_slave_dig_outs[] = {
1951 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07001952};
1953
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001954static struct hda_input_mux ad1988_6stack_capture_source = {
1955 .num_items = 5,
1956 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001957 { "Front Mic", 0x1 }, /* port-B */
1958 { "Line", 0x2 }, /* port-C */
1959 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001960 { "CD", 0x5 },
1961 { "Mix", 0x9 },
1962 },
1963};
1964
1965static struct hda_input_mux ad1988_laptop_capture_source = {
1966 .num_items = 3,
1967 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001968 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001969 { "CD", 0x5 },
1970 { "Mix", 0x9 },
1971 },
1972};
1973
1974/*
1975 */
1976static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1977 struct snd_ctl_elem_info *uinfo)
1978{
1979 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1980 struct ad198x_spec *spec = codec->spec;
1981 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1982 spec->num_channel_mode);
1983}
1984
1985static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1986 struct snd_ctl_elem_value *ucontrol)
1987{
1988 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1989 struct ad198x_spec *spec = codec->spec;
1990 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1991 spec->num_channel_mode, spec->multiout.max_channels);
1992}
1993
1994static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1995 struct snd_ctl_elem_value *ucontrol)
1996{
1997 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1998 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001999 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2000 spec->num_channel_mode,
2001 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002002 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002003 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002004 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002005}
2006
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002007/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002008static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002009 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2010 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2011 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2012 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2013 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002014 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002015};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002016
Takashi Iwaid32410b12005-11-24 16:06:23 +01002017static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2018 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2019 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2020 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2021 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2022 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002023 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002024};
2025
2026static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002027 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2028 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2029 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2030 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2031 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2032 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2033 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2034
2035 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2036 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2037 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2038 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2039 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2040 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2041 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2042 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2043
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002044 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002045 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2046
2047 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2048 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2049
2050 { } /* end */
2051};
2052
2053/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002054static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002055 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002056 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002057 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2058 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002059 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002060};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002061
Takashi Iwaid32410b12005-11-24 16:06:23 +01002062static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2063 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002064 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2065 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2066 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002067 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002068};
2069
2070static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002071 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002072 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2073 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2074 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002075 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2076 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2077
2078 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2079 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2080 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2081 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2082 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2083 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2084 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2085 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2086
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002087 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002088 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2089
2090 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2091 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2092 {
2093 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2094 .name = "Channel Mode",
2095 .info = ad198x_ch_mode_info,
2096 .get = ad198x_ch_mode_get,
2097 .put = ad198x_ch_mode_put,
2098 },
2099
2100 { } /* end */
2101};
2102
2103/* laptop mode */
2104static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2105 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2106 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2107 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2108
2109 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2110 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2111 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2112 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2113 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2114 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2115
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002116 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002117 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2118
2119 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2120
2121 {
2122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2123 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01002124 .info = ad198x_eapd_info,
2125 .get = ad198x_eapd_get,
2126 .put = ad198x_eapd_put,
2127 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002128 },
2129
2130 { } /* end */
2131};
2132
2133/* capture */
2134static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2135 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2136 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2137 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2138 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2139 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2140 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2141 {
2142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2143 /* The multiple "Capture Source" controls confuse alsamixer
2144 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002145 */
2146 /* .name = "Capture Source", */
2147 .name = "Input Source",
2148 .count = 3,
2149 .info = ad198x_mux_enum_info,
2150 .get = ad198x_mux_enum_get,
2151 .put = ad198x_mux_enum_put,
2152 },
2153 { } /* end */
2154};
2155
2156static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2157 struct snd_ctl_elem_info *uinfo)
2158{
2159 static char *texts[] = {
2160 "PCM", "ADC1", "ADC2", "ADC3"
2161 };
2162 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2163 uinfo->count = 1;
2164 uinfo->value.enumerated.items = 4;
2165 if (uinfo->value.enumerated.item >= 4)
2166 uinfo->value.enumerated.item = 3;
2167 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2168 return 0;
2169}
2170
2171static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2172 struct snd_ctl_elem_value *ucontrol)
2173{
2174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2175 unsigned int sel;
2176
Takashi Iwaibddcf542007-07-24 18:04:05 +02002177 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2178 AC_AMP_GET_INPUT);
2179 if (!(sel & 0x80))
2180 ucontrol->value.enumerated.item[0] = 0;
2181 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002182 sel = snd_hda_codec_read(codec, 0x0b, 0,
2183 AC_VERB_GET_CONNECT_SEL, 0);
2184 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002185 sel++;
2186 else
2187 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002188 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002189 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002190 return 0;
2191}
2192
2193static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2194 struct snd_ctl_elem_value *ucontrol)
2195{
2196 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002197 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002198 int change;
2199
Takashi Iwai35b26722007-05-05 12:17:17 +02002200 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002201 if (val > 3)
2202 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002203 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002204 sel = snd_hda_codec_read(codec, 0x1d, 0,
2205 AC_VERB_GET_AMP_GAIN_MUTE,
2206 AC_AMP_GET_INPUT);
2207 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002208 if (change) {
2209 snd_hda_codec_write_cache(codec, 0x1d, 0,
2210 AC_VERB_SET_AMP_GAIN_MUTE,
2211 AMP_IN_UNMUTE(0));
2212 snd_hda_codec_write_cache(codec, 0x1d, 0,
2213 AC_VERB_SET_AMP_GAIN_MUTE,
2214 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002215 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002216 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002217 sel = snd_hda_codec_read(codec, 0x1d, 0,
2218 AC_VERB_GET_AMP_GAIN_MUTE,
2219 AC_AMP_GET_INPUT | 0x01);
2220 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002221 if (change) {
2222 snd_hda_codec_write_cache(codec, 0x1d, 0,
2223 AC_VERB_SET_AMP_GAIN_MUTE,
2224 AMP_IN_MUTE(0));
2225 snd_hda_codec_write_cache(codec, 0x1d, 0,
2226 AC_VERB_SET_AMP_GAIN_MUTE,
2227 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002228 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002229 sel = snd_hda_codec_read(codec, 0x0b, 0,
2230 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2231 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002232 if (change)
2233 snd_hda_codec_write_cache(codec, 0x0b, 0,
2234 AC_VERB_SET_CONNECT_SEL,
2235 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002236 }
2237 return change;
2238}
2239
2240static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2241 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2242 {
2243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2244 .name = "IEC958 Playback Source",
2245 .info = ad1988_spdif_playback_source_info,
2246 .get = ad1988_spdif_playback_source_get,
2247 .put = ad1988_spdif_playback_source_put,
2248 },
2249 { } /* end */
2250};
2251
2252static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2253 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2254 { } /* end */
2255};
2256
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002257static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2258 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002259 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002260 { } /* end */
2261};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002262
2263/*
2264 * initialization verbs
2265 */
2266
2267/*
2268 * for 6-stack (+dig)
2269 */
2270static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002271 /* Front, Surround, CLFE, side DAC; unmute as default */
2272 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2273 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2274 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2275 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002276 /* Port-A front headphon path */
2277 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2278 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2279 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2280 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2281 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2282 /* Port-D line-out path */
2283 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2284 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2285 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2286 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2287 /* Port-F surround path */
2288 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2289 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2290 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2291 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2292 /* Port-G CLFE path */
2293 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2294 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2295 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2296 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2297 /* Port-H side path */
2298 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2299 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2300 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2301 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 /* Mono out path */
2303 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2304 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2305 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2306 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2307 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2308 /* Port-B front mic-in path */
2309 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2310 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2311 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2312 /* Port-C line-in path */
2313 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2314 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2315 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2316 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2317 /* Port-E mic-in path */
2318 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2319 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2320 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2321 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002322 /* Analog CD Input */
2323 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002324 /* Analog Mix output amp */
2325 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002326
2327 { }
2328};
2329
2330static struct hda_verb ad1988_capture_init_verbs[] = {
2331 /* mute analog mix */
2332 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2333 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2334 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2335 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2336 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2337 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2338 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2339 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2340 /* select ADCs - front-mic */
2341 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2342 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2343 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002344
2345 { }
2346};
2347
2348static struct hda_verb ad1988_spdif_init_verbs[] = {
2349 /* SPDIF out sel */
2350 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2351 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2352 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002353 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002354 /* SPDIF out pin */
2355 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002356
2357 { }
2358};
2359
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002360/* AD1989 has no ADC -> SPDIF route */
2361static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002362 /* SPDIF-1 out pin */
2363 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002364 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002365 /* SPDIF-2/HDMI out pin */
2366 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2367 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002368 { }
2369};
2370
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002371/*
2372 * verbs for 3stack (+dig)
2373 */
2374static struct hda_verb ad1988_3stack_ch2_init[] = {
2375 /* set port-C to line-in */
2376 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2377 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2378 /* set port-E to mic-in */
2379 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2380 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2381 { } /* end */
2382};
2383
2384static struct hda_verb ad1988_3stack_ch6_init[] = {
2385 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002386 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002387 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002388 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002389 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002390 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002391 { } /* end */
2392};
2393
2394static struct hda_channel_mode ad1988_3stack_modes[2] = {
2395 { 2, ad1988_3stack_ch2_init },
2396 { 6, ad1988_3stack_ch6_init },
2397};
2398
2399static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002400 /* Front, Surround, CLFE, side DAC; unmute as default */
2401 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2402 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2403 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2404 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002405 /* Port-A front headphon path */
2406 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2407 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2408 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2409 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2410 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2411 /* Port-D line-out path */
2412 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2413 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2414 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2415 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2416 /* Mono out path */
2417 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2418 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2419 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2420 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2421 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2422 /* Port-B front mic-in path */
2423 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2424 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2425 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002426 /* Port-C line-in/surround path - 6ch mode as default */
2427 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2428 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002429 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002430 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002431 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002432 /* Port-E mic-in/CLFE path - 6ch mode as default */
2433 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2434 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002435 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002436 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002437 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2438 /* mute analog mix */
2439 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2440 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2441 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2442 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2443 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2444 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2445 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2446 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2447 /* select ADCs - front-mic */
2448 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2449 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2450 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002451 /* Analog Mix output amp */
2452 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002453 { }
2454};
2455
2456/*
2457 * verbs for laptop mode (+dig)
2458 */
2459static struct hda_verb ad1988_laptop_hp_on[] = {
2460 /* unmute port-A and mute port-D */
2461 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2462 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2463 { } /* end */
2464};
2465static struct hda_verb ad1988_laptop_hp_off[] = {
2466 /* mute port-A and unmute port-D */
2467 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2468 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2469 { } /* end */
2470};
2471
2472#define AD1988_HP_EVENT 0x01
2473
2474static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002475 /* Front, Surround, CLFE, side DAC; unmute as default */
2476 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2477 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2478 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2479 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002480 /* Port-A front headphon path */
2481 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2482 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2483 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2484 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2486 /* unsolicited event for pin-sense */
2487 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2488 /* Port-D line-out path + EAPD */
2489 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2490 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2491 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2493 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2494 /* Mono out path */
2495 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2496 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2497 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2498 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2499 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2500 /* Port-B mic-in path */
2501 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2502 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2503 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2504 /* Port-C docking station - try to output */
2505 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2506 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2507 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2508 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2509 /* mute analog mix */
2510 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2511 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2512 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2513 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2514 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2515 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2516 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2517 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2518 /* select ADCs - mic */
2519 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2520 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2521 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002522 /* Analog Mix output amp */
2523 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002524 { }
2525};
2526
2527static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2528{
2529 if ((res >> 26) != AD1988_HP_EVENT)
2530 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002531 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002532 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2533 else
2534 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2535}
2536
Takashi Iwaicb53c622007-08-10 17:21:45 +02002537#ifdef CONFIG_SND_HDA_POWER_SAVE
2538static struct hda_amp_list ad1988_loopbacks[] = {
2539 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2540 { 0x20, HDA_INPUT, 1 }, /* Line */
2541 { 0x20, HDA_INPUT, 4 }, /* Mic */
2542 { 0x20, HDA_INPUT, 6 }, /* CD */
2543 { } /* end */
2544};
2545#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002546
2547/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002548 * Automatic parse of I/O pins from the BIOS configuration
2549 */
2550
Takashi Iwaid32410b12005-11-24 16:06:23 +01002551enum {
2552 AD_CTL_WIDGET_VOL,
2553 AD_CTL_WIDGET_MUTE,
2554 AD_CTL_BIND_MUTE,
2555};
2556static struct snd_kcontrol_new ad1988_control_templates[] = {
2557 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2558 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2559 HDA_BIND_MUTE(NULL, 0, 0, 0),
2560};
2561
2562/* add dynamic controls */
2563static int add_control(struct ad198x_spec *spec, int type, const char *name,
2564 unsigned long val)
2565{
2566 struct snd_kcontrol_new *knew;
2567
Takashi Iwai603c4012008-07-30 15:01:44 +02002568 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2569 knew = snd_array_new(&spec->kctls);
2570 if (!knew)
2571 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002572 *knew = ad1988_control_templates[type];
2573 knew->name = kstrdup(name, GFP_KERNEL);
2574 if (! knew->name)
2575 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002576 if (get_amp_nid_(val))
Takashi Iwai9c96fa52009-11-16 11:25:33 +01002577 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002578 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002579 return 0;
2580}
2581
2582#define AD1988_PIN_CD_NID 0x18
2583#define AD1988_PIN_BEEP_NID 0x10
2584
2585static hda_nid_t ad1988_mixer_nids[8] = {
2586 /* A B C D E F G H */
2587 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2588};
2589
2590static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2591{
2592 static hda_nid_t idx_to_dac[8] = {
2593 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002594 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002595 };
2596 static hda_nid_t idx_to_dac_rev2[8] = {
2597 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002598 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002599 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002600 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002601 return idx_to_dac_rev2[idx];
2602 else
2603 return idx_to_dac[idx];
2604}
2605
2606static hda_nid_t ad1988_boost_nids[8] = {
2607 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2608};
2609
2610static int ad1988_pin_idx(hda_nid_t nid)
2611{
2612 static hda_nid_t ad1988_io_pins[8] = {
2613 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2614 };
2615 int i;
2616 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2617 if (ad1988_io_pins[i] == nid)
2618 return i;
2619 return 0; /* should be -1 */
2620}
2621
2622static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2623{
2624 static int loopback_idx[8] = {
2625 2, 0, 1, 3, 4, 5, 1, 4
2626 };
2627 switch (nid) {
2628 case AD1988_PIN_CD_NID:
2629 return 6;
2630 default:
2631 return loopback_idx[ad1988_pin_idx(nid)];
2632 }
2633}
2634
2635static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2636{
2637 static int adc_idx[8] = {
2638 0, 1, 2, 8, 4, 3, 6, 7
2639 };
2640 switch (nid) {
2641 case AD1988_PIN_CD_NID:
2642 return 5;
2643 default:
2644 return adc_idx[ad1988_pin_idx(nid)];
2645 }
2646}
2647
2648/* fill in the dac_nids table from the parsed pin configuration */
2649static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2650 const struct auto_pin_cfg *cfg)
2651{
2652 struct ad198x_spec *spec = codec->spec;
2653 int i, idx;
2654
2655 spec->multiout.dac_nids = spec->private_dac_nids;
2656
2657 /* check the pins hardwired to audio widget */
2658 for (i = 0; i < cfg->line_outs; i++) {
2659 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2660 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2661 }
2662 spec->multiout.num_dacs = cfg->line_outs;
2663 return 0;
2664}
2665
2666/* add playback controls from the parsed DAC table */
2667static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2668 const struct auto_pin_cfg *cfg)
2669{
2670 char name[32];
2671 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2672 hda_nid_t nid;
2673 int i, err;
2674
2675 for (i = 0; i < cfg->line_outs; i++) {
2676 hda_nid_t dac = spec->multiout.dac_nids[i];
2677 if (! dac)
2678 continue;
2679 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2680 if (i == 2) {
2681 /* Center/LFE */
2682 err = add_control(spec, AD_CTL_WIDGET_VOL,
2683 "Center Playback Volume",
2684 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2685 if (err < 0)
2686 return err;
2687 err = add_control(spec, AD_CTL_WIDGET_VOL,
2688 "LFE Playback Volume",
2689 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2690 if (err < 0)
2691 return err;
2692 err = add_control(spec, AD_CTL_BIND_MUTE,
2693 "Center Playback Switch",
2694 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2695 if (err < 0)
2696 return err;
2697 err = add_control(spec, AD_CTL_BIND_MUTE,
2698 "LFE Playback Switch",
2699 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2700 if (err < 0)
2701 return err;
2702 } else {
2703 sprintf(name, "%s Playback Volume", chname[i]);
2704 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2705 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2706 if (err < 0)
2707 return err;
2708 sprintf(name, "%s Playback Switch", chname[i]);
2709 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2710 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2711 if (err < 0)
2712 return err;
2713 }
2714 }
2715 return 0;
2716}
2717
2718/* add playback controls for speaker and HP outputs */
2719static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2720 const char *pfx)
2721{
2722 struct ad198x_spec *spec = codec->spec;
2723 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002724 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002725 char name[32];
2726
2727 if (! pin)
2728 return 0;
2729
2730 idx = ad1988_pin_idx(pin);
2731 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002732 /* check whether the corresponding DAC was already taken */
2733 for (i = 0; i < spec->autocfg.line_outs; i++) {
2734 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2735 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2736 if (dac == nid)
2737 break;
2738 }
2739 if (i >= spec->autocfg.line_outs) {
2740 /* specify the DAC as the extra output */
2741 if (!spec->multiout.hp_nid)
2742 spec->multiout.hp_nid = nid;
2743 else
2744 spec->multiout.extra_out_nid[0] = nid;
2745 /* control HP volume/switch on the output mixer amp */
2746 sprintf(name, "%s Playback Volume", pfx);
2747 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2748 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2749 if (err < 0)
2750 return err;
2751 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002752 nid = ad1988_mixer_nids[idx];
2753 sprintf(name, "%s Playback Switch", pfx);
2754 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2755 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2756 return err;
2757 return 0;
2758}
2759
2760/* create input playback/capture controls for the given pin */
2761static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2762 const char *ctlname, int boost)
2763{
2764 char name[32];
2765 int err, idx;
2766
2767 sprintf(name, "%s Playback Volume", ctlname);
2768 idx = ad1988_pin_to_loopback_idx(pin);
2769 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2770 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2771 return err;
2772 sprintf(name, "%s Playback Switch", ctlname);
2773 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2774 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2775 return err;
2776 if (boost) {
2777 hda_nid_t bnid;
2778 idx = ad1988_pin_idx(pin);
2779 bnid = ad1988_boost_nids[idx];
2780 if (bnid) {
2781 sprintf(name, "%s Boost", ctlname);
2782 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2783 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2784
2785 }
2786 }
2787 return 0;
2788}
2789
2790/* create playback/capture controls for input pins */
2791static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2792 const struct auto_pin_cfg *cfg)
2793{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002794 struct hda_input_mux *imux = &spec->private_imux;
2795 int i, err;
2796
2797 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002798 err = new_analog_input(spec, cfg->input_pins[i],
2799 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002800 i <= AUTO_PIN_FRONT_MIC);
2801 if (err < 0)
2802 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002803 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002804 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2805 imux->num_items++;
2806 }
2807 imux->items[imux->num_items].label = "Mix";
2808 imux->items[imux->num_items].index = 9;
2809 imux->num_items++;
2810
2811 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2812 "Analog Mix Playback Volume",
2813 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2814 return err;
2815 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2816 "Analog Mix Playback Switch",
2817 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2818 return err;
2819
2820 return 0;
2821}
2822
2823static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2824 hda_nid_t nid, int pin_type,
2825 int dac_idx)
2826{
2827 /* set as output */
2828 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2829 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2830 switch (nid) {
2831 case 0x11: /* port-A - DAC 04 */
2832 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2833 break;
2834 case 0x14: /* port-B - DAC 06 */
2835 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2836 break;
2837 case 0x15: /* port-C - DAC 05 */
2838 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2839 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002840 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002841 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2842 break;
2843 case 0x13: /* mono - DAC 04 */
2844 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2845 break;
2846 }
2847}
2848
2849static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2850{
2851 struct ad198x_spec *spec = codec->spec;
2852 int i;
2853
2854 for (i = 0; i < spec->autocfg.line_outs; i++) {
2855 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2856 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2857 }
2858}
2859
2860static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2861{
2862 struct ad198x_spec *spec = codec->spec;
2863 hda_nid_t pin;
2864
Takashi Iwai82bc9552006-03-21 11:24:42 +01002865 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002866 if (pin) /* connect to front */
2867 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002868 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002869 if (pin) /* connect to front */
2870 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2871}
2872
2873static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2874{
2875 struct ad198x_spec *spec = codec->spec;
2876 int i, idx;
2877
2878 for (i = 0; i < AUTO_PIN_LAST; i++) {
2879 hda_nid_t nid = spec->autocfg.input_pins[i];
2880 if (! nid)
2881 continue;
2882 switch (nid) {
2883 case 0x15: /* port-C */
2884 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2885 break;
2886 case 0x17: /* port-E */
2887 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2888 break;
2889 }
2890 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2891 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2892 if (nid != AD1988_PIN_CD_NID)
2893 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2894 AMP_OUT_MUTE);
2895 idx = ad1988_pin_idx(nid);
2896 if (ad1988_boost_nids[idx])
2897 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2898 AC_VERB_SET_AMP_GAIN_MUTE,
2899 AMP_OUT_ZERO);
2900 }
2901}
2902
2903/* parse the BIOS configuration and set up the alc_spec */
2904/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2905static int ad1988_parse_auto_config(struct hda_codec *codec)
2906{
2907 struct ad198x_spec *spec = codec->spec;
2908 int err;
2909
Kailang Yangdf694da2005-12-05 19:42:22 +01002910 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002911 return err;
2912 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2913 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002914 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002915 return 0; /* can't find valid BIOS pin config */
2916 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002917 (err = ad1988_auto_create_extra_out(codec,
2918 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002919 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002920 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002921 "Headphone")) < 0 ||
2922 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2923 return err;
2924
2925 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2926
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002927 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002928 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2929 if (spec->autocfg.dig_in_pin)
2930 spec->dig_in_nid = AD1988_SPDIF_IN;
2931
Takashi Iwai603c4012008-07-30 15:01:44 +02002932 if (spec->kctls.list)
2933 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002934
2935 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2936
2937 spec->input_mux = &spec->private_imux;
2938
2939 return 1;
2940}
2941
2942/* init callback for auto-configuration model -- overriding the default init */
2943static int ad1988_auto_init(struct hda_codec *codec)
2944{
2945 ad198x_init(codec);
2946 ad1988_auto_init_multi_out(codec);
2947 ad1988_auto_init_extra_out(codec);
2948 ad1988_auto_init_analog_input(codec);
2949 return 0;
2950}
2951
2952
2953/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002954 */
2955
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002956static const char *ad1988_models[AD1988_MODEL_LAST] = {
2957 [AD1988_6STACK] = "6stack",
2958 [AD1988_6STACK_DIG] = "6stack-dig",
2959 [AD1988_3STACK] = "3stack",
2960 [AD1988_3STACK_DIG] = "3stack-dig",
2961 [AD1988_LAPTOP] = "laptop",
2962 [AD1988_LAPTOP_DIG] = "laptop-dig",
2963 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002964};
2965
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002966static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01002967 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01002968 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02002969 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07002970 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002971 {}
2972};
2973
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002974static int patch_ad1988(struct hda_codec *codec)
2975{
2976 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01002977 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002978
2979 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2980 if (spec == NULL)
2981 return -ENOMEM;
2982
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002983 codec->spec = spec;
2984
Takashi Iwai1a806f42006-07-03 15:58:16 +02002985 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002986 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2987
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002988 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002989 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002990 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02002991 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
2992 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002993 board_config = AD1988_AUTO;
2994 }
2995
2996 if (board_config == AD1988_AUTO) {
2997 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01002998 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002999 if (err < 0) {
3000 ad198x_free(codec);
3001 return err;
3002 } else if (! err) {
3003 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3004 board_config = AD1988_6STACK;
3005 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003006 }
3007
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003008 err = snd_hda_attach_beep_device(codec, 0x10);
3009 if (err < 0) {
3010 ad198x_free(codec);
3011 return err;
3012 }
3013 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3014
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003015 switch (board_config) {
3016 case AD1988_6STACK:
3017 case AD1988_6STACK_DIG:
3018 spec->multiout.max_channels = 8;
3019 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003020 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003021 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3022 else
3023 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003024 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003025 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003026 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003027 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3028 else
3029 spec->mixers[0] = ad1988_6stack_mixers1;
3030 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003031 spec->num_init_verbs = 1;
3032 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3033 if (board_config == AD1988_6STACK_DIG) {
3034 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3035 spec->dig_in_nid = AD1988_SPDIF_IN;
3036 }
3037 break;
3038 case AD1988_3STACK:
3039 case AD1988_3STACK_DIG:
3040 spec->multiout.max_channels = 6;
3041 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003042 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003043 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3044 else
3045 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003046 spec->input_mux = &ad1988_6stack_capture_source;
3047 spec->channel_mode = ad1988_3stack_modes;
3048 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003049 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003050 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003051 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3052 else
3053 spec->mixers[0] = ad1988_3stack_mixers1;
3054 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003055 spec->num_init_verbs = 1;
3056 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3057 if (board_config == AD1988_3STACK_DIG)
3058 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3059 break;
3060 case AD1988_LAPTOP:
3061 case AD1988_LAPTOP_DIG:
3062 spec->multiout.max_channels = 2;
3063 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003064 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003065 spec->input_mux = &ad1988_laptop_capture_source;
3066 spec->num_mixers = 1;
3067 spec->mixers[0] = ad1988_laptop_mixers;
3068 spec->num_init_verbs = 1;
3069 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3070 if (board_config == AD1988_LAPTOP_DIG)
3071 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3072 break;
3073 }
3074
Takashi Iwaid32410b12005-11-24 16:06:23 +01003075 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3076 spec->adc_nids = ad1988_adc_nids;
3077 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003078 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3079 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3080 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003081 if (codec->vendor_id >= 0x11d4989a) {
3082 spec->mixers[spec->num_mixers++] =
3083 ad1989_spdif_out_mixers;
3084 spec->init_verbs[spec->num_init_verbs++] =
3085 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003086 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003087 } else {
3088 spec->mixers[spec->num_mixers++] =
3089 ad1988_spdif_out_mixers;
3090 spec->init_verbs[spec->num_init_verbs++] =
3091 ad1988_spdif_init_verbs;
3092 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003093 }
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003094 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003095 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
3096
3097 codec->patch_ops = ad198x_patch_ops;
3098 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003099 case AD1988_AUTO:
3100 codec->patch_ops.init = ad1988_auto_init;
3101 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003102 case AD1988_LAPTOP:
3103 case AD1988_LAPTOP_DIG:
3104 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3105 break;
3106 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003107#ifdef CONFIG_SND_HDA_POWER_SAVE
3108 spec->loopback.amplist = ad1988_loopbacks;
3109#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003110 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003111
3112 return 0;
3113}
3114
3115
3116/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003117 * AD1884 / AD1984
3118 *
3119 * port-B - front line/mic-in
3120 * port-E - aux in/out
3121 * port-F - aux in/out
3122 * port-C - rear line/mic-in
3123 * port-D - rear line/hp-out
3124 * port-A - front line/hp-out
3125 *
3126 * AD1984 = AD1884 + two digital mic-ins
3127 *
3128 * FIXME:
3129 * For simplicity, we share the single DAC for both HP and line-outs
3130 * right now. The inidividual playbacks could be easily implemented,
3131 * but no build-up framework is given, so far.
3132 */
3133
3134static hda_nid_t ad1884_dac_nids[1] = {
3135 0x04,
3136};
3137
3138static hda_nid_t ad1884_adc_nids[2] = {
3139 0x08, 0x09,
3140};
3141
3142static hda_nid_t ad1884_capsrc_nids[2] = {
3143 0x0c, 0x0d,
3144};
3145
3146#define AD1884_SPDIF_OUT 0x02
3147
3148static struct hda_input_mux ad1884_capture_source = {
3149 .num_items = 4,
3150 .items = {
3151 { "Front Mic", 0x0 },
3152 { "Mic", 0x1 },
3153 { "CD", 0x2 },
3154 { "Mix", 0x3 },
3155 },
3156};
3157
3158static struct snd_kcontrol_new ad1884_base_mixers[] = {
3159 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3160 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3161 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3162 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3163 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3164 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3165 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3166 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3167 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3168 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3169 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3170 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003171 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3172 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3173 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3174 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3175 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3176 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3177 {
3178 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3179 /* The multiple "Capture Source" controls confuse alsamixer
3180 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003181 */
3182 /* .name = "Capture Source", */
3183 .name = "Input Source",
3184 .count = 2,
3185 .info = ad198x_mux_enum_info,
3186 .get = ad198x_mux_enum_get,
3187 .put = ad198x_mux_enum_put,
3188 },
3189 /* SPDIF controls */
3190 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3191 {
3192 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3193 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3194 /* identical with ad1983 */
3195 .info = ad1983_spdif_route_info,
3196 .get = ad1983_spdif_route_get,
3197 .put = ad1983_spdif_route_put,
3198 },
3199 { } /* end */
3200};
3201
3202static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3203 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3204 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3205 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003206 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003207 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003208 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003209 { } /* end */
3210};
3211
3212/*
3213 * initialization verbs
3214 */
3215static struct hda_verb ad1884_init_verbs[] = {
3216 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003217 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3218 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003219 /* Port-A (HP) mixer */
3220 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3221 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3222 /* Port-A pin */
3223 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3224 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3225 /* HP selector - select DAC2 */
3226 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3227 /* Port-D (Line-out) mixer */
3228 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3229 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3230 /* Port-D pin */
3231 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3232 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3233 /* Mono-out mixer */
3234 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3235 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3236 /* Mono-out pin */
3237 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3238 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3239 /* Mono selector */
3240 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3241 /* Port-B (front mic) pin */
3242 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003243 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003244 /* Port-C (rear mic) pin */
3245 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003246 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003247 /* Analog mixer; mute as default */
3248 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3249 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3250 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3251 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3252 /* Analog Mix output amp */
3253 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3254 /* SPDIF output selector */
3255 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3256 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3257 { } /* end */
3258};
3259
Takashi Iwaicb53c622007-08-10 17:21:45 +02003260#ifdef CONFIG_SND_HDA_POWER_SAVE
3261static struct hda_amp_list ad1884_loopbacks[] = {
3262 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3263 { 0x20, HDA_INPUT, 1 }, /* Mic */
3264 { 0x20, HDA_INPUT, 2 }, /* CD */
3265 { 0x20, HDA_INPUT, 4 }, /* Docking */
3266 { } /* end */
3267};
3268#endif
3269
Takashi Iwai2134ea42008-01-10 16:53:55 +01003270static const char *ad1884_slave_vols[] = {
3271 "PCM Playback Volume",
3272 "Mic Playback Volume",
3273 "Mono Playback Volume",
3274 "Front Mic Playback Volume",
3275 "Mic Playback Volume",
3276 "CD Playback Volume",
3277 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003278 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003279 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003280 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003281 NULL
3282};
3283
Takashi Iwai2bac6472007-05-18 18:21:41 +02003284static int patch_ad1884(struct hda_codec *codec)
3285{
3286 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003287 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003288
3289 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3290 if (spec == NULL)
3291 return -ENOMEM;
3292
Takashi Iwai2bac6472007-05-18 18:21:41 +02003293 codec->spec = spec;
3294
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003295 err = snd_hda_attach_beep_device(codec, 0x10);
3296 if (err < 0) {
3297 ad198x_free(codec);
3298 return err;
3299 }
3300 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3301
Takashi Iwai2bac6472007-05-18 18:21:41 +02003302 spec->multiout.max_channels = 2;
3303 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3304 spec->multiout.dac_nids = ad1884_dac_nids;
3305 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3306 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3307 spec->adc_nids = ad1884_adc_nids;
3308 spec->capsrc_nids = ad1884_capsrc_nids;
3309 spec->input_mux = &ad1884_capture_source;
3310 spec->num_mixers = 1;
3311 spec->mixers[0] = ad1884_base_mixers;
3312 spec->num_init_verbs = 1;
3313 spec->init_verbs[0] = ad1884_init_verbs;
3314 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003315#ifdef CONFIG_SND_HDA_POWER_SAVE
3316 spec->loopback.amplist = ad1884_loopbacks;
3317#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003318 spec->vmaster_nid = 0x04;
3319 /* we need to cover all playback volumes */
3320 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003321
3322 codec->patch_ops = ad198x_patch_ops;
3323
3324 return 0;
3325}
3326
3327/*
3328 * Lenovo Thinkpad T61/X61
3329 */
3330static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003331 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003332 .items = {
3333 { "Mic", 0x0 },
3334 { "Internal Mic", 0x1 },
3335 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003336 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003337 },
3338};
3339
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003340
3341/*
3342 * Dell Precision T3400
3343 */
3344static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3345 .num_items = 3,
3346 .items = {
3347 { "Front Mic", 0x0 },
3348 { "Line-In", 0x1 },
3349 { "Mix", 0x3 },
3350 },
3351};
3352
3353
Takashi Iwai2bac6472007-05-18 18:21:41 +02003354static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3355 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3356 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3357 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3358 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3359 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3360 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3361 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3362 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3363 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3364 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003365 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3366 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003367 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003368 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3369 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3370 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3371 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3372 {
3373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3374 /* The multiple "Capture Source" controls confuse alsamixer
3375 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003376 */
3377 /* .name = "Capture Source", */
3378 .name = "Input Source",
3379 .count = 2,
3380 .info = ad198x_mux_enum_info,
3381 .get = ad198x_mux_enum_get,
3382 .put = ad198x_mux_enum_put,
3383 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003384 /* SPDIF controls */
3385 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3386 {
3387 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3388 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3389 /* identical with ad1983 */
3390 .info = ad1983_spdif_route_info,
3391 .get = ad1983_spdif_route_get,
3392 .put = ad1983_spdif_route_put,
3393 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003394 { } /* end */
3395};
3396
3397/* additional verbs */
3398static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3399 /* Port-E (docking station mic) pin */
3400 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3401 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3402 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003403 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003404 /* Analog mixer - docking mic; mute as default */
3405 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003406 /* enable EAPD bit */
3407 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003408 { } /* end */
3409};
3410
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003411/*
3412 * Dell Precision T3400
3413 */
3414static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3415 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3416 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3417 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3418 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3419 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3420 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3421 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3422 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3423 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003424 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3425 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3426 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3427 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3428 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3429 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3430 {
3431 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3432 /* The multiple "Capture Source" controls confuse alsamixer
3433 * So call somewhat different..
3434 */
3435 /* .name = "Capture Source", */
3436 .name = "Input Source",
3437 .count = 2,
3438 .info = ad198x_mux_enum_info,
3439 .get = ad198x_mux_enum_get,
3440 .put = ad198x_mux_enum_put,
3441 },
3442 { } /* end */
3443};
3444
Takashi Iwai2bac6472007-05-18 18:21:41 +02003445/* Digial MIC ADC NID 0x05 + 0x06 */
3446static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3447 struct hda_codec *codec,
3448 unsigned int stream_tag,
3449 unsigned int format,
3450 struct snd_pcm_substream *substream)
3451{
3452 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3453 stream_tag, 0, format);
3454 return 0;
3455}
3456
3457static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3458 struct hda_codec *codec,
3459 struct snd_pcm_substream *substream)
3460{
Takashi Iwai888afa12008-03-18 09:57:50 +01003461 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003462 return 0;
3463}
3464
3465static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3466 .substreams = 2,
3467 .channels_min = 2,
3468 .channels_max = 2,
3469 .nid = 0x05,
3470 .ops = {
3471 .prepare = ad1984_pcm_dmic_prepare,
3472 .cleanup = ad1984_pcm_dmic_cleanup
3473 },
3474};
3475
3476static int ad1984_build_pcms(struct hda_codec *codec)
3477{
3478 struct ad198x_spec *spec = codec->spec;
3479 struct hda_pcm *info;
3480 int err;
3481
3482 err = ad198x_build_pcms(codec);
3483 if (err < 0)
3484 return err;
3485
3486 info = spec->pcm_rec + codec->num_pcms;
3487 codec->num_pcms++;
3488 info->name = "AD1984 Digital Mic";
3489 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3490 return 0;
3491}
3492
3493/* models */
3494enum {
3495 AD1984_BASIC,
3496 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003497 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003498 AD1984_MODELS
3499};
3500
3501static const char *ad1984_models[AD1984_MODELS] = {
3502 [AD1984_BASIC] = "basic",
3503 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003504 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003505};
3506
3507static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3508 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003509 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003510 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003511 {}
3512};
3513
3514static int patch_ad1984(struct hda_codec *codec)
3515{
3516 struct ad198x_spec *spec;
3517 int board_config, err;
3518
3519 err = patch_ad1884(codec);
3520 if (err < 0)
3521 return err;
3522 spec = codec->spec;
3523 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3524 ad1984_models, ad1984_cfg_tbl);
3525 switch (board_config) {
3526 case AD1984_BASIC:
3527 /* additional digital mics */
3528 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3529 codec->patch_ops.build_pcms = ad1984_build_pcms;
3530 break;
3531 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003532 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003533 spec->input_mux = &ad1984_thinkpad_capture_source;
3534 spec->mixers[0] = ad1984_thinkpad_mixers;
3535 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3536 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003537 case AD1984_DELL_DESKTOP:
3538 spec->multiout.dig_out_nid = 0;
3539 spec->input_mux = &ad1984_dell_desktop_capture_source;
3540 spec->mixers[0] = ad1984_dell_desktop_mixers;
3541 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003542 }
3543 return 0;
3544}
3545
3546
3547/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003548 * AD1883 / AD1884A / AD1984A / AD1984B
3549 *
3550 * port-B (0x14) - front mic-in
3551 * port-E (0x1c) - rear mic-in
3552 * port-F (0x16) - CD / ext out
3553 * port-C (0x15) - rear line-in
3554 * port-D (0x12) - rear line-out
3555 * port-A (0x11) - front hp-out
3556 *
3557 * AD1984A = AD1884A + digital-mic
3558 * AD1883 = equivalent with AD1984A
3559 * AD1984B = AD1984A + extra SPDIF-out
3560 *
3561 * FIXME:
3562 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3563 */
3564
3565static hda_nid_t ad1884a_dac_nids[1] = {
3566 0x03,
3567};
3568
3569#define ad1884a_adc_nids ad1884_adc_nids
3570#define ad1884a_capsrc_nids ad1884_capsrc_nids
3571
3572#define AD1884A_SPDIF_OUT 0x02
3573
3574static struct hda_input_mux ad1884a_capture_source = {
3575 .num_items = 5,
3576 .items = {
3577 { "Front Mic", 0x0 },
3578 { "Mic", 0x4 },
3579 { "Line", 0x1 },
3580 { "CD", 0x2 },
3581 { "Mix", 0x3 },
3582 },
3583};
3584
3585static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3586 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3587 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3588 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3589 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3590 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3591 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3592 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3593 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3594 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3595 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3596 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3597 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3598 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3599 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3600 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3601 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003602 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3603 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3604 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3605 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3606 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3607 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3608 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3609 {
3610 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3611 /* The multiple "Capture Source" controls confuse alsamixer
3612 * So call somewhat different..
3613 */
3614 /* .name = "Capture Source", */
3615 .name = "Input Source",
3616 .count = 2,
3617 .info = ad198x_mux_enum_info,
3618 .get = ad198x_mux_enum_get,
3619 .put = ad198x_mux_enum_put,
3620 },
3621 /* SPDIF controls */
3622 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3623 {
3624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3625 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3626 /* identical with ad1983 */
3627 .info = ad1983_spdif_route_info,
3628 .get = ad1983_spdif_route_get,
3629 .put = ad1983_spdif_route_put,
3630 },
3631 { } /* end */
3632};
3633
3634/*
3635 * initialization verbs
3636 */
3637static struct hda_verb ad1884a_init_verbs[] = {
3638 /* DACs; unmute as default */
3639 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3640 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3641 /* Port-A (HP) mixer - route only from analog mixer */
3642 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3643 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3644 /* Port-A pin */
3645 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3646 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3647 /* Port-D (Line-out) mixer - route only from analog mixer */
3648 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3649 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3650 /* Port-D pin */
3651 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3652 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3653 /* Mono-out mixer - route only from analog mixer */
3654 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3655 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3656 /* Mono-out pin */
3657 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3658 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3659 /* Port-B (front mic) pin */
3660 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003661 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003662 /* Port-C (rear line-in) pin */
3663 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003664 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003665 /* Port-E (rear mic) pin */
3666 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3667 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3668 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3669 /* Port-F (CD) pin */
3670 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3671 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3672 /* Analog mixer; mute as default */
3673 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3674 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3675 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3676 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3677 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3678 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3679 /* Analog Mix output amp */
3680 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3681 /* capture sources */
3682 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3683 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3684 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3685 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3686 /* SPDIF output amp */
3687 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3688 { } /* end */
3689};
3690
3691#ifdef CONFIG_SND_HDA_POWER_SAVE
3692static struct hda_amp_list ad1884a_loopbacks[] = {
3693 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3694 { 0x20, HDA_INPUT, 1 }, /* Mic */
3695 { 0x20, HDA_INPUT, 2 }, /* CD */
3696 { 0x20, HDA_INPUT, 4 }, /* Docking */
3697 { } /* end */
3698};
3699#endif
3700
3701/*
3702 * Laptop model
3703 *
3704 * Port A: Headphone jack
3705 * Port B: MIC jack
3706 * Port C: Internal MIC
3707 * Port D: Dock Line Out (if enabled)
3708 * Port E: Dock Line In (if enabled)
3709 * Port F: Internal speakers
3710 */
3711
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003712static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3713 struct snd_ctl_elem_value *ucontrol)
3714{
3715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3716 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3717 int mute = (!ucontrol->value.integer.value[0] &&
3718 !ucontrol->value.integer.value[1]);
3719 /* toggle GPIO1 according to the mute state */
3720 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3721 mute ? 0x02 : 0x0);
3722 return ret;
3723}
Takashi Iwaic5059252008-02-16 09:43:56 +01003724
3725static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3726 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003727 {
3728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3729 .name = "Master Playback Switch",
3730 .info = snd_hda_mixer_amp_switch_info,
3731 .get = snd_hda_mixer_amp_switch_get,
3732 .put = ad1884a_mobile_master_sw_put,
3733 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3734 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003735 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3736 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3737 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3738 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3739 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3740 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3741 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3742 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3743 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003744 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3745 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3746 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3747 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3748 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003749 { } /* end */
3750};
3751
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003752static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3753 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db172009-07-02 16:10:23 +02003754 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3755 {
3756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3757 .name = "Master Playback Switch",
3758 .info = snd_hda_mixer_amp_switch_info,
3759 .get = snd_hda_mixer_amp_switch_get,
3760 .put = ad1884a_mobile_master_sw_put,
3761 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3762 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003763 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3764 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003765 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3766 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003767 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3768 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003769 { } /* end */
3770};
3771
Takashi Iwaic5059252008-02-16 09:43:56 +01003772/* mute internal speaker if HP is plugged */
3773static void ad1884a_hp_automute(struct hda_codec *codec)
3774{
3775 unsigned int present;
3776
Takashi Iwaid56757a2009-11-18 08:00:14 +01003777 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01003778 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3779 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3780 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3781 present ? 0x00 : 0x02);
3782}
3783
Takashi Iwai269ef192008-05-30 15:32:15 +02003784/* switch to external mic if plugged */
3785static void ad1884a_hp_automic(struct hda_codec *codec)
3786{
3787 unsigned int present;
3788
Takashi Iwaid56757a2009-11-18 08:00:14 +01003789 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02003790 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3791 present ? 0 : 1);
3792}
3793
Takashi Iwaic5059252008-02-16 09:43:56 +01003794#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02003795#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01003796
3797/* unsolicited event for HP jack sensing */
3798static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3799{
Takashi Iwai269ef192008-05-30 15:32:15 +02003800 switch (res >> 26) {
3801 case AD1884A_HP_EVENT:
3802 ad1884a_hp_automute(codec);
3803 break;
3804 case AD1884A_MIC_EVENT:
3805 ad1884a_hp_automic(codec);
3806 break;
3807 }
Takashi Iwaic5059252008-02-16 09:43:56 +01003808}
3809
3810/* initialize jack-sensing, too */
3811static int ad1884a_hp_init(struct hda_codec *codec)
3812{
3813 ad198x_init(codec);
3814 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02003815 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01003816 return 0;
3817}
3818
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003819/* mute internal speaker if HP or docking HP is plugged */
3820static void ad1884a_laptop_automute(struct hda_codec *codec)
3821{
3822 unsigned int present;
3823
Takashi Iwaid56757a2009-11-18 08:00:14 +01003824 present = snd_hda_jack_detect(codec, 0x11);
3825 if (!present)
3826 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003827 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3828 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3829 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3830 present ? 0x00 : 0x02);
3831}
3832
3833/* switch to external mic if plugged */
3834static void ad1884a_laptop_automic(struct hda_codec *codec)
3835{
3836 unsigned int idx;
3837
Takashi Iwaid56757a2009-11-18 08:00:14 +01003838 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003839 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01003840 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003841 idx = 4;
3842 else
3843 idx = 1;
3844 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3845}
3846
3847/* unsolicited event for HP jack sensing */
3848static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3849 unsigned int res)
3850{
3851 switch (res >> 26) {
3852 case AD1884A_HP_EVENT:
3853 ad1884a_laptop_automute(codec);
3854 break;
3855 case AD1884A_MIC_EVENT:
3856 ad1884a_laptop_automic(codec);
3857 break;
3858 }
3859}
3860
3861/* initialize jack-sensing, too */
3862static int ad1884a_laptop_init(struct hda_codec *codec)
3863{
3864 ad198x_init(codec);
3865 ad1884a_laptop_automute(codec);
3866 ad1884a_laptop_automic(codec);
3867 return 0;
3868}
3869
Takashi Iwaic5059252008-02-16 09:43:56 +01003870/* additional verbs for laptop model */
3871static struct hda_verb ad1884a_laptop_verbs[] = {
3872 /* Port-A (HP) pin - always unmuted */
3873 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3874 /* Port-F (int speaker) mixer - route only from analog mixer */
3875 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3876 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08003877 /* Port-F (int speaker) pin */
3878 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01003879 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08003880 /* required for compaq 6530s/6531s speaker output */
3881 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003882 /* Port-C pin - internal mic-in */
3883 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3884 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3885 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02003886 /* Port-D (docking line-out) pin - default unmuted */
3887 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01003888 /* analog mix */
3889 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3890 /* unsolicited event for pin-sense */
3891 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003892 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02003893 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003894 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02003895 /* allow to touch GPIO1 (for mute control) */
3896 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3897 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3898 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01003899 { } /* end */
3900};
3901
Takashi Iwai73156132009-04-23 08:24:48 +02003902static struct hda_verb ad1884a_mobile_verbs[] = {
3903 /* DACs; unmute as default */
3904 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3905 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3906 /* Port-A (HP) mixer - route only from analog mixer */
3907 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3908 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3909 /* Port-A pin */
3910 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3911 /* Port-A (HP) pin - always unmuted */
3912 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3913 /* Port-B (mic jack) pin */
3914 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3915 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3916 /* Port-C (int mic) pin */
3917 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3918 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3919 /* Port-F (int speaker) mixer - route only from analog mixer */
3920 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3921 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3922 /* Port-F pin */
3923 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3924 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3925 /* Analog mixer; mute as default */
3926 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3927 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3928 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3929 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3930 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3931 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3932 /* Analog Mix output amp */
3933 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3934 /* capture sources */
3935 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3936 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3937 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3938 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3939 /* unsolicited event for pin-sense */
3940 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3941 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db172009-07-02 16:10:23 +02003942 /* allow to touch GPIO1 (for mute control) */
3943 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
3944 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
3945 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02003946 { } /* end */
3947};
3948
Takashi Iwaic5059252008-02-16 09:43:56 +01003949/*
Takashi Iwaif0813742008-03-18 12:13:03 +01003950 * Thinkpad X300
3951 * 0x11 - HP
3952 * 0x12 - speaker
3953 * 0x14 - mic-in
3954 * 0x17 - built-in mic
3955 */
3956
3957static struct hda_verb ad1984a_thinkpad_verbs[] = {
3958 /* HP unmute */
3959 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3960 /* analog mix */
3961 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3962 /* turn on EAPD */
3963 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3964 /* unsolicited event for pin-sense */
3965 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3966 /* internal mic - dmic */
3967 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02003968 /* set magic COEFs for dmic */
3969 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3970 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01003971 { } /* end */
3972};
3973
3974static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3975 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3976 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3977 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3978 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3979 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3980 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01003981 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3982 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3983 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3984 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3985 {
3986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3987 .name = "Capture Source",
3988 .info = ad198x_mux_enum_info,
3989 .get = ad198x_mux_enum_get,
3990 .put = ad198x_mux_enum_put,
3991 },
3992 { } /* end */
3993};
3994
3995static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3996 .num_items = 3,
3997 .items = {
3998 { "Mic", 0x0 },
3999 { "Internal Mic", 0x5 },
4000 { "Mix", 0x3 },
4001 },
4002};
4003
4004/* mute internal speaker if HP is plugged */
4005static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4006{
4007 unsigned int present;
4008
Takashi Iwaid56757a2009-11-18 08:00:14 +01004009 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004010 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4011 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4012}
4013
4014/* unsolicited event for HP jack sensing */
4015static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4016 unsigned int res)
4017{
4018 if ((res >> 26) != AD1884A_HP_EVENT)
4019 return;
4020 ad1984a_thinkpad_automute(codec);
4021}
4022
4023/* initialize jack-sensing, too */
4024static int ad1984a_thinkpad_init(struct hda_codec *codec)
4025{
4026 ad198x_init(codec);
4027 ad1984a_thinkpad_automute(codec);
4028 return 0;
4029}
4030
4031/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004032 * HP Touchsmart
4033 * port-A (0x11) - front hp-out
4034 * port-B (0x14) - unused
4035 * port-C (0x15) - unused
4036 * port-D (0x12) - rear line out
4037 * port-E (0x1c) - front mic-in
4038 * port-F (0x16) - Internal speakers
4039 * digital-mic (0x17) - Internal mic
4040 */
4041
4042static struct hda_verb ad1984a_touchsmart_verbs[] = {
4043 /* DACs; unmute as default */
4044 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4045 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4046 /* Port-A (HP) mixer - route only from analog mixer */
4047 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4048 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4049 /* Port-A pin */
4050 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4051 /* Port-A (HP) pin - always unmuted */
4052 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4053 /* Port-E (int speaker) mixer - route only from analog mixer */
4054 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4055 /* Port-E pin */
4056 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4057 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4058 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4059 /* Port-F (int speaker) mixer - route only from analog mixer */
4060 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4061 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4062 /* Port-F pin */
4063 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4064 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4065 /* Analog mixer; mute as default */
4066 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4067 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4068 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4069 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4070 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4071 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4072 /* Analog Mix output amp */
4073 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4074 /* capture sources */
4075 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4076 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4077 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4078 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4079 /* unsolicited event for pin-sense */
4080 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4081 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4082 /* allow to touch GPIO1 (for mute control) */
4083 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4084 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4085 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4086 /* internal mic - dmic */
4087 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4088 /* set magic COEFs for dmic */
4089 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4090 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4091 { } /* end */
4092};
4093
4094static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4095 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4096/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4097 {
4098 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4099 .name = "Master Playback Switch",
4100 .info = snd_hda_mixer_amp_switch_info,
4101 .get = snd_hda_mixer_amp_switch_get,
4102 .put = ad1884a_mobile_master_sw_put,
4103 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4104 },
4105 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4106 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4107 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4108 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4109 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4110 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4111 { } /* end */
4112};
4113
4114/* switch to external mic if plugged */
4115static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4116{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004117 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004118 snd_hda_codec_write(codec, 0x0c, 0,
4119 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004120 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004121 snd_hda_codec_write(codec, 0x0c, 0,
4122 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004123}
4124
4125
4126/* unsolicited event for HP jack sensing */
4127static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4128 unsigned int res)
4129{
4130 switch (res >> 26) {
4131 case AD1884A_HP_EVENT:
4132 ad1884a_hp_automute(codec);
4133 break;
4134 case AD1884A_MIC_EVENT:
4135 ad1984a_touchsmart_automic(codec);
4136 break;
4137 }
4138}
4139
4140/* initialize jack-sensing, too */
4141static int ad1984a_touchsmart_init(struct hda_codec *codec)
4142{
4143 ad198x_init(codec);
4144 ad1884a_hp_automute(codec);
4145 ad1984a_touchsmart_automic(codec);
4146 return 0;
4147}
4148
4149
4150/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004151 */
4152
4153enum {
4154 AD1884A_DESKTOP,
4155 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004156 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004157 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004158 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004159 AD1884A_MODELS
4160};
4161
4162static const char *ad1884a_models[AD1884A_MODELS] = {
4163 [AD1884A_DESKTOP] = "desktop",
4164 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004165 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004166 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004167 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004168};
4169
4170static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4171 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004172 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004173 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004174 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004175 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004176 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4177 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004178 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004179 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004180 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004181 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004182};
4183
4184static int patch_ad1884a(struct hda_codec *codec)
4185{
4186 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004187 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004188
4189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4190 if (spec == NULL)
4191 return -ENOMEM;
4192
Takashi Iwaic5059252008-02-16 09:43:56 +01004193 codec->spec = spec;
4194
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004195 err = snd_hda_attach_beep_device(codec, 0x10);
4196 if (err < 0) {
4197 ad198x_free(codec);
4198 return err;
4199 }
4200 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4201
Takashi Iwaic5059252008-02-16 09:43:56 +01004202 spec->multiout.max_channels = 2;
4203 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4204 spec->multiout.dac_nids = ad1884a_dac_nids;
4205 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4206 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4207 spec->adc_nids = ad1884a_adc_nids;
4208 spec->capsrc_nids = ad1884a_capsrc_nids;
4209 spec->input_mux = &ad1884a_capture_source;
4210 spec->num_mixers = 1;
4211 spec->mixers[0] = ad1884a_base_mixers;
4212 spec->num_init_verbs = 1;
4213 spec->init_verbs[0] = ad1884a_init_verbs;
4214 spec->spdif_route = 0;
4215#ifdef CONFIG_SND_HDA_POWER_SAVE
4216 spec->loopback.amplist = ad1884a_loopbacks;
4217#endif
4218 codec->patch_ops = ad198x_patch_ops;
4219
4220 /* override some parameters */
4221 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004222 ad1884a_models,
4223 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004224 switch (board_config) {
4225 case AD1884A_LAPTOP:
4226 spec->mixers[0] = ad1884a_laptop_mixers;
4227 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4228 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004229 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4230 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004231 /* set the upper-limit for mixer amp to 0dB for avoiding the
4232 * possible damage by overloading
4233 */
4234 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4235 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4236 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4237 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4238 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004239 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004240 case AD1884A_MOBILE:
4241 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004242 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004243 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004244 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4245 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004246 /* 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 Iwaib40b04a2008-02-16 09:44:56 +01004254 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004255 case AD1884A_THINKPAD:
4256 spec->mixers[0] = ad1984a_thinkpad_mixers;
4257 spec->init_verbs[spec->num_init_verbs++] =
4258 ad1984a_thinkpad_verbs;
4259 spec->multiout.dig_out_nid = 0;
4260 spec->input_mux = &ad1984a_thinkpad_capture_source;
4261 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4262 codec->patch_ops.init = ad1984a_thinkpad_init;
4263 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004264 case AD1984A_TOUCHSMART:
4265 spec->mixers[0] = ad1984a_touchsmart_mixers;
4266 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4267 spec->multiout.dig_out_nid = 0;
4268 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4269 codec->patch_ops.init = ad1984a_touchsmart_init;
4270 /* set the upper-limit for mixer amp to 0dB for avoiding the
4271 * possible damage by overloading
4272 */
4273 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4274 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4275 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4276 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4277 (1 << AC_AMPCAP_MUTE_SHIFT));
4278 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004279 }
4280
4281 return 0;
4282}
4283
4284
4285/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004286 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004287 *
4288 * port-A - front hp-out
4289 * port-B - front mic-in
4290 * port-C - rear line-in, shared surr-out (3stack)
4291 * port-D - rear line-out
4292 * port-E - rear mic-in, shared clfe-out (3stack)
4293 * port-F - rear surr-out (6stack)
4294 * port-G - rear clfe-out (6stack)
4295 */
4296
4297static hda_nid_t ad1882_dac_nids[3] = {
4298 0x04, 0x03, 0x05
4299};
4300
4301static hda_nid_t ad1882_adc_nids[2] = {
4302 0x08, 0x09,
4303};
4304
4305static hda_nid_t ad1882_capsrc_nids[2] = {
4306 0x0c, 0x0d,
4307};
4308
4309#define AD1882_SPDIF_OUT 0x02
4310
4311/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4312static struct hda_input_mux ad1882_capture_source = {
4313 .num_items = 5,
4314 .items = {
4315 { "Front Mic", 0x1 },
4316 { "Mic", 0x4 },
4317 { "Line", 0x2 },
4318 { "CD", 0x3 },
4319 { "Mix", 0x7 },
4320 },
4321};
4322
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004323/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4324static struct hda_input_mux ad1882a_capture_source = {
4325 .num_items = 5,
4326 .items = {
4327 { "Front Mic", 0x1 },
4328 { "Mic", 0x4},
4329 { "Line", 0x2 },
4330 { "Digital Mic", 0x06 },
4331 { "Mix", 0x7 },
4332 },
4333};
4334
Takashi Iwai0ac85512007-06-20 15:46:13 +02004335static struct snd_kcontrol_new ad1882_base_mixers[] = {
4336 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4337 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4338 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4339 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4340 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4341 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4342 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4343 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004344
Takashi Iwai0ac85512007-06-20 15:46:13 +02004345 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4346 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4347 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4348 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4349 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4350 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4351 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4352 {
4353 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4354 /* The multiple "Capture Source" controls confuse alsamixer
4355 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004356 */
4357 /* .name = "Capture Source", */
4358 .name = "Input Source",
4359 .count = 2,
4360 .info = ad198x_mux_enum_info,
4361 .get = ad198x_mux_enum_get,
4362 .put = ad198x_mux_enum_put,
4363 },
4364 /* SPDIF controls */
4365 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4366 {
4367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4368 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4369 /* identical with ad1983 */
4370 .info = ad1983_spdif_route_info,
4371 .get = ad1983_spdif_route_get,
4372 .put = ad1983_spdif_route_put,
4373 },
4374 { } /* end */
4375};
4376
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004377static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4378 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4379 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4380 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4381 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4382 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4383 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4384 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4385 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004386 { } /* end */
4387};
4388
4389static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4390 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4391 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4392 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4393 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4394 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4395 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4396 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4397 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004398 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4399 { } /* end */
4400};
4401
Takashi Iwai0ac85512007-06-20 15:46:13 +02004402static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4403 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4404 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4405 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4406 {
4407 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4408 .name = "Channel Mode",
4409 .info = ad198x_ch_mode_info,
4410 .get = ad198x_ch_mode_get,
4411 .put = ad198x_ch_mode_put,
4412 },
4413 { } /* end */
4414};
4415
4416static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4417 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4418 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4419 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4420 { } /* end */
4421};
4422
4423static struct hda_verb ad1882_ch2_init[] = {
4424 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4425 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4426 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4427 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4428 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4429 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4430 { } /* end */
4431};
4432
4433static struct hda_verb ad1882_ch4_init[] = {
4434 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4435 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4436 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4437 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4438 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4439 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4440 { } /* end */
4441};
4442
4443static struct hda_verb ad1882_ch6_init[] = {
4444 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4445 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4446 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4447 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4448 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4449 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4450 { } /* end */
4451};
4452
4453static struct hda_channel_mode ad1882_modes[3] = {
4454 { 2, ad1882_ch2_init },
4455 { 4, ad1882_ch4_init },
4456 { 6, ad1882_ch6_init },
4457};
4458
4459/*
4460 * initialization verbs
4461 */
4462static struct hda_verb ad1882_init_verbs[] = {
4463 /* DACs; mute as default */
4464 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4465 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4466 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4467 /* Port-A (HP) mixer */
4468 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4469 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4470 /* Port-A pin */
4471 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4472 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4473 /* HP selector - select DAC2 */
4474 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4475 /* Port-D (Line-out) mixer */
4476 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4477 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4478 /* Port-D pin */
4479 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4480 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4481 /* Mono-out mixer */
4482 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4483 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4484 /* Mono-out pin */
4485 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4486 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4487 /* Port-B (front mic) pin */
4488 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4489 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4490 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4491 /* Port-C (line-in) pin */
4492 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4493 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4494 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4495 /* Port-C mixer - mute as input */
4496 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4497 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4498 /* Port-E (mic-in) pin */
4499 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4500 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4501 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4502 /* Port-E mixer - mute as input */
4503 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4504 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4505 /* Port-F (surround) */
4506 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4507 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4508 /* Port-G (CLFE) */
4509 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4510 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4511 /* Analog mixer; mute as default */
4512 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4513 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4514 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4515 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4516 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4517 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4518 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4519 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4520 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4521 /* Analog Mix output amp */
4522 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4523 /* SPDIF output selector */
4524 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4525 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4526 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4527 { } /* end */
4528};
4529
Takashi Iwaicb53c622007-08-10 17:21:45 +02004530#ifdef CONFIG_SND_HDA_POWER_SAVE
4531static struct hda_amp_list ad1882_loopbacks[] = {
4532 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4533 { 0x20, HDA_INPUT, 1 }, /* Mic */
4534 { 0x20, HDA_INPUT, 4 }, /* Line */
4535 { 0x20, HDA_INPUT, 6 }, /* CD */
4536 { } /* end */
4537};
4538#endif
4539
Takashi Iwai0ac85512007-06-20 15:46:13 +02004540/* models */
4541enum {
4542 AD1882_3STACK,
4543 AD1882_6STACK,
4544 AD1882_MODELS
4545};
4546
4547static const char *ad1882_models[AD1986A_MODELS] = {
4548 [AD1882_3STACK] = "3stack",
4549 [AD1882_6STACK] = "6stack",
4550};
4551
4552
4553static int patch_ad1882(struct hda_codec *codec)
4554{
4555 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004556 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004557
4558 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4559 if (spec == NULL)
4560 return -ENOMEM;
4561
Takashi Iwai0ac85512007-06-20 15:46:13 +02004562 codec->spec = spec;
4563
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004564 err = snd_hda_attach_beep_device(codec, 0x10);
4565 if (err < 0) {
4566 ad198x_free(codec);
4567 return err;
4568 }
4569 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4570
Takashi Iwai0ac85512007-06-20 15:46:13 +02004571 spec->multiout.max_channels = 6;
4572 spec->multiout.num_dacs = 3;
4573 spec->multiout.dac_nids = ad1882_dac_nids;
4574 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4575 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4576 spec->adc_nids = ad1882_adc_nids;
4577 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004578 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004579 spec->input_mux = &ad1882_capture_source;
4580 else
4581 spec->input_mux = &ad1882a_capture_source;
4582 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004583 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004584 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004585 spec->mixers[1] = ad1882_loopback_mixers;
4586 else
4587 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004588 spec->num_init_verbs = 1;
4589 spec->init_verbs[0] = ad1882_init_verbs;
4590 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004591#ifdef CONFIG_SND_HDA_POWER_SAVE
4592 spec->loopback.amplist = ad1882_loopbacks;
4593#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004594 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004595
4596 codec->patch_ops = ad198x_patch_ops;
4597
4598 /* override some parameters */
4599 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4600 ad1882_models, NULL);
4601 switch (board_config) {
4602 default:
4603 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004604 spec->num_mixers = 3;
4605 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004606 spec->channel_mode = ad1882_modes;
4607 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4608 spec->need_dac_fix = 1;
4609 spec->multiout.max_channels = 2;
4610 spec->multiout.num_dacs = 1;
4611 break;
4612 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004613 spec->num_mixers = 3;
4614 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004615 break;
4616 }
4617 return 0;
4618}
4619
4620
4621/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622 * patch entries
4623 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004624static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004625 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004626 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004627 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004628 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004629 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4630 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004631 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4632 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004633 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004635 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004636 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004637 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004638 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4639 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 {} /* terminator */
4641};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004642
4643MODULE_ALIAS("snd-hda-codec-id:11d4*");
4644
4645MODULE_LICENSE("GPL");
4646MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4647
4648static struct hda_codec_preset_list analog_list = {
4649 .preset = snd_hda_preset_analog,
4650 .owner = THIS_MODULE,
4651};
4652
4653static int __init patch_analog_init(void)
4654{
4655 return snd_hda_add_codec_preset(&analog_list);
4656}
4657
4658static void __exit patch_analog_exit(void)
4659{
4660 snd_hda_delete_codec_preset(&analog_list);
4661}
4662
4663module_init(patch_analog_init)
4664module_exit(patch_analog_exit)