blob: 056810c14e719def9d82e1446778d6561815e32d [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/slab.h>
24#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040025#include <linux/module.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 Iwai128bc4b2012-05-07 17:42:31 +020030#include "hda_auto_parser.h"
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010031#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020032#include "hda_jack.h"
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010033#include "hda_generic.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Takashi Iwai9ff4bc82013-01-22 16:45:58 +010035#define ENABLE_AD_STATIC_QUIRKS
36
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020037struct ad198x_spec {
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010038 struct hda_gen_spec gen;
39
Takashi Iwai272f3ea2013-01-22 15:31:33 +010040 /* for auto parser */
41 int smux_paths[4];
42 unsigned int cur_smux;
Takashi Iwaia928bd22013-01-22 18:18:42 +010043 hda_nid_t eapd_nid;
Takashi Iwai272f3ea2013-01-22 15:31:33 +010044
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010045 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Takashi Iwai9ff4bc82013-01-22 16:45:58 +010046
47#ifdef ENABLE_AD_STATIC_QUIRKS
48 const struct snd_kcontrol_new *mixers[6];
49 int num_mixers;
Raymond Yau28220842011-02-08 19:58:25 +080050 const struct hda_verb *init_verbs[6]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010051 * don't forget NULL termination!
52 */
53 unsigned int num_init_verbs;
54
55 /* playback */
56 struct hda_multi_out multiout; /* playback set-up
57 * max_channels, dacs must be set
58 * dig_out_nid and hp_nid are optional
59 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010060 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020061 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010062
63 /* capture */
64 unsigned int num_adc_nids;
Takashi Iwai498f5b12011-05-02 11:33:15 +020065 const hda_nid_t *adc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010066 hda_nid_t dig_in_nid; /* digital-in NID; optional */
67
68 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020069 const struct hda_input_mux *input_mux;
Takashi Iwai498f5b12011-05-02 11:33:15 +020070 const hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010071 unsigned int cur_mux[3];
72
73 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010074 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010075 int num_channel_mode;
76
77 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020078 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010079
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020080 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010081
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +010082 unsigned int jack_present: 1;
83 unsigned int inv_jack_detect: 1;/* inverted jack-detection */
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +010084 unsigned int analog_beep: 1; /* analog beep input present */
Takashi Iwai18478e82012-03-09 17:51:10 +010085 unsigned int avoid_init_slave_vol:1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +020086
Takashi Iwai83012a72012-08-24 18:38:08 +020087#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +020088 struct hda_loopback_check loopback;
89#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010090 /* for virtual master */
91 hda_nid_t vmaster_nid;
Takashi Iwaiea734962011-01-17 11:29:34 +010092 const char * const *slave_vols;
93 const char * const *slave_sws;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +010094#endif /* ENABLE_AD_STATIC_QUIRKS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095};
96
Takashi Iwai9ff4bc82013-01-22 16:45:58 +010097#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020098/*
99 * input MUX handling (common part)
100 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100101static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200102{
103 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
104 struct ad198x_spec *spec = codec->spec;
105
106 return snd_hda_input_mux_info(spec->input_mux, uinfo);
107}
108
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100109static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200110{
111 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
112 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100113 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200114
Takashi Iwai985be542005-11-02 18:26:49 +0100115 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200116 return 0;
117}
118
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100119static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200120{
121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
122 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100123 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200124
125 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100126 spec->capsrc_nids[adc_idx],
127 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200128}
129
130/*
131 * initialization (common callbacks)
132 */
133static int ad198x_init(struct hda_codec *codec)
134{
135 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100136 int i;
137
138 for (i = 0; i < spec->num_init_verbs; i++)
139 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200140 return 0;
141}
142
Takashi Iwai9322ca52012-02-03 14:28:01 +0100143static const char * const ad_slave_pfxs[] = {
144 "Front", "Surround", "Center", "LFE", "Side",
145 "Headphone", "Mono", "Speaker", "IEC958",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100146 NULL
147};
148
Takashi Iwai9322ca52012-02-03 14:28:01 +0100149static const char * const ad1988_6stack_fp_slave_pfxs[] = {
150 "Front", "Surround", "Center", "LFE", "Side", "IEC958",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100151 NULL
152};
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100153#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwai2134ea42008-01-10 16:53:55 +0100154
Takashi Iwai67d634c2009-11-16 15:35:59 +0100155#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100156/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200157static const struct snd_kcontrol_new ad_beep_mixer[] = {
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100158 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +0200159 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100160 { } /* end */
161};
162
Takashi Iwai498f5b12011-05-02 11:33:15 +0200163static const struct snd_kcontrol_new ad_beep2_mixer[] = {
Jaroslav Kysela0bf0e5a2010-03-26 10:33:18 +0100164 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
165 HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
166 { } /* end */
167};
168
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100169#define set_beep_amp(spec, nid, idx, dir) \
170 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100171#else
172#define set_beep_amp(spec, nid, idx, dir) /* NOP */
173#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100174
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100175#ifdef CONFIG_SND_HDA_INPUT_BEEP
176static int create_beep_ctls(struct hda_codec *codec)
177{
178 struct ad198x_spec *spec = codec->spec;
179 const struct snd_kcontrol_new *knew;
180
181 if (!spec->beep_amp)
182 return 0;
183
184 knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
185 for ( ; knew->name; knew++) {
186 int err;
187 struct snd_kcontrol *kctl;
188 kctl = snd_ctl_new1(knew, codec);
189 if (!kctl)
190 return -ENOMEM;
191 kctl->private_value = spec->beep_amp;
192 err = snd_hda_ctl_add(codec, 0, kctl);
193 if (err < 0)
194 return err;
195 }
196 return 0;
197}
198#else
199#define create_beep_ctls(codec) 0
200#endif
201
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100202#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200203static int ad198x_build_controls(struct hda_codec *codec)
204{
205 struct ad198x_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100206 struct snd_kcontrol *kctl;
Takashi Iwai985be542005-11-02 18:26:49 +0100207 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200208 int err;
209
Takashi Iwai985be542005-11-02 18:26:49 +0100210 for (i = 0; i < spec->num_mixers; i++) {
211 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
212 if (err < 0)
213 return err;
214 }
215 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -0600216 err = snd_hda_create_spdif_out_ctls(codec,
217 spec->multiout.dig_out_nid,
218 spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100219 if (err < 0)
220 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100221 err = snd_hda_create_spdif_share_sw(codec,
222 &spec->multiout);
223 if (err < 0)
224 return err;
225 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100226 }
227 if (spec->dig_in_nid) {
228 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
229 if (err < 0)
230 return err;
231 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100232
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100233 /* create beep controls if needed */
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100234 err = create_beep_ctls(codec);
235 if (err < 0)
236 return err;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100237
Takashi Iwai2134ea42008-01-10 16:53:55 +0100238 /* if we have no master control, let's create it */
239 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100240 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100241 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100242 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai18478e82012-03-09 17:51:10 +0100243 err = __snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100244 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100245 (spec->slave_vols ?
Takashi Iwai9322ca52012-02-03 14:28:01 +0100246 spec->slave_vols : ad_slave_pfxs),
Takashi Iwai18478e82012-03-09 17:51:10 +0100247 "Playback Volume",
Takashi Iwai29e58532012-03-12 12:25:03 +0100248 !spec->avoid_init_slave_vol, NULL);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100249 if (err < 0)
250 return err;
251 }
252 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
253 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
254 NULL,
255 (spec->slave_sws ?
Takashi Iwai9322ca52012-02-03 14:28:01 +0100256 spec->slave_sws : ad_slave_pfxs),
257 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +0100258 if (err < 0)
259 return err;
260 }
261
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100262 /* assign Capture Source enums to NID */
263 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
264 if (!kctl)
265 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
266 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +0100267 err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100268 if (err < 0)
269 return err;
270 }
271
272 /* assign IEC958 enums to NID */
273 kctl = snd_hda_find_mixer_ctl(codec,
274 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
275 if (kctl) {
276 err = snd_hda_add_nid(codec, kctl, 0,
277 spec->multiout.dig_out_nid);
278 if (err < 0)
279 return err;
280 }
281
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200282 return 0;
283}
284
Takashi Iwai83012a72012-08-24 18:38:08 +0200285#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200286static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
287{
288 struct ad198x_spec *spec = codec->spec;
289 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
290}
291#endif
292
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200293/*
294 * Analog playback callbacks
295 */
296static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
297 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100298 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200299{
300 struct ad198x_spec *spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100301 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
Takashi Iwai9a081602008-02-12 18:37:26 +0100302 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200303}
304
305static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
306 struct hda_codec *codec,
307 unsigned int stream_tag,
308 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100309 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200310{
311 struct ad198x_spec *spec = codec->spec;
312 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
313 format, substream);
314}
315
316static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
317 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100318 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200319{
320 struct ad198x_spec *spec = codec->spec;
321 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
322}
323
324/*
325 * Digital out
326 */
327static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
328 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100329 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200330{
331 struct ad198x_spec *spec = codec->spec;
332 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
333}
334
335static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
336 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100337 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200338{
339 struct ad198x_spec *spec = codec->spec;
340 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
341}
342
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200343static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
344 struct hda_codec *codec,
345 unsigned int stream_tag,
346 unsigned int format,
347 struct snd_pcm_substream *substream)
348{
349 struct ad198x_spec *spec = codec->spec;
350 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
351 format, substream);
352}
353
Takashi Iwai9411e212009-02-13 11:32:28 +0100354static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
355 struct hda_codec *codec,
356 struct snd_pcm_substream *substream)
357{
358 struct ad198x_spec *spec = codec->spec;
359 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
360}
361
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200362/*
363 * Analog capture
364 */
365static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
366 struct hda_codec *codec,
367 unsigned int stream_tag,
368 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100369 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200370{
371 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100372 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
373 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200374 return 0;
375}
376
377static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
378 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100379 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200380{
381 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100382 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200383 return 0;
384}
385
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200386/*
387 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200388static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200389 .substreams = 1,
390 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100391 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200392 .nid = 0, /* fill later */
393 .ops = {
394 .open = ad198x_playback_pcm_open,
395 .prepare = ad198x_playback_pcm_prepare,
Raymond Yau34588702011-09-23 19:03:25 +0800396 .cleanup = ad198x_playback_pcm_cleanup,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200397 },
398};
399
Takashi Iwai498f5b12011-05-02 11:33:15 +0200400static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100401 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200402 .channels_min = 2,
403 .channels_max = 2,
404 .nid = 0, /* fill later */
405 .ops = {
406 .prepare = ad198x_capture_pcm_prepare,
407 .cleanup = ad198x_capture_pcm_cleanup
408 },
409};
410
Takashi Iwai498f5b12011-05-02 11:33:15 +0200411static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200412 .substreams = 1,
413 .channels_min = 2,
414 .channels_max = 2,
415 .nid = 0, /* fill later */
416 .ops = {
417 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200418 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100419 .prepare = ad198x_dig_playback_pcm_prepare,
420 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200421 },
422};
423
Takashi Iwai498f5b12011-05-02 11:33:15 +0200424static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100425 .substreams = 1,
426 .channels_min = 2,
427 .channels_max = 2,
428 /* NID is set in alc_build_pcms */
429};
430
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200431static int ad198x_build_pcms(struct hda_codec *codec)
432{
433 struct ad198x_spec *spec = codec->spec;
434 struct hda_pcm *info = spec->pcm_rec;
435
436 codec->num_pcms = 1;
437 codec->pcm_info = info;
438
439 info->name = "AD198x Analog";
440 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
441 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
442 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
443 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100444 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
445 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200446
447 if (spec->multiout.dig_out_nid) {
448 info++;
449 codec->num_pcms++;
Takashi Iwaiae24c312012-11-05 12:32:46 +0100450 codec->spdif_status_reset = 1;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200451 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100452 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200453 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
454 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100455 if (spec->dig_in_nid) {
456 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
457 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
458 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200459 }
460
461 return 0;
462}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100463#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200464
Daniel T Chenea52bf22009-12-27 18:48:29 -0500465static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
466 hda_nid_t hp)
467{
Raymond Yaua01ef052011-06-01 15:09:48 +0800468 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
469 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100470 !codec->inv_eapd ? 0x00 : 0x02);
Raymond Yaua01ef052011-06-01 15:09:48 +0800471 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
472 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100473 !codec->inv_eapd ? 0x00 : 0x02);
Daniel T Chenea52bf22009-12-27 18:48:29 -0500474}
475
476static void ad198x_power_eapd(struct hda_codec *codec)
477{
478 /* We currently only handle front, HP */
479 switch (codec->vendor_id) {
480 case 0x11d41882:
481 case 0x11d4882a:
482 case 0x11d41884:
483 case 0x11d41984:
484 case 0x11d41883:
485 case 0x11d4184a:
486 case 0x11d4194a:
487 case 0x11d4194b:
Takashi Iwai4dffbe02011-06-03 10:05:02 +0200488 case 0x11d41988:
489 case 0x11d4198b:
490 case 0x11d4989a:
491 case 0x11d4989b:
Daniel T Chenea52bf22009-12-27 18:48:29 -0500492 ad198x_power_eapd_write(codec, 0x12, 0x11);
493 break;
494 case 0x11d41981:
495 case 0x11d41983:
496 ad198x_power_eapd_write(codec, 0x05, 0x06);
497 break;
498 case 0x11d41986:
499 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
500 break;
Daniel T Chenea52bf22009-12-27 18:48:29 -0500501 }
502}
503
Takashi Iwai0da26922011-04-26 15:18:33 +0200504static void ad198x_shutup(struct hda_codec *codec)
505{
506 snd_hda_shutup_pins(codec);
507 ad198x_power_eapd(codec);
508}
509
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200510static void ad198x_free(struct hda_codec *codec)
511{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100512 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100513
Takashi Iwai603c4012008-07-30 15:01:44 +0200514 if (!spec)
515 return;
516
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100517 snd_hda_gen_spec_free(&spec->gen);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100518 kfree(spec);
519 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200520}
521
Takashi Iwai2a439522011-07-26 09:52:50 +0200522#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200523static int ad198x_suspend(struct hda_codec *codec)
Daniel T Chenea52bf22009-12-27 18:48:29 -0500524{
525 ad198x_shutup(codec);
Daniel T Chenea52bf22009-12-27 18:48:29 -0500526 return 0;
527}
Daniel T Chenea52bf22009-12-27 18:48:29 -0500528#endif
529
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100530#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwai498f5b12011-05-02 11:33:15 +0200531static const struct hda_codec_ops ad198x_patch_ops = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200532 .build_controls = ad198x_build_controls,
533 .build_pcms = ad198x_build_pcms,
534 .init = ad198x_init,
535 .free = ad198x_free,
Takashi Iwai2a439522011-07-26 09:52:50 +0200536#ifdef CONFIG_PM
Takashi Iwai83012a72012-08-24 18:38:08 +0200537 .check_power_status = ad198x_check_power_status,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500538 .suspend = ad198x_suspend,
Daniel T Chenea52bf22009-12-27 18:48:29 -0500539#endif
540 .reboot_notify = ad198x_shutup,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200541};
542
543
544/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100545 * EAPD control
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100546 * the private value = nid
Takashi Iwai18a815d2006-03-01 19:54:39 +0100547 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200548#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100549
550static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
551 struct snd_ctl_elem_value *ucontrol)
552{
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct ad198x_spec *spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100555 if (codec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100556 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
557 else
558 ucontrol->value.integer.value[0] = spec->cur_eapd;
559 return 0;
560}
561
562static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol)
564{
565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
566 struct ad198x_spec *spec = codec->spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100567 hda_nid_t nid = kcontrol->private_value & 0xff;
568 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100569 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100570 if (codec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100571 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200572 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100573 return 0;
574 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200575 snd_hda_codec_write_cache(codec, nid,
576 0, AC_VERB_SET_EAPD_BTLENABLE,
577 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100578 return 1;
579}
580
Takashi Iwai9230d212006-03-13 13:49:49 +0100581static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_info *uinfo);
583static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_value *ucontrol);
585static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
586 struct snd_ctl_elem_value *ucontrol);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100587#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwai9230d212006-03-13 13:49:49 +0100588
589
Takashi Iwai18a815d2006-03-01 19:54:39 +0100590/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100591 * Automatic parse of I/O pins from the BIOS configuration
592 */
593
594static int ad198x_auto_build_controls(struct hda_codec *codec)
595{
596 int err;
597
598 err = snd_hda_gen_build_controls(codec);
599 if (err < 0)
600 return err;
601 err = create_beep_ctls(codec);
602 if (err < 0)
603 return err;
604 return 0;
605}
606
607static const struct hda_codec_ops ad198x_auto_patch_ops = {
608 .build_controls = ad198x_auto_build_controls,
609 .build_pcms = snd_hda_gen_build_pcms,
610 .init = snd_hda_gen_init,
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100611 .free = snd_hda_gen_free,
Takashi Iwai8a6c21a2013-01-18 07:51:17 +0100612 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100613#ifdef CONFIG_PM
614 .check_power_status = snd_hda_gen_check_power_status,
615 .suspend = ad198x_suspend,
616#endif
617 .reboot_notify = ad198x_shutup,
618};
619
620
621static int ad198x_parse_auto_config(struct hda_codec *codec)
622{
623 struct ad198x_spec *spec = codec->spec;
624 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
625 int err;
626
627 codec->spdif_status_reset = 1;
628 codec->no_trigger_sense = 1;
629 codec->no_sticky_stream = 1;
630
631 spec->gen.indep_hp = 1;
632
633 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
634 if (err < 0)
635 return err;
636 err = snd_hda_gen_parse_auto_config(codec, cfg);
637 if (err < 0)
638 return err;
639
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100640 codec->patch_ops = ad198x_auto_patch_ops;
641
642 return 0;
643}
644
645/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200646 * AD1986A specific
647 */
648
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100649#ifdef ENABLE_AD_STATIC_QUIRKS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#define AD1986A_SPDIF_OUT 0x02
651#define AD1986A_FRONT_DAC 0x03
652#define AD1986A_SURR_DAC 0x04
653#define AD1986A_CLFE_DAC 0x05
654#define AD1986A_ADC 0x06
655
Takashi Iwai498f5b12011-05-02 11:33:15 +0200656static const hda_nid_t ad1986a_dac_nids[3] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
658};
Takashi Iwai498f5b12011-05-02 11:33:15 +0200659static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
660static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Takashi Iwai498f5b12011-05-02 11:33:15 +0200662static const struct hda_input_mux ad1986a_capture_source = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .num_items = 7,
664 .items = {
665 { "Mic", 0x0 },
666 { "CD", 0x1 },
667 { "Aux", 0x3 },
668 { "Line", 0x4 },
669 { "Mix", 0x5 },
670 { "Mono", 0x6 },
671 { "Phone", 0x7 },
672 },
673};
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Takashi Iwai498f5b12011-05-02 11:33:15 +0200676static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200677 .ops = &snd_hda_bind_vol,
678 .values = {
679 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
680 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
681 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
682 0
683 },
684};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Takashi Iwai498f5b12011-05-02 11:33:15 +0200686static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200687 .ops = &snd_hda_bind_sw,
688 .values = {
689 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
690 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
691 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
692 0
693 },
694};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 * mixers
698 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200699static const struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200700 /*
701 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
702 */
703 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
704 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
706 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
707 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
708 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
709 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
710 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
711 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
712 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
713 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
714 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
715 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
716 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
717 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
718 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
719 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
720 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
721 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
722 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100723 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
725 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
726 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
727 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
728 {
729 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
730 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200731 .info = ad198x_mux_enum_info,
732 .get = ad198x_mux_enum_get,
733 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 },
735 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
736 { } /* end */
737};
738
Takashi Iwai9230d212006-03-13 13:49:49 +0100739/* additional mixers for 3stack mode */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200740static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +0100741 {
742 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
743 .name = "Channel Mode",
744 .info = ad198x_ch_mode_info,
745 .get = ad198x_ch_mode_get,
746 .put = ad198x_ch_mode_put,
747 },
748 { } /* end */
749};
750
751/* laptop model - 2ch only */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200752static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
Takashi Iwai9230d212006-03-13 13:49:49 +0100753
Takashi Iwai20a45e82007-08-15 22:20:45 +0200754/* master controls both pins 0x1a and 0x1b */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200755static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
Takashi Iwai20a45e82007-08-15 22:20:45 +0200756 .ops = &snd_hda_bind_vol,
757 .values = {
758 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
759 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
760 0,
761 },
762};
763
Takashi Iwai498f5b12011-05-02 11:33:15 +0200764static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
Takashi Iwai20a45e82007-08-15 22:20:45 +0200765 .ops = &snd_hda_bind_sw,
766 .values = {
767 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
768 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
769 0,
770 },
771};
772
Takashi Iwai498f5b12011-05-02 11:33:15 +0200773static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +0100774 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
775 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200776 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
777 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100778 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
779 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
780 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
781 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
782 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
783 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
784 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
785 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100786 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100787 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100788 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
789 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
790 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
791 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
792 {
793 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
794 .name = "Capture Source",
795 .info = ad198x_mux_enum_info,
796 .get = ad198x_mux_enum_get,
797 .put = ad198x_mux_enum_put,
798 },
799 { } /* end */
800};
801
Takashi Iwai825aa972006-03-17 10:50:49 +0100802/* laptop-eapd model - 2ch only */
803
Takashi Iwai498f5b12011-05-02 11:33:15 +0200804static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100805 .num_items = 3,
806 .items = {
807 { "Mic", 0x0 },
808 { "Internal Mic", 0x4 },
809 { "Mix", 0x5 },
810 },
811};
812
Takashi Iwai498f5b12011-05-02 11:33:15 +0200813static const struct hda_input_mux ad1986a_automic_capture_source = {
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100814 .num_items = 2,
815 .items = {
816 { "Mic", 0x0 },
817 { "Mix", 0x5 },
818 },
819};
820
Takashi Iwai498f5b12011-05-02 11:33:15 +0200821static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200822 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
823 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200824 { } /* end */
825};
826
Takashi Iwai498f5b12011-05-02 11:33:15 +0200827static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100828 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
829 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100830 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
831 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
David Henningsson5f99f862011-01-04 15:24:24 +0100832 HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100833 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
834 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
835 {
836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
837 .name = "Capture Source",
838 .info = ad198x_mux_enum_info,
839 .get = ad198x_mux_enum_get,
840 .put = ad198x_mux_enum_put,
841 },
842 {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100845 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwai1725b822008-11-21 02:25:48 +0100846 .info = ad198x_eapd_info,
847 .get = ad198x_eapd_get,
848 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100849 .private_value = 0x1b, /* port-D */
Takashi Iwai1725b822008-11-21 02:25:48 +0100850 },
851 { } /* end */
852};
853
Takashi Iwai498f5b12011-05-02 11:33:15 +0200854static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
Takashi Iwai16d11a82009-06-24 14:07:53 +0200855 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
856 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100857 { } /* end */
858};
859
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100860/* re-connect the mic boost input according to the jack sensing */
861static void ad1986a_automic(struct hda_codec *codec)
862{
863 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100864 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100865 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
866 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100867 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100868}
869
870#define AD1986A_MIC_EVENT 0x36
871
872static void ad1986a_automic_unsol_event(struct hda_codec *codec,
873 unsigned int res)
874{
875 if ((res >> 26) != AD1986A_MIC_EVENT)
876 return;
877 ad1986a_automic(codec);
878}
879
880static int ad1986a_automic_init(struct hda_codec *codec)
881{
882 ad198x_init(codec);
883 ad1986a_automic(codec);
884 return 0;
885}
886
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200887/* laptop-automute - 2ch only */
888
889static void ad1986a_update_hp(struct hda_codec *codec)
890{
891 struct ad198x_spec *spec = codec->spec;
892 unsigned int mute;
893
894 if (spec->jack_present)
895 mute = HDA_AMP_MUTE; /* mute internal speaker */
896 else
897 /* unmute internal speaker if necessary */
898 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
899 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
900 HDA_AMP_MUTE, mute);
901}
902
903static void ad1986a_hp_automute(struct hda_codec *codec)
904{
905 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200906
Takashi Iwaid56757a2009-11-18 08:00:14 +0100907 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200908 if (spec->inv_jack_detect)
909 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200910 ad1986a_update_hp(codec);
911}
912
913#define AD1986A_HP_EVENT 0x37
914
915static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
916{
917 if ((res >> 26) != AD1986A_HP_EVENT)
918 return;
919 ad1986a_hp_automute(codec);
920}
921
922static int ad1986a_hp_init(struct hda_codec *codec)
923{
924 ad198x_init(codec);
925 ad1986a_hp_automute(codec);
926 return 0;
927}
928
929/* bind hp and internal speaker mute (with plug check) */
930static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
931 struct snd_ctl_elem_value *ucontrol)
932{
933 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai8092e602012-12-13 17:03:30 +0100934 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200935 if (change)
936 ad1986a_update_hp(codec);
937 return change;
938}
939
Takashi Iwai498f5b12011-05-02 11:33:15 +0200940static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200941 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
942 {
943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
944 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100945 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200946 .info = snd_hda_mixer_amp_switch_info,
947 .get = snd_hda_mixer_amp_switch_get,
948 .put = ad1986a_hp_master_sw_put,
949 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
950 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200951 { } /* end */
952};
953
Takashi Iwai16d11a82009-06-24 14:07:53 +0200954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955/*
956 * initialization verbs
957 */
Takashi Iwai498f5b12011-05-02 11:33:15 +0200958static const struct hda_verb ad1986a_init_verbs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /* Front, Surround, CLFE DAC; mute as default */
960 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
961 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
962 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
963 /* Downmix - off */
964 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
965 /* HP, Line-Out, Surround, CLFE selectors */
966 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
967 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
968 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
969 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
970 /* Mono selector */
971 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
972 /* Mic selector: Mic 1/2 pin */
973 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
974 /* Line-in selector: Line-in */
975 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
976 /* Mic 1/2 swap */
977 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
978 /* Record selector: mic */
979 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
980 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
981 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
982 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
983 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
984 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
985 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
986 /* PC beep */
987 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
988 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
989 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
990 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
991 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
992 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
993 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200994 /* HP Pin */
995 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
996 /* Front, Surround, CLFE Pins */
997 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
998 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
999 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1000 /* Mono Pin */
1001 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1002 /* Mic Pin */
1003 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1004 /* Line, Aux, CD, Beep-In Pin */
1005 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1006 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1007 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1008 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1009 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 { } /* end */
1011};
1012
Takashi Iwai498f5b12011-05-02 11:33:15 +02001013static const struct hda_verb ad1986a_ch2_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001014 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001015 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1016 /* Line-in selectors */
1017 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001018 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001019 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1020 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
1021 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001022 { } /* end */
1023};
1024
Takashi Iwai498f5b12011-05-02 11:33:15 +02001025static const struct hda_verb ad1986a_ch4_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001026 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001027 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1028 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001029 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001030 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1031 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001032 { } /* end */
1033};
1034
Takashi Iwai498f5b12011-05-02 11:33:15 +02001035static const struct hda_verb ad1986a_ch6_init[] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001036 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001037 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1038 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001039 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +02001040 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1041 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +01001042 { } /* end */
1043};
1044
Takashi Iwai498f5b12011-05-02 11:33:15 +02001045static const struct hda_channel_mode ad1986a_modes[3] = {
Takashi Iwai9230d212006-03-13 13:49:49 +01001046 { 2, ad1986a_ch2_init },
1047 { 4, ad1986a_ch4_init },
1048 { 6, ad1986a_ch6_init },
1049};
1050
Takashi Iwai825aa972006-03-17 10:50:49 +01001051/* eapd initialization */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001052static const struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +01001053 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +01001054 {}
1055};
1056
Takashi Iwai498f5b12011-05-02 11:33:15 +02001057static const struct hda_verb ad1986a_automic_verbs[] = {
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001058 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1059 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1060 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
1061 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
1062 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
1063 {}
1064};
1065
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001066/* pin sensing on HP jack */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001067static const struct hda_verb ad1986a_hp_init_verbs[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001068 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
1069 {}
1070};
1071
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001072static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
1073 unsigned int res)
1074{
1075 switch (res >> 26) {
1076 case AD1986A_HP_EVENT:
1077 ad1986a_hp_automute(codec);
1078 break;
1079 case AD1986A_MIC_EVENT:
1080 ad1986a_automic(codec);
1081 break;
1082 }
1083}
1084
1085static int ad1986a_samsung_p50_init(struct hda_codec *codec)
1086{
1087 ad198x_init(codec);
1088 ad1986a_hp_automute(codec);
1089 ad1986a_automic(codec);
1090 return 0;
1091}
1092
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001093
Takashi Iwai9230d212006-03-13 13:49:49 +01001094/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001095enum {
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001096 AD1986A_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001097 AD1986A_6STACK,
1098 AD1986A_3STACK,
1099 AD1986A_LAPTOP,
1100 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001101 AD1986A_LAPTOP_AUTOMUTE,
Takashi Iwai1725b822008-11-21 02:25:48 +01001102 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001103 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001104 AD1986A_MODELS
1105};
Takashi Iwai9230d212006-03-13 13:49:49 +01001106
Takashi Iwaiea734962011-01-17 11:29:34 +01001107static const char * const ad1986a_models[AD1986A_MODELS] = {
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001108 [AD1986A_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001109 [AD1986A_6STACK] = "6stack",
1110 [AD1986A_3STACK] = "3stack",
1111 [AD1986A_LAPTOP] = "laptop",
1112 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001113 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Takashi Iwai1725b822008-11-21 02:25:48 +01001114 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001115 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001116};
1117
Takashi Iwai498f5b12011-05-02 11:33:15 +02001118static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001119 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001120 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001121 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001122 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001123 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1124 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1125 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1126 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001127 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001128 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001129 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1130 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1131 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1132 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1133 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001134 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Daniel T Chenba579eb2010-02-20 11:16:30 -05001135 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001136 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001137 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001138 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001139 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001140 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001141 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001142 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001143 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001144 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001145 {}
1146};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Takashi Iwai83012a72012-08-24 18:38:08 +02001148#ifdef CONFIG_PM
Takashi Iwai498f5b12011-05-02 11:33:15 +02001149static const struct hda_amp_list ad1986a_loopbacks[] = {
Takashi Iwaicb53c622007-08-10 17:21:45 +02001150 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1151 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1152 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1153 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1154 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1155 { } /* end */
1156};
1157#endif
1158
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001159static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1160{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001161 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001162 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1163}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001164#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001165
Takashi Iwai361dab32012-05-09 14:35:27 +02001166static int alloc_ad_spec(struct hda_codec *codec)
1167{
1168 struct ad198x_spec *spec;
1169
1170 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1171 if (!spec)
1172 return -ENOMEM;
1173 codec->spec = spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001174 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02001175 return 0;
1176}
1177
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001178/*
Takashi Iwaia928bd22013-01-22 18:18:42 +01001179 * AD1986A fixup codes
1180 */
1181
1182/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
1183static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
1184 const struct hda_fixup *fix, int action)
1185{
1186 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1187 codec->inv_jack_detect = 1;
1188}
1189
1190enum {
1191 AD1986A_FIXUP_INV_JACK_DETECT,
Takashi Iwaie0b27162013-07-04 16:50:46 +02001192 AD1986A_FIXUP_ULTRA,
Takashi Iwaia928bd22013-01-22 18:18:42 +01001193};
1194
1195static const struct hda_fixup ad1986a_fixups[] = {
1196 [AD1986A_FIXUP_INV_JACK_DETECT] = {
1197 .type = HDA_FIXUP_FUNC,
1198 .v.func = ad_fixup_inv_jack_detect,
1199 },
Takashi Iwaie0b27162013-07-04 16:50:46 +02001200 [AD1986A_FIXUP_ULTRA] = {
1201 .type = HDA_FIXUP_PINS,
1202 .v.pins = (const struct hda_pintbl[]) {
1203 { 0x1b, 0x90170110 }, /* speaker */
1204 { 0x1d, 0x90a7013e }, /* int mic */
1205 {}
1206 },
1207 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01001208};
1209
1210static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
Takashi Iwaie0b27162013-07-04 16:50:46 +02001211 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001212 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
1213 {}
1214};
1215
1216/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001217 */
1218static int ad1986a_parse_auto_config(struct hda_codec *codec)
1219{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001220 int err;
1221 struct ad198x_spec *spec;
1222
1223 err = alloc_ad_spec(codec);
1224 if (err < 0)
1225 return err;
1226 spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001227
1228 /* AD1986A has the inverted EAPD implementation */
1229 codec->inv_eapd = 1;
1230
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001231 spec->gen.mixer_nid = 0x07;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001232 spec->gen.beep_nid = 0x19;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001233 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1234
1235 /* AD1986A has a hardware problem that it can't share a stream
1236 * with multiple output pins. The copy of front to surrounds
1237 * causes noisy or silent outputs at a certain timing, e.g.
1238 * changing the volume.
1239 * So, let's disable the shared stream.
1240 */
1241 spec->gen.multiout.no_share_stream = 1;
1242
Takashi Iwaia928bd22013-01-22 18:18:42 +01001243 snd_hda_pick_fixup(codec, NULL, ad1986a_fixup_tbl, ad1986a_fixups);
1244 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1245
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001246 err = ad198x_parse_auto_config(codec);
1247 if (err < 0) {
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001248 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001249 return err;
1250 }
1251
Takashi Iwaia928bd22013-01-22 18:18:42 +01001252 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1253
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001254 return 0;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001255}
1256
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001257#ifdef ENABLE_AD_STATIC_QUIRKS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258static int patch_ad1986a(struct hda_codec *codec)
1259{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001260 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001261 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001263 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1264 ad1986a_models,
1265 ad1986a_cfg_tbl);
Takashi Iwai657e1b92013-01-22 18:42:39 +01001266 if (board_config < 0) {
1267 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
1268 codec->chip_name);
1269 board_config = AD1986A_AUTO;
1270 }
1271
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001272 if (board_config == AD1986A_AUTO)
1273 return ad1986a_parse_auto_config(codec);
1274
Takashi Iwai361dab32012-05-09 14:35:27 +02001275 err = alloc_ad_spec(codec);
1276 if (err < 0)
1277 return err;
1278 spec = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001280 err = snd_hda_attach_beep_device(codec, 0x19);
1281 if (err < 0) {
1282 ad198x_free(codec);
1283 return err;
1284 }
1285 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 spec->multiout.max_channels = 6;
1288 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1289 spec->multiout.dac_nids = ad1986a_dac_nids;
1290 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001291 spec->num_adc_nids = 1;
1292 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001293 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001294 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001295 spec->num_mixers = 1;
1296 spec->mixers[0] = ad1986a_mixers;
1297 spec->num_init_verbs = 1;
1298 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwai83012a72012-08-24 18:38:08 +02001299#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02001300 spec->loopback.amplist = ad1986a_loopbacks;
1301#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001302 spec->vmaster_nid = 0x1b;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001303 codec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001305 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Takashi Iwai9230d212006-03-13 13:49:49 +01001307 /* override some parameters */
Takashi Iwai9230d212006-03-13 13:49:49 +01001308 switch (board_config) {
1309 case AD1986A_3STACK:
1310 spec->num_mixers = 2;
1311 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001312 spec->num_init_verbs = 2;
1313 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001314 spec->channel_mode = ad1986a_modes;
1315 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001316 spec->need_dac_fix = 1;
1317 spec->multiout.max_channels = 2;
1318 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001319 break;
1320 case AD1986A_LAPTOP:
1321 spec->mixers[0] = ad1986a_laptop_mixers;
1322 spec->multiout.max_channels = 2;
1323 spec->multiout.num_dacs = 1;
1324 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1325 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001326 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001327 spec->num_mixers = 3;
1328 spec->mixers[0] = ad1986a_laptop_master_mixers;
1329 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1330 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001331 spec->num_init_verbs = 2;
1332 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1333 spec->multiout.max_channels = 2;
1334 spec->multiout.num_dacs = 1;
1335 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1336 if (!is_jack_available(codec, 0x25))
1337 spec->multiout.dig_out_nid = 0;
1338 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1339 break;
1340 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001341 spec->num_mixers = 2;
1342 spec->mixers[0] = ad1986a_laptop_master_mixers;
1343 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001344 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001345 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001346 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001347 spec->multiout.max_channels = 2;
1348 spec->multiout.num_dacs = 1;
1349 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001350 if (!is_jack_available(codec, 0x25))
1351 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001352 spec->input_mux = &ad1986a_automic_capture_source;
1353 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1354 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001355 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001356 case AD1986A_SAMSUNG_P50:
1357 spec->num_mixers = 2;
1358 spec->mixers[0] = ad1986a_automute_master_mixers;
1359 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1360 spec->num_init_verbs = 4;
1361 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1362 spec->init_verbs[2] = ad1986a_automic_verbs;
1363 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1364 spec->multiout.max_channels = 2;
1365 spec->multiout.num_dacs = 1;
1366 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1367 if (!is_jack_available(codec, 0x25))
1368 spec->multiout.dig_out_nid = 0;
1369 spec->input_mux = &ad1986a_automic_capture_source;
1370 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1371 codec->patch_ops.init = ad1986a_samsung_p50_init;
1372 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001373 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001374 spec->num_mixers = 3;
1375 spec->mixers[0] = ad1986a_automute_master_mixers;
1376 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1377 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001378 spec->num_init_verbs = 3;
1379 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1380 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1381 spec->multiout.max_channels = 2;
1382 spec->multiout.num_dacs = 1;
1383 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001384 if (!is_jack_available(codec, 0x25))
1385 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001386 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1387 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1388 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001389 /* Lenovo N100 seems to report the reversed bit
1390 * for HP jack-sensing
1391 */
1392 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001393 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001394 }
1395
Takashi Iwaid29240c2007-10-26 12:35:56 +02001396 /* AD1986A has a hardware problem that it can't share a stream
1397 * with multiple output pins. The copy of front to surrounds
1398 * causes noisy or silent outputs at a certain timing, e.g.
1399 * changing the volume.
1400 * So, let's disable the shared stream.
1401 */
1402 spec->multiout.no_share_stream = 1;
1403
Takashi Iwai729d55b2009-12-25 22:49:01 +01001404 codec->no_trigger_sense = 1;
Takashi Iwai0e7adbe2010-10-25 10:37:11 +02001405 codec->no_sticky_stream = 1;
Takashi Iwai729d55b2009-12-25 22:49:01 +01001406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 return 0;
1408}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001409#else /* ENABLE_AD_STATIC_QUIRKS */
1410#define patch_ad1986a ad1986a_parse_auto_config
1411#endif /* ENABLE_AD_STATIC_QUIRKS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001414 * AD1983 specific
1415 */
1416
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001417/*
1418 * SPDIF mux control for AD1983 auto-parser
1419 */
1420static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
1421 struct snd_ctl_elem_info *uinfo)
1422{
1423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1424 struct ad198x_spec *spec = codec->spec;
1425 static const char * const texts2[] = { "PCM", "ADC" };
1426 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
1427 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1428 int num_conns = snd_hda_get_num_conns(codec, dig_out);
1429
1430 if (num_conns == 2)
1431 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
1432 else if (num_conns == 3)
1433 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
1434 else
1435 return -EINVAL;
1436}
1437
1438static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
1439 struct snd_ctl_elem_value *ucontrol)
1440{
1441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1442 struct ad198x_spec *spec = codec->spec;
1443
1444 ucontrol->value.enumerated.item[0] = spec->cur_smux;
1445 return 0;
1446}
1447
1448static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
1449 struct snd_ctl_elem_value *ucontrol)
1450{
1451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1452 struct ad198x_spec *spec = codec->spec;
1453 unsigned int val = ucontrol->value.enumerated.item[0];
1454 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1455 int num_conns = snd_hda_get_num_conns(codec, dig_out);
1456
1457 if (val >= num_conns)
1458 return -EINVAL;
1459 if (spec->cur_smux == val)
1460 return 0;
1461 spec->cur_smux = val;
1462 snd_hda_codec_write_cache(codec, dig_out, 0,
1463 AC_VERB_SET_CONNECT_SEL, val);
1464 return 1;
1465}
1466
1467static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
1468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1469 .name = "IEC958 Playback Source",
1470 .info = ad1983_auto_smux_enum_info,
1471 .get = ad1983_auto_smux_enum_get,
1472 .put = ad1983_auto_smux_enum_put,
1473};
1474
1475static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
1476{
1477 struct ad198x_spec *spec = codec->spec;
1478 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
1479 int num_conns;
1480
1481 if (!dig_out)
1482 return 0;
1483 num_conns = snd_hda_get_num_conns(codec, dig_out);
1484 if (num_conns != 2 && num_conns != 3)
1485 return 0;
1486 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
1487 return -ENOMEM;
1488 return 0;
1489}
1490
Takashi Iwaibd450dc2013-07-04 15:48:04 +02001491static int patch_ad1983(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001492{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001493 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001494 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001495
Takashi Iwai361dab32012-05-09 14:35:27 +02001496 err = alloc_ad_spec(codec);
1497 if (err < 0)
1498 return err;
1499 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001500
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001501 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001502 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1503 err = ad198x_parse_auto_config(codec);
1504 if (err < 0)
1505 goto error;
1506 err = ad1983_add_spdif_mux_ctl(codec);
1507 if (err < 0)
1508 goto error;
1509 return 0;
1510
1511 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001512 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001513 return err;
1514}
1515
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001516
1517/*
1518 * AD1981 HD specific
1519 */
1520
Takashi Iwaia928bd22013-01-22 18:18:42 +01001521/* follow EAPD via vmaster hook */
1522static void ad_vmaster_eapd_hook(void *private_data, int enabled)
1523{
1524 struct hda_codec *codec = private_data;
1525 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02001526
1527 if (!spec->eapd_nid)
1528 return;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001529 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
1530 AC_VERB_SET_EAPD_BTLENABLE,
1531 enabled ? 0x02 : 0x00);
1532}
1533
1534static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
1535 const struct hda_fixup *fix, int action)
1536{
1537 struct ad198x_spec *spec = codec->spec;
1538
1539 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1540 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1541 spec->eapd_nid = 0x05;
1542 }
1543}
1544
1545/* set the upper-limit for mixer amp to 0dB for avoiding the possible
1546 * damage by overloading
1547 */
1548static void ad1981_fixup_amp_override(struct hda_codec *codec,
1549 const struct hda_fixup *fix, int action)
1550{
1551 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1552 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1553 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1554 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1555 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1556 (1 << AC_AMPCAP_MUTE_SHIFT));
1557}
1558
1559enum {
1560 AD1981_FIXUP_AMP_OVERRIDE,
1561 AD1981_FIXUP_HP_EAPD,
1562};
1563
1564static const struct hda_fixup ad1981_fixups[] = {
1565 [AD1981_FIXUP_AMP_OVERRIDE] = {
1566 .type = HDA_FIXUP_FUNC,
1567 .v.func = ad1981_fixup_amp_override,
1568 },
1569 [AD1981_FIXUP_HP_EAPD] = {
1570 .type = HDA_FIXUP_FUNC,
1571 .v.func = ad1981_fixup_hp_eapd,
1572 .chained = true,
1573 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
1574 },
1575};
1576
1577static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
1578 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
1579 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
1580 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
1581 /* HP nx6320 (reversed SSID, H/W bug) */
1582 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
1583 {}
1584};
1585
Takashi Iwaibd450dc2013-07-04 15:48:04 +02001586static int patch_ad1981(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001587{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001588 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001589 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001590
Takashi Iwai361dab32012-05-09 14:35:27 +02001591 err = alloc_ad_spec(codec);
1592 if (err < 0)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001593 return -ENOMEM;
Takashi Iwai361dab32012-05-09 14:35:27 +02001594 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001595
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001596 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001597 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001598 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01001599
1600 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
1601 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1602
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001603 err = ad198x_parse_auto_config(codec);
1604 if (err < 0)
1605 goto error;
1606 err = ad1983_add_spdif_mux_ctl(codec);
1607 if (err < 0)
1608 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001609
1610 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1611
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001612 return 0;
1613
1614 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001615 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001616 return err;
1617}
1618
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001619
1620/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001621 * AD1988
1622 *
1623 * Output pins and routes
1624 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001625 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001626 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1627 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1628 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1629 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1630 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1631 * port-F 0x16 (mute) <- 0x2a <- 06
1632 * port-G 0x24 (mute) <- 0x27 <- 05
1633 * port-H 0x25 (mute) <- 0x28 <- 0a
1634 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1635 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001636 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1637 * (*) 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 +01001638 *
1639 * Input pins and routes
1640 *
1641 * pin boost mix input # / adc input #
1642 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1643 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1644 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1645 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1646 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1647 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1648 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1649 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1650 *
1651 *
1652 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001653 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001654 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001655 *
1656 * Inputs of Analog Mix (0x20)
1657 * 0:Port-B (front mic)
1658 * 1:Port-C/G/H (line-in)
1659 * 2:Port-A
1660 * 3:Port-D (line-in/2)
1661 * 4:Port-E/G/H (mic-in)
1662 * 5:Port-F (mic2-in)
1663 * 6:CD
1664 * 7:Beep
1665 *
1666 * ADC selection
1667 * 0:Port-A
1668 * 1:Port-B (front mic-in)
1669 * 2:Port-C (line-in)
1670 * 3:Port-F (mic2-in)
1671 * 4:Port-E (mic-in)
1672 * 5:CD
1673 * 6:Port-G
1674 * 7:Port-H
1675 * 8:Port-D (line-in/2)
1676 * 9:Mix
1677 *
1678 * Proposed pin assignments by the datasheet
1679 *
1680 * 6-stack
1681 * Port-A front headphone
1682 * B front mic-in
1683 * C rear line-in
1684 * D rear front-out
1685 * E rear mic-in
1686 * F rear surround
1687 * G rear CLFE
1688 * H rear side
1689 *
1690 * 3-stack
1691 * Port-A front headphone
1692 * B front mic
1693 * C rear line-in/surround
1694 * D rear front-out
1695 * E rear mic-in/CLFE
1696 *
1697 * laptop
1698 * Port-A headphone
1699 * B mic-in
1700 * C docking station
1701 * D internal speaker (with EAPD)
1702 * E/F quad mic array
1703 */
1704
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001705#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001706static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1707 struct snd_ctl_elem_info *uinfo)
1708{
1709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1710 struct ad198x_spec *spec = codec->spec;
1711 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1712 spec->num_channel_mode);
1713}
1714
1715static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
1717{
1718 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1719 struct ad198x_spec *spec = codec->spec;
1720 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1721 spec->num_channel_mode, spec->multiout.max_channels);
1722}
1723
1724static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1725 struct snd_ctl_elem_value *ucontrol)
1726{
1727 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1728 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001729 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1730 spec->num_channel_mode,
1731 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001732 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001733 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001734 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001735}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001736#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001737
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001738static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
1739 struct snd_ctl_elem_info *uinfo)
1740{
1741 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1742 static const char * const texts[] = {
1743 "PCM", "ADC1", "ADC2", "ADC3",
1744 };
1745 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
1746 if (num_conns > 4)
1747 num_conns = 4;
1748 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
1749}
1750
1751static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
1752 struct snd_ctl_elem_value *ucontrol)
1753{
1754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1755 struct ad198x_spec *spec = codec->spec;
1756
1757 ucontrol->value.enumerated.item[0] = spec->cur_smux;
1758 return 0;
1759}
1760
1761static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
1762 struct snd_ctl_elem_value *ucontrol)
1763{
1764 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1765 struct ad198x_spec *spec = codec->spec;
1766 unsigned int val = ucontrol->value.enumerated.item[0];
1767 struct nid_path *path;
1768 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
1769
1770 if (val >= num_conns)
1771 return -EINVAL;
1772 if (spec->cur_smux == val)
1773 return 0;
1774
1775 mutex_lock(&codec->control_mutex);
1776 codec->cached_write = 1;
1777 path = snd_hda_get_path_from_idx(codec,
1778 spec->smux_paths[spec->cur_smux]);
1779 if (path)
1780 snd_hda_activate_path(codec, path, false, true);
1781 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
1782 if (path)
1783 snd_hda_activate_path(codec, path, true, true);
1784 spec->cur_smux = val;
1785 codec->cached_write = 0;
1786 mutex_unlock(&codec->control_mutex);
1787 snd_hda_codec_flush_cache(codec); /* flush the updates */
1788 return 1;
1789}
1790
1791static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
1792 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1793 .name = "IEC958 Playback Source",
1794 .info = ad1988_auto_smux_enum_info,
1795 .get = ad1988_auto_smux_enum_get,
1796 .put = ad1988_auto_smux_enum_put,
1797};
1798
1799static int ad1988_auto_init(struct hda_codec *codec)
1800{
1801 struct ad198x_spec *spec = codec->spec;
1802 int i, err;
1803
1804 err = snd_hda_gen_init(codec);
1805 if (err < 0)
1806 return err;
1807 if (!spec->gen.autocfg.dig_outs)
1808 return 0;
1809
1810 for (i = 0; i < 4; i++) {
1811 struct nid_path *path;
1812 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
1813 if (path)
1814 snd_hda_activate_path(codec, path, path->active, false);
1815 }
1816
1817 return 0;
1818}
1819
1820static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
1821{
1822 struct ad198x_spec *spec = codec->spec;
1823 int i, num_conns;
1824 /* we create four static faked paths, since AD codecs have odd
1825 * widget connections regarding the SPDIF out source
1826 */
1827 static struct nid_path fake_paths[4] = {
1828 {
1829 .depth = 3,
1830 .path = { 0x02, 0x1d, 0x1b },
1831 .idx = { 0, 0, 0 },
1832 .multi = { 0, 0, 0 },
1833 },
1834 {
1835 .depth = 4,
1836 .path = { 0x08, 0x0b, 0x1d, 0x1b },
1837 .idx = { 0, 0, 1, 0 },
1838 .multi = { 0, 1, 0, 0 },
1839 },
1840 {
1841 .depth = 4,
1842 .path = { 0x09, 0x0b, 0x1d, 0x1b },
1843 .idx = { 0, 1, 1, 0 },
1844 .multi = { 0, 1, 0, 0 },
1845 },
1846 {
1847 .depth = 4,
1848 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
1849 .idx = { 0, 2, 1, 0 },
1850 .multi = { 0, 1, 0, 0 },
1851 },
1852 };
1853
1854 /* SPDIF source mux appears to be present only on AD1988A */
1855 if (!spec->gen.autocfg.dig_outs ||
1856 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
1857 return 0;
1858
1859 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
1860 if (num_conns != 3 && num_conns != 4)
1861 return 0;
1862
1863 for (i = 0; i < num_conns; i++) {
1864 struct nid_path *path = snd_array_new(&spec->gen.paths);
1865 if (!path)
1866 return -ENOMEM;
1867 *path = fake_paths[i];
1868 if (!i)
1869 path->active = 1;
1870 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
1871 }
1872
1873 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
1874 return -ENOMEM;
1875
1876 codec->patch_ops.init = ad1988_auto_init;
1877
1878 return 0;
1879}
1880
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001881/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01001882 */
1883
Takashi Iwai36ad4532013-07-04 16:34:20 +02001884enum {
1885 AD1988_FIXUP_6STACK_DIG,
1886};
1887
1888static const struct hda_fixup ad1988_fixups[] = {
1889 [AD1988_FIXUP_6STACK_DIG] = {
1890 .type = HDA_FIXUP_PINS,
1891 .v.pins = (const struct hda_pintbl[]) {
1892 { 0x11, 0x02214130 }, /* front-hp */
1893 { 0x12, 0x01014010 }, /* line-out */
1894 { 0x14, 0x02a19122 }, /* front-mic */
1895 { 0x15, 0x01813021 }, /* line-in */
1896 { 0x16, 0x01011012 }, /* line-out */
1897 { 0x17, 0x01a19020 }, /* mic */
1898 { 0x1b, 0x0145f1f0 }, /* SPDIF */
1899 { 0x24, 0x01016011 }, /* line-out */
1900 { 0x25, 0x01012013 }, /* line-out */
1901 { }
1902 }
1903 },
1904};
1905
1906static const struct hda_model_fixup ad1988_fixup_models[] = {
1907 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
1908 {}
1909};
1910
1911static int patch_ad1988(struct hda_codec *codec)
Takashi Iwaid32410b12005-11-24 16:06:23 +01001912{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001913 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001914 int err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01001915
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001916 err = alloc_ad_spec(codec);
1917 if (err < 0)
1918 return err;
1919 spec = codec->spec;
1920
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001921 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01001922 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001923 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001924 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai36ad4532013-07-04 16:34:20 +02001925
1926 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
1927 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1928
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001929 err = ad198x_parse_auto_config(codec);
1930 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001931 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001932 err = ad1988_add_spdif_mux_ctl(codec);
1933 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001934 goto error;
Takashi Iwai36ad4532013-07-04 16:34:20 +02001935
1936 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1937
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001938 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001939
1940 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001941 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001942 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01001943}
1944
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001945
1946/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02001947 * AD1884 / AD1984
1948 *
1949 * port-B - front line/mic-in
1950 * port-E - aux in/out
1951 * port-F - aux in/out
1952 * port-C - rear line/mic-in
1953 * port-D - rear line/hp-out
1954 * port-A - front line/hp-out
1955 *
1956 * AD1984 = AD1884 + two digital mic-ins
1957 *
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001958 * AD1883 / AD1884A / AD1984A / AD1984B
1959 *
1960 * port-B (0x14) - front mic-in
1961 * port-E (0x1c) - rear mic-in
1962 * port-F (0x16) - CD / ext out
1963 * port-C (0x15) - rear line-in
1964 * port-D (0x12) - rear line-out
1965 * port-A (0x11) - front hp-out
1966 *
1967 * AD1984A = AD1884A + digital-mic
1968 * AD1883 = equivalent with AD1984A
1969 * AD1984B = AD1984A + extra SPDIF-out
Takashi Iwai2bac6472007-05-18 18:21:41 +02001970 */
1971
Takashi Iwaia928bd22013-01-22 18:18:42 +01001972/* set the upper-limit for mixer amp to 0dB for avoiding the possible
1973 * damage by overloading
1974 */
1975static void ad1884_fixup_amp_override(struct hda_codec *codec,
1976 const struct hda_fixup *fix, int action)
1977{
1978 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1979 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
1980 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1981 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1982 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1983 (1 << AC_AMPCAP_MUTE_SHIFT));
1984}
1985
Takashi Iwai1a39b5e2013-07-04 14:32:16 +02001986/* toggle GPIO1 according to the mute state */
1987static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
1988{
1989 struct hda_codec *codec = private_data;
1990 struct ad198x_spec *spec = codec->spec;
1991
1992 if (spec->eapd_nid)
1993 ad_vmaster_eapd_hook(private_data, enabled);
1994 snd_hda_codec_update_cache(codec, 0x01, 0,
1995 AC_VERB_SET_GPIO_DATA,
1996 enabled ? 0x00 : 0x02);
1997}
1998
Takashi Iwaia928bd22013-01-22 18:18:42 +01001999static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
2000 const struct hda_fixup *fix, int action)
2001{
2002 struct ad198x_spec *spec = codec->spec;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +02002003 static const struct hda_verb gpio_init_verbs[] = {
2004 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
2005 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
2006 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
2007 {},
2008 };
Takashi Iwaia928bd22013-01-22 18:18:42 +01002009
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02002010 switch (action) {
2011 case HDA_FIXUP_ACT_PRE_PROBE:
Takashi Iwai1a39b5e2013-07-04 14:32:16 +02002012 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
2013 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02002014 break;
2015 case HDA_FIXUP_ACT_PROBE:
Takashi Iwaia928bd22013-01-22 18:18:42 +01002016 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
2017 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
2018 else
2019 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02002020 break;
Takashi Iwaia928bd22013-01-22 18:18:42 +01002021 }
2022}
2023
Takashi Iwai6a699be2013-07-04 14:45:37 +02002024/* set magic COEFs for dmic */
2025static const struct hda_verb ad1884_dmic_init_verbs[] = {
2026 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
2027 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
2028 {}
2029};
2030
Takashi Iwaia928bd22013-01-22 18:18:42 +01002031enum {
2032 AD1884_FIXUP_AMP_OVERRIDE,
2033 AD1884_FIXUP_HP_EAPD,
Takashi Iwai6a699be2013-07-04 14:45:37 +02002034 AD1884_FIXUP_DMIC_COEF,
Takashi Iwaif4046272013-07-04 15:14:17 +02002035 AD1884_FIXUP_HP_TOUCHSMART,
Takashi Iwaia928bd22013-01-22 18:18:42 +01002036};
2037
2038static const struct hda_fixup ad1884_fixups[] = {
2039 [AD1884_FIXUP_AMP_OVERRIDE] = {
2040 .type = HDA_FIXUP_FUNC,
2041 .v.func = ad1884_fixup_amp_override,
2042 },
2043 [AD1884_FIXUP_HP_EAPD] = {
2044 .type = HDA_FIXUP_FUNC,
2045 .v.func = ad1884_fixup_hp_eapd,
2046 .chained = true,
2047 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
2048 },
Takashi Iwai6a699be2013-07-04 14:45:37 +02002049 [AD1884_FIXUP_DMIC_COEF] = {
2050 .type = HDA_FIXUP_VERBS,
2051 .v.verbs = ad1884_dmic_init_verbs,
2052 },
Takashi Iwaif4046272013-07-04 15:14:17 +02002053 [AD1884_FIXUP_HP_TOUCHSMART] = {
2054 .type = HDA_FIXUP_VERBS,
2055 .v.verbs = ad1884_dmic_init_verbs,
2056 .chained = true,
2057 .chain_id = AD1884_FIXUP_HP_EAPD,
2058 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01002059};
2060
2061static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
Takashi Iwaif4046272013-07-04 15:14:17 +02002062 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
Takashi Iwaia928bd22013-01-22 18:18:42 +01002063 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
Takashi Iwai6a699be2013-07-04 14:45:37 +02002064 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_DMIC_COEF),
Takashi Iwaia928bd22013-01-22 18:18:42 +01002065 {}
2066};
2067
2068
Takashi Iwai5ccc6182013-07-04 15:36:56 +02002069static int patch_ad1884(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01002070{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002071 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01002072 int err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01002073
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002074 err = alloc_ad_spec(codec);
2075 if (err < 0)
2076 return err;
2077 spec = codec->spec;
2078
Takashi Iwaif2f8be42013-01-21 16:40:16 +01002079 spec->gen.mixer_nid = 0x20;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01002080 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01002081 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01002082
2083 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
2084 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
2085
Takashi Iwai272f3ea2013-01-22 15:31:33 +01002086 err = ad198x_parse_auto_config(codec);
2087 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002088 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01002089 err = ad1983_add_spdif_mux_ctl(codec);
2090 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002091 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01002092
2093 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
2094
Takashi Iwai272f3ea2013-01-22 15:31:33 +01002095 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002096
2097 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01002098 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002099 return err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01002100}
2101
Takashi Iwaic5059252008-02-16 09:43:56 +01002102/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02002103 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02002104 *
2105 * port-A - front hp-out
2106 * port-B - front mic-in
2107 * port-C - rear line-in, shared surr-out (3stack)
2108 * port-D - rear line-out
2109 * port-E - rear mic-in, shared clfe-out (3stack)
2110 * port-F - rear surr-out (6stack)
2111 * port-G - rear clfe-out (6stack)
2112 */
2113
Takashi Iwaiaa95d612013-07-04 15:16:31 +02002114static int patch_ad1882(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01002115{
Takashi Iwai0ac85512007-06-20 15:46:13 +02002116 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002117 int err;
Takashi Iwai0ac85512007-06-20 15:46:13 +02002118
Takashi Iwai361dab32012-05-09 14:35:27 +02002119 err = alloc_ad_spec(codec);
2120 if (err < 0)
2121 return err;
2122 spec = codec->spec;
Takashi Iwai0ac85512007-06-20 15:46:13 +02002123
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002124 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01002125 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01002126 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002127 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
2128 err = ad198x_parse_auto_config(codec);
2129 if (err < 0)
2130 goto error;
2131 err = ad1988_add_spdif_mux_ctl(codec);
2132 if (err < 0)
2133 goto error;
2134 return 0;
2135
2136 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01002137 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01002138 return err;
2139}
2140
Takashi Iwai0ac85512007-06-20 15:46:13 +02002141
2142/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 * patch entries
2144 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02002145static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai5ccc6182013-07-04 15:36:56 +02002146 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
Takashi Iwai0ac85512007-06-20 15:46:13 +02002147 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02002148 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02002149 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02002150 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
2151 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002152 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2153 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02002154 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002156 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02002157 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02002158 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002159 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
2160 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 {} /* terminator */
2162};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01002163
2164MODULE_ALIAS("snd-hda-codec-id:11d4*");
2165
2166MODULE_LICENSE("GPL");
2167MODULE_DESCRIPTION("Analog Devices HD-audio codec");
2168
2169static struct hda_codec_preset_list analog_list = {
2170 .preset = snd_hda_preset_analog,
2171 .owner = THIS_MODULE,
2172};
2173
2174static int __init patch_analog_init(void)
2175{
2176 return snd_hda_add_codec_preset(&analog_list);
2177}
2178
2179static void __exit patch_analog_exit(void)
2180{
2181 snd_hda_delete_codec_preset(&analog_list);
2182}
2183
2184module_init(patch_analog_init)
2185module_exit(patch_analog_exit)