blob: 7a426ed491f2bea356f6a2610329f5ed84e17ebf [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
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020036struct ad198x_spec {
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010037 struct hda_gen_spec gen;
38
Takashi Iwai272f3ea2013-01-22 15:31:33 +010039 /* for auto parser */
40 int smux_paths[4];
41 unsigned int cur_smux;
Takashi Iwaia928bd22013-01-22 18:18:42 +010042 hda_nid_t eapd_nid;
Takashi Iwai272f3ea2013-01-22 15:31:33 +010043
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010044 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
Takashi Iwai2134ea42008-01-10 16:53:55 +010047
Takashi Iwai67d634c2009-11-16 15:35:59 +010048#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010049/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwai498f5b12011-05-02 11:33:15 +020050static const struct snd_kcontrol_new ad_beep_mixer[] = {
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010051 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +020052 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010053 { } /* end */
54};
55
56#define set_beep_amp(spec, nid, idx, dir) \
57 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +010058#else
59#define set_beep_amp(spec, nid, idx, dir) /* NOP */
60#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010061
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010062#ifdef CONFIG_SND_HDA_INPUT_BEEP
63static int create_beep_ctls(struct hda_codec *codec)
64{
65 struct ad198x_spec *spec = codec->spec;
66 const struct snd_kcontrol_new *knew;
67
68 if (!spec->beep_amp)
69 return 0;
70
Takashi Iwai632408a2013-07-05 14:14:14 +020071 for (knew = ad_beep_mixer ; knew->name; knew++) {
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010072 int err;
73 struct snd_kcontrol *kctl;
74 kctl = snd_ctl_new1(knew, codec);
75 if (!kctl)
76 return -ENOMEM;
77 kctl->private_value = spec->beep_amp;
78 err = snd_hda_ctl_add(codec, 0, kctl);
79 if (err < 0)
80 return err;
81 }
82 return 0;
83}
84#else
85#define create_beep_ctls(codec) 0
86#endif
87
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020088
Daniel T Chenea52bf22009-12-27 18:48:29 -050089static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
90 hda_nid_t hp)
91{
Raymond Yaua01ef052011-06-01 15:09:48 +080092 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
93 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010094 !codec->inv_eapd ? 0x00 : 0x02);
Raymond Yaua01ef052011-06-01 15:09:48 +080095 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
96 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +010097 !codec->inv_eapd ? 0x00 : 0x02);
Daniel T Chenea52bf22009-12-27 18:48:29 -050098}
99
100static void ad198x_power_eapd(struct hda_codec *codec)
101{
102 /* We currently only handle front, HP */
103 switch (codec->vendor_id) {
104 case 0x11d41882:
105 case 0x11d4882a:
106 case 0x11d41884:
107 case 0x11d41984:
108 case 0x11d41883:
109 case 0x11d4184a:
110 case 0x11d4194a:
111 case 0x11d4194b:
Takashi Iwai4dffbe02011-06-03 10:05:02 +0200112 case 0x11d41988:
113 case 0x11d4198b:
114 case 0x11d4989a:
115 case 0x11d4989b:
Daniel T Chenea52bf22009-12-27 18:48:29 -0500116 ad198x_power_eapd_write(codec, 0x12, 0x11);
117 break;
118 case 0x11d41981:
119 case 0x11d41983:
120 ad198x_power_eapd_write(codec, 0x05, 0x06);
121 break;
122 case 0x11d41986:
123 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
124 break;
Daniel T Chenea52bf22009-12-27 18:48:29 -0500125 }
126}
127
Takashi Iwai0da26922011-04-26 15:18:33 +0200128static void ad198x_shutup(struct hda_codec *codec)
129{
130 snd_hda_shutup_pins(codec);
131 ad198x_power_eapd(codec);
132}
133
Takashi Iwai2a439522011-07-26 09:52:50 +0200134#ifdef CONFIG_PM
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200135static int ad198x_suspend(struct hda_codec *codec)
Daniel T Chenea52bf22009-12-27 18:48:29 -0500136{
137 ad198x_shutup(codec);
Daniel T Chenea52bf22009-12-27 18:48:29 -0500138 return 0;
139}
Daniel T Chenea52bf22009-12-27 18:48:29 -0500140#endif
141
Takashi Iwaif710a9f2013-11-13 09:42:56 +0100142/* follow EAPD via vmaster hook */
143static void ad_vmaster_eapd_hook(void *private_data, int enabled)
144{
145 struct hda_codec *codec = private_data;
146 struct ad198x_spec *spec = codec->spec;
147
148 if (!spec->eapd_nid)
149 return;
Takashi Iwaice8e0fd2013-12-02 15:01:35 +0100150 if (codec->inv_eapd)
151 enabled = !enabled;
Takashi Iwaif710a9f2013-11-13 09:42:56 +0100152 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
153 AC_VERB_SET_EAPD_BTLENABLE,
154 enabled ? 0x02 : 0x00);
155}
Takashi Iwai9230d212006-03-13 13:49:49 +0100156
Takashi Iwai18a815d2006-03-01 19:54:39 +0100157/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100158 * Automatic parse of I/O pins from the BIOS configuration
159 */
160
161static int ad198x_auto_build_controls(struct hda_codec *codec)
162{
163 int err;
164
165 err = snd_hda_gen_build_controls(codec);
166 if (err < 0)
167 return err;
168 err = create_beep_ctls(codec);
169 if (err < 0)
170 return err;
171 return 0;
172}
173
174static const struct hda_codec_ops ad198x_auto_patch_ops = {
175 .build_controls = ad198x_auto_build_controls,
176 .build_pcms = snd_hda_gen_build_pcms,
177 .init = snd_hda_gen_init,
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100178 .free = snd_hda_gen_free,
Takashi Iwai8a6c21a2013-01-18 07:51:17 +0100179 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100180#ifdef CONFIG_PM
181 .check_power_status = snd_hda_gen_check_power_status,
182 .suspend = ad198x_suspend,
183#endif
184 .reboot_notify = ad198x_shutup,
185};
186
187
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100188static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100189{
190 struct ad198x_spec *spec = codec->spec;
191 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
192 int err;
193
194 codec->spdif_status_reset = 1;
195 codec->no_trigger_sense = 1;
196 codec->no_sticky_stream = 1;
197
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100198 spec->gen.indep_hp = indep_hp;
Takashi Iwaif1e762d2013-12-09 16:02:24 +0100199 spec->gen.add_stereo_mix_input = 1;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100200
201 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
202 if (err < 0)
203 return err;
204 err = snd_hda_gen_parse_auto_config(codec, cfg);
205 if (err < 0)
206 return err;
207
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100208 codec->patch_ops = ad198x_auto_patch_ops;
209
210 return 0;
211}
212
213/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200214 * AD1986A specific
215 */
216
Takashi Iwai361dab32012-05-09 14:35:27 +0200217static int alloc_ad_spec(struct hda_codec *codec)
218{
219 struct ad198x_spec *spec;
220
221 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
222 if (!spec)
223 return -ENOMEM;
224 codec->spec = spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100225 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +0200226 return 0;
227}
228
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100229/*
Takashi Iwaia928bd22013-01-22 18:18:42 +0100230 * AD1986A fixup codes
231 */
232
233/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
234static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
235 const struct hda_fixup *fix, int action)
236{
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100237 struct ad198x_spec *spec = codec->spec;
238
239 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaia928bd22013-01-22 18:18:42 +0100240 codec->inv_jack_detect = 1;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100241 spec->gen.keep_eapd_on = 1;
Takashi Iwaif710a9f2013-11-13 09:42:56 +0100242 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
243 spec->eapd_nid = 0x1b;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100244 }
Takashi Iwaia928bd22013-01-22 18:18:42 +0100245}
246
247enum {
248 AD1986A_FIXUP_INV_JACK_DETECT,
Takashi Iwaie0b27162013-07-04 16:50:46 +0200249 AD1986A_FIXUP_ULTRA,
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200250 AD1986A_FIXUP_SAMSUNG,
Takashi Iwai632408a2013-07-05 14:14:14 +0200251 AD1986A_FIXUP_3STACK,
252 AD1986A_FIXUP_LAPTOP,
253 AD1986A_FIXUP_LAPTOP_IMIC,
Takashi Iwaia928bd22013-01-22 18:18:42 +0100254};
255
256static const struct hda_fixup ad1986a_fixups[] = {
257 [AD1986A_FIXUP_INV_JACK_DETECT] = {
258 .type = HDA_FIXUP_FUNC,
259 .v.func = ad_fixup_inv_jack_detect,
260 },
Takashi Iwaie0b27162013-07-04 16:50:46 +0200261 [AD1986A_FIXUP_ULTRA] = {
262 .type = HDA_FIXUP_PINS,
263 .v.pins = (const struct hda_pintbl[]) {
264 { 0x1b, 0x90170110 }, /* speaker */
265 { 0x1d, 0x90a7013e }, /* int mic */
266 {}
267 },
268 },
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200269 [AD1986A_FIXUP_SAMSUNG] = {
270 .type = HDA_FIXUP_PINS,
271 .v.pins = (const struct hda_pintbl[]) {
272 { 0x1b, 0x90170110 }, /* speaker */
273 { 0x1d, 0x90a7013e }, /* int mic */
274 { 0x20, 0x411111f0 }, /* N/A */
275 { 0x24, 0x411111f0 }, /* N/A */
276 {}
277 },
278 },
Takashi Iwai632408a2013-07-05 14:14:14 +0200279 [AD1986A_FIXUP_3STACK] = {
280 .type = HDA_FIXUP_PINS,
281 .v.pins = (const struct hda_pintbl[]) {
282 { 0x1a, 0x02214021 }, /* headphone */
283 { 0x1b, 0x01014011 }, /* front */
Takashi Iwaied0e0d02014-01-07 17:48:11 +0100284 { 0x1c, 0x01813030 }, /* line-in */
285 { 0x1d, 0x01a19020 }, /* rear mic */
Takashi Iwai632408a2013-07-05 14:14:14 +0200286 { 0x1e, 0x411111f0 }, /* N/A */
287 { 0x1f, 0x02a190f0 }, /* mic */
Takashi Iwaied0e0d02014-01-07 17:48:11 +0100288 { 0x20, 0x411111f0 }, /* N/A */
Takashi Iwai632408a2013-07-05 14:14:14 +0200289 {}
290 },
291 },
292 [AD1986A_FIXUP_LAPTOP] = {
293 .type = HDA_FIXUP_PINS,
294 .v.pins = (const struct hda_pintbl[]) {
295 { 0x1a, 0x02214021 }, /* headphone */
296 { 0x1b, 0x90170110 }, /* speaker */
297 { 0x1c, 0x411111f0 }, /* N/A */
298 { 0x1d, 0x411111f0 }, /* N/A */
299 { 0x1e, 0x411111f0 }, /* N/A */
300 { 0x1f, 0x02a191f0 }, /* mic */
301 { 0x20, 0x411111f0 }, /* N/A */
302 {}
303 },
304 },
305 [AD1986A_FIXUP_LAPTOP_IMIC] = {
306 .type = HDA_FIXUP_PINS,
307 .v.pins = (const struct hda_pintbl[]) {
308 { 0x1d, 0x90a7013e }, /* int mic */
309 {}
310 },
311 .chained_before = 1,
312 .chain_id = AD1986A_FIXUP_LAPTOP,
313 },
Takashi Iwaia928bd22013-01-22 18:18:42 +0100314};
315
316static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
Takashi Iwai632408a2013-07-05 14:14:14 +0200317 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
318 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
319 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
320 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
321 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200322 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
Takashi Iwaie0b27162013-07-04 16:50:46 +0200323 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
Takashi Iwaia928bd22013-01-22 18:18:42 +0100324 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
Takashi Iwai632408a2013-07-05 14:14:14 +0200325 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
326 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
327 {}
328};
329
330static const struct hda_model_fixup ad1986a_fixup_models[] = {
331 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
332 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
333 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
334 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
Takashi Iwaia928bd22013-01-22 18:18:42 +0100335 {}
336};
337
338/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100339 */
Takashi Iwai632408a2013-07-05 14:14:14 +0200340static int patch_ad1986a(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100341{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100342 int err;
343 struct ad198x_spec *spec;
Takashi Iwai36907392013-12-10 17:29:26 +0100344 static hda_nid_t preferred_pairs[] = {
345 0x1a, 0x03,
346 0x1b, 0x03,
347 0x1c, 0x04,
348 0x1d, 0x05,
349 0x1e, 0x03,
350 0
351 };
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100352
353 err = alloc_ad_spec(codec);
354 if (err < 0)
355 return err;
356 spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100357
358 /* AD1986A has the inverted EAPD implementation */
359 codec->inv_eapd = 1;
360
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100361 spec->gen.mixer_nid = 0x07;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100362 spec->gen.beep_nid = 0x19;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100363 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
364
365 /* AD1986A has a hardware problem that it can't share a stream
366 * with multiple output pins. The copy of front to surrounds
367 * causes noisy or silent outputs at a certain timing, e.g.
368 * changing the volume.
369 * So, let's disable the shared stream.
370 */
371 spec->gen.multiout.no_share_stream = 1;
Takashi Iwai36907392013-12-10 17:29:26 +0100372 /* give fixed DAC/pin pairs */
373 spec->gen.preferred_dacs = preferred_pairs;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100374
Takashi Iwaib3bd4fc2013-12-02 15:04:03 +0100375 /* AD1986A can't manage the dynamic pin on/off smoothly */
376 spec->gen.auto_mute_via_amp = 1;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100377
Takashi Iwai632408a2013-07-05 14:14:14 +0200378 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
379 ad1986a_fixups);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100380 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
381
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100382 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100383 if (err < 0) {
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100384 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100385 return err;
386 }
387
Takashi Iwaia928bd22013-01-22 18:18:42 +0100388 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
389
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100390 return 0;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100391}
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200395 * AD1983 specific
396 */
397
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100398/*
399 * SPDIF mux control for AD1983 auto-parser
400 */
401static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
402 struct snd_ctl_elem_info *uinfo)
403{
404 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
405 struct ad198x_spec *spec = codec->spec;
406 static const char * const texts2[] = { "PCM", "ADC" };
407 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
408 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
409 int num_conns = snd_hda_get_num_conns(codec, dig_out);
410
411 if (num_conns == 2)
412 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
413 else if (num_conns == 3)
414 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
415 else
416 return -EINVAL;
417}
418
419static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
420 struct snd_ctl_elem_value *ucontrol)
421{
422 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
423 struct ad198x_spec *spec = codec->spec;
424
425 ucontrol->value.enumerated.item[0] = spec->cur_smux;
426 return 0;
427}
428
429static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
431{
432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433 struct ad198x_spec *spec = codec->spec;
434 unsigned int val = ucontrol->value.enumerated.item[0];
435 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
436 int num_conns = snd_hda_get_num_conns(codec, dig_out);
437
438 if (val >= num_conns)
439 return -EINVAL;
440 if (spec->cur_smux == val)
441 return 0;
442 spec->cur_smux = val;
443 snd_hda_codec_write_cache(codec, dig_out, 0,
444 AC_VERB_SET_CONNECT_SEL, val);
445 return 1;
446}
447
448static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
449 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
450 .name = "IEC958 Playback Source",
451 .info = ad1983_auto_smux_enum_info,
452 .get = ad1983_auto_smux_enum_get,
453 .put = ad1983_auto_smux_enum_put,
454};
455
456static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
457{
458 struct ad198x_spec *spec = codec->spec;
459 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
460 int num_conns;
461
462 if (!dig_out)
463 return 0;
464 num_conns = snd_hda_get_num_conns(codec, dig_out);
465 if (num_conns != 2 && num_conns != 3)
466 return 0;
467 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
468 return -ENOMEM;
469 return 0;
470}
471
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200472static int patch_ad1983(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100473{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200474 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100475 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200476
Takashi Iwai361dab32012-05-09 14:35:27 +0200477 err = alloc_ad_spec(codec);
478 if (err < 0)
479 return err;
480 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200481
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100482 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100483 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100484 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100485 if (err < 0)
486 goto error;
487 err = ad1983_add_spdif_mux_ctl(codec);
488 if (err < 0)
489 goto error;
490 return 0;
491
492 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100493 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100494 return err;
495}
496
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200497
498/*
499 * AD1981 HD specific
500 */
501
Takashi Iwaia928bd22013-01-22 18:18:42 +0100502static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
503 const struct hda_fixup *fix, int action)
504{
505 struct ad198x_spec *spec = codec->spec;
506
507 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
508 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
509 spec->eapd_nid = 0x05;
510 }
511}
512
513/* set the upper-limit for mixer amp to 0dB for avoiding the possible
514 * damage by overloading
515 */
516static void ad1981_fixup_amp_override(struct hda_codec *codec,
517 const struct hda_fixup *fix, int action)
518{
519 if (action == HDA_FIXUP_ACT_PRE_PROBE)
520 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
521 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
522 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
523 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
524 (1 << AC_AMPCAP_MUTE_SHIFT));
525}
526
527enum {
528 AD1981_FIXUP_AMP_OVERRIDE,
529 AD1981_FIXUP_HP_EAPD,
530};
531
532static const struct hda_fixup ad1981_fixups[] = {
533 [AD1981_FIXUP_AMP_OVERRIDE] = {
534 .type = HDA_FIXUP_FUNC,
535 .v.func = ad1981_fixup_amp_override,
536 },
537 [AD1981_FIXUP_HP_EAPD] = {
538 .type = HDA_FIXUP_FUNC,
539 .v.func = ad1981_fixup_hp_eapd,
540 .chained = true,
541 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
542 },
543};
544
545static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
546 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
547 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
548 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
549 /* HP nx6320 (reversed SSID, H/W bug) */
550 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
551 {}
552};
553
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200554static int patch_ad1981(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100555{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200556 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100557 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200558
Takashi Iwai361dab32012-05-09 14:35:27 +0200559 err = alloc_ad_spec(codec);
560 if (err < 0)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200561 return -ENOMEM;
Takashi Iwai361dab32012-05-09 14:35:27 +0200562 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200563
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100564 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100565 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100566 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100567
568 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
569 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
570
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100571 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100572 if (err < 0)
573 goto error;
574 err = ad1983_add_spdif_mux_ctl(codec);
575 if (err < 0)
576 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100577
578 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
579
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100580 return 0;
581
582 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100583 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100584 return err;
585}
586
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200587
588/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100589 * AD1988
590 *
591 * Output pins and routes
592 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100593 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100594 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
595 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
596 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
597 * port-D 0x12 (mute/hp) <- 0x29 <- 04
598 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
599 * port-F 0x16 (mute) <- 0x2a <- 06
600 * port-G 0x24 (mute) <- 0x27 <- 05
601 * port-H 0x25 (mute) <- 0x28 <- 0a
602 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
603 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100604 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
605 * (*) 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 +0100606 *
607 * Input pins and routes
608 *
609 * pin boost mix input # / adc input #
610 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
611 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
612 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
613 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
614 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
615 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
616 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
617 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
618 *
619 *
620 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +0100621 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +0100622 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100623 *
624 * Inputs of Analog Mix (0x20)
625 * 0:Port-B (front mic)
626 * 1:Port-C/G/H (line-in)
627 * 2:Port-A
628 * 3:Port-D (line-in/2)
629 * 4:Port-E/G/H (mic-in)
630 * 5:Port-F (mic2-in)
631 * 6:CD
632 * 7:Beep
633 *
634 * ADC selection
635 * 0:Port-A
636 * 1:Port-B (front mic-in)
637 * 2:Port-C (line-in)
638 * 3:Port-F (mic2-in)
639 * 4:Port-E (mic-in)
640 * 5:CD
641 * 6:Port-G
642 * 7:Port-H
643 * 8:Port-D (line-in/2)
644 * 9:Mix
645 *
646 * Proposed pin assignments by the datasheet
647 *
648 * 6-stack
649 * Port-A front headphone
650 * B front mic-in
651 * C rear line-in
652 * D rear front-out
653 * E rear mic-in
654 * F rear surround
655 * G rear CLFE
656 * H rear side
657 *
658 * 3-stack
659 * Port-A front headphone
660 * B front mic
661 * C rear line-in/surround
662 * D rear front-out
663 * E rear mic-in/CLFE
664 *
665 * laptop
666 * Port-A headphone
667 * B mic-in
668 * C docking station
669 * D internal speaker (with EAPD)
670 * E/F quad mic array
671 */
672
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100673#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100674static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_info *uinfo)
676{
677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
678 struct ad198x_spec *spec = codec->spec;
679 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
680 spec->num_channel_mode);
681}
682
683static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
684 struct snd_ctl_elem_value *ucontrol)
685{
686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
687 struct ad198x_spec *spec = codec->spec;
688 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
689 spec->num_channel_mode, spec->multiout.max_channels);
690}
691
692static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
693 struct snd_ctl_elem_value *ucontrol)
694{
695 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
696 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200697 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
698 spec->num_channel_mode,
699 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +0200700 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +0200701 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200702 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100703}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100704#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100705
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100706static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_info *uinfo)
708{
709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710 static const char * const texts[] = {
711 "PCM", "ADC1", "ADC2", "ADC3",
712 };
713 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
714 if (num_conns > 4)
715 num_conns = 4;
716 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
717}
718
719static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
720 struct snd_ctl_elem_value *ucontrol)
721{
722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723 struct ad198x_spec *spec = codec->spec;
724
725 ucontrol->value.enumerated.item[0] = spec->cur_smux;
726 return 0;
727}
728
729static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_value *ucontrol)
731{
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 struct ad198x_spec *spec = codec->spec;
734 unsigned int val = ucontrol->value.enumerated.item[0];
735 struct nid_path *path;
736 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
737
738 if (val >= num_conns)
739 return -EINVAL;
740 if (spec->cur_smux == val)
741 return 0;
742
743 mutex_lock(&codec->control_mutex);
744 codec->cached_write = 1;
745 path = snd_hda_get_path_from_idx(codec,
746 spec->smux_paths[spec->cur_smux]);
747 if (path)
748 snd_hda_activate_path(codec, path, false, true);
749 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
750 if (path)
751 snd_hda_activate_path(codec, path, true, true);
752 spec->cur_smux = val;
753 codec->cached_write = 0;
754 mutex_unlock(&codec->control_mutex);
755 snd_hda_codec_flush_cache(codec); /* flush the updates */
756 return 1;
757}
758
759static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
761 .name = "IEC958 Playback Source",
762 .info = ad1988_auto_smux_enum_info,
763 .get = ad1988_auto_smux_enum_get,
764 .put = ad1988_auto_smux_enum_put,
765};
766
767static int ad1988_auto_init(struct hda_codec *codec)
768{
769 struct ad198x_spec *spec = codec->spec;
770 int i, err;
771
772 err = snd_hda_gen_init(codec);
773 if (err < 0)
774 return err;
775 if (!spec->gen.autocfg.dig_outs)
776 return 0;
777
778 for (i = 0; i < 4; i++) {
779 struct nid_path *path;
780 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
781 if (path)
782 snd_hda_activate_path(codec, path, path->active, false);
783 }
784
785 return 0;
786}
787
788static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
789{
790 struct ad198x_spec *spec = codec->spec;
791 int i, num_conns;
792 /* we create four static faked paths, since AD codecs have odd
793 * widget connections regarding the SPDIF out source
794 */
795 static struct nid_path fake_paths[4] = {
796 {
797 .depth = 3,
798 .path = { 0x02, 0x1d, 0x1b },
799 .idx = { 0, 0, 0 },
800 .multi = { 0, 0, 0 },
801 },
802 {
803 .depth = 4,
804 .path = { 0x08, 0x0b, 0x1d, 0x1b },
805 .idx = { 0, 0, 1, 0 },
806 .multi = { 0, 1, 0, 0 },
807 },
808 {
809 .depth = 4,
810 .path = { 0x09, 0x0b, 0x1d, 0x1b },
811 .idx = { 0, 1, 1, 0 },
812 .multi = { 0, 1, 0, 0 },
813 },
814 {
815 .depth = 4,
816 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
817 .idx = { 0, 2, 1, 0 },
818 .multi = { 0, 1, 0, 0 },
819 },
820 };
821
822 /* SPDIF source mux appears to be present only on AD1988A */
823 if (!spec->gen.autocfg.dig_outs ||
824 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
825 return 0;
826
827 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
828 if (num_conns != 3 && num_conns != 4)
829 return 0;
830
831 for (i = 0; i < num_conns; i++) {
832 struct nid_path *path = snd_array_new(&spec->gen.paths);
833 if (!path)
834 return -ENOMEM;
835 *path = fake_paths[i];
836 if (!i)
837 path->active = 1;
838 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
839 }
840
841 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
842 return -ENOMEM;
843
844 codec->patch_ops.init = ad1988_auto_init;
845
846 return 0;
847}
848
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100849/*
Takashi Iwaid32410b12005-11-24 16:06:23 +0100850 */
851
Takashi Iwai36ad4532013-07-04 16:34:20 +0200852enum {
853 AD1988_FIXUP_6STACK_DIG,
854};
855
856static const struct hda_fixup ad1988_fixups[] = {
857 [AD1988_FIXUP_6STACK_DIG] = {
858 .type = HDA_FIXUP_PINS,
859 .v.pins = (const struct hda_pintbl[]) {
860 { 0x11, 0x02214130 }, /* front-hp */
861 { 0x12, 0x01014010 }, /* line-out */
862 { 0x14, 0x02a19122 }, /* front-mic */
863 { 0x15, 0x01813021 }, /* line-in */
864 { 0x16, 0x01011012 }, /* line-out */
865 { 0x17, 0x01a19020 }, /* mic */
866 { 0x1b, 0x0145f1f0 }, /* SPDIF */
867 { 0x24, 0x01016011 }, /* line-out */
868 { 0x25, 0x01012013 }, /* line-out */
869 { }
870 }
871 },
872};
873
874static const struct hda_model_fixup ad1988_fixup_models[] = {
875 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
876 {}
877};
878
879static int patch_ad1988(struct hda_codec *codec)
Takashi Iwaid32410b12005-11-24 16:06:23 +0100880{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100881 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100882 int err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100883
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100884 err = alloc_ad_spec(codec);
885 if (err < 0)
886 return err;
887 spec = codec->spec;
888
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100889 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +0100890 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100891 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100892 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai36ad4532013-07-04 16:34:20 +0200893
894 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
895 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
896
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100897 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100898 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100899 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100900 err = ad1988_add_spdif_mux_ctl(codec);
901 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100902 goto error;
Takashi Iwai36ad4532013-07-04 16:34:20 +0200903
904 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
905
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100906 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100907
908 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100909 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100910 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100911}
912
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100913
914/*
Takashi Iwai2bac6472007-05-18 18:21:41 +0200915 * AD1884 / AD1984
916 *
917 * port-B - front line/mic-in
918 * port-E - aux in/out
919 * port-F - aux in/out
920 * port-C - rear line/mic-in
921 * port-D - rear line/hp-out
922 * port-A - front line/hp-out
923 *
924 * AD1984 = AD1884 + two digital mic-ins
925 *
Takashi Iwai5ccc6182013-07-04 15:36:56 +0200926 * AD1883 / AD1884A / AD1984A / AD1984B
927 *
928 * port-B (0x14) - front mic-in
929 * port-E (0x1c) - rear mic-in
930 * port-F (0x16) - CD / ext out
931 * port-C (0x15) - rear line-in
932 * port-D (0x12) - rear line-out
933 * port-A (0x11) - front hp-out
934 *
935 * AD1984A = AD1884A + digital-mic
936 * AD1883 = equivalent with AD1984A
937 * AD1984B = AD1984A + extra SPDIF-out
Takashi Iwai2bac6472007-05-18 18:21:41 +0200938 */
939
Takashi Iwaia928bd22013-01-22 18:18:42 +0100940/* set the upper-limit for mixer amp to 0dB for avoiding the possible
941 * damage by overloading
942 */
943static void ad1884_fixup_amp_override(struct hda_codec *codec,
944 const struct hda_fixup *fix, int action)
945{
946 if (action == HDA_FIXUP_ACT_PRE_PROBE)
947 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
948 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
949 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
950 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
951 (1 << AC_AMPCAP_MUTE_SHIFT));
952}
953
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200954/* toggle GPIO1 according to the mute state */
955static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
956{
957 struct hda_codec *codec = private_data;
958 struct ad198x_spec *spec = codec->spec;
959
960 if (spec->eapd_nid)
961 ad_vmaster_eapd_hook(private_data, enabled);
962 snd_hda_codec_update_cache(codec, 0x01, 0,
963 AC_VERB_SET_GPIO_DATA,
964 enabled ? 0x00 : 0x02);
965}
966
Takashi Iwaia928bd22013-01-22 18:18:42 +0100967static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
968 const struct hda_fixup *fix, int action)
969{
970 struct ad198x_spec *spec = codec->spec;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200971 static const struct hda_verb gpio_init_verbs[] = {
972 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
973 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
974 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
975 {},
976 };
Takashi Iwaia928bd22013-01-22 18:18:42 +0100977
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200978 switch (action) {
979 case HDA_FIXUP_ACT_PRE_PROBE:
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200980 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
Takashi Iwai1cd9b2f2013-12-02 13:19:45 +0100981 spec->gen.own_eapd_ctl = 1;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200982 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200983 break;
984 case HDA_FIXUP_ACT_PROBE:
Takashi Iwaia928bd22013-01-22 18:18:42 +0100985 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
986 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
987 else
988 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200989 break;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100990 }
991}
992
Takashi Iwai1ac32932013-10-26 00:24:14 +0200993static void ad1884_fixup_thinkpad(struct hda_codec *codec,
994 const struct hda_fixup *fix, int action)
995{
996 struct ad198x_spec *spec = codec->spec;
997
Takashi Iwaiafb5a772013-10-26 00:33:58 +0200998 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwai1ac32932013-10-26 00:24:14 +0200999 spec->gen.keep_eapd_on = 1;
Takashi Iwaiafb5a772013-10-26 00:33:58 +02001000 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1001 spec->eapd_nid = 0x12;
1002 }
Takashi Iwai1ac32932013-10-26 00:24:14 +02001003}
1004
Takashi Iwai6a699be2013-07-04 14:45:37 +02001005/* set magic COEFs for dmic */
1006static const struct hda_verb ad1884_dmic_init_verbs[] = {
1007 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1008 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1009 {}
1010};
1011
Takashi Iwaia928bd22013-01-22 18:18:42 +01001012enum {
1013 AD1884_FIXUP_AMP_OVERRIDE,
1014 AD1884_FIXUP_HP_EAPD,
Takashi Iwai6a699be2013-07-04 14:45:37 +02001015 AD1884_FIXUP_DMIC_COEF,
Takashi Iwai1ac32932013-10-26 00:24:14 +02001016 AD1884_FIXUP_THINKPAD,
Takashi Iwaif4046272013-07-04 15:14:17 +02001017 AD1884_FIXUP_HP_TOUCHSMART,
Takashi Iwaia928bd22013-01-22 18:18:42 +01001018};
1019
1020static const struct hda_fixup ad1884_fixups[] = {
1021 [AD1884_FIXUP_AMP_OVERRIDE] = {
1022 .type = HDA_FIXUP_FUNC,
1023 .v.func = ad1884_fixup_amp_override,
1024 },
1025 [AD1884_FIXUP_HP_EAPD] = {
1026 .type = HDA_FIXUP_FUNC,
1027 .v.func = ad1884_fixup_hp_eapd,
1028 .chained = true,
1029 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1030 },
Takashi Iwai6a699be2013-07-04 14:45:37 +02001031 [AD1884_FIXUP_DMIC_COEF] = {
1032 .type = HDA_FIXUP_VERBS,
1033 .v.verbs = ad1884_dmic_init_verbs,
1034 },
Takashi Iwai1ac32932013-10-26 00:24:14 +02001035 [AD1884_FIXUP_THINKPAD] = {
1036 .type = HDA_FIXUP_FUNC,
1037 .v.func = ad1884_fixup_thinkpad,
1038 .chained = true,
1039 .chain_id = AD1884_FIXUP_DMIC_COEF,
1040 },
Takashi Iwaif4046272013-07-04 15:14:17 +02001041 [AD1884_FIXUP_HP_TOUCHSMART] = {
1042 .type = HDA_FIXUP_VERBS,
1043 .v.verbs = ad1884_dmic_init_verbs,
1044 .chained = true,
1045 .chain_id = AD1884_FIXUP_HP_EAPD,
1046 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01001047};
1048
1049static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
Takashi Iwaif4046272013-07-04 15:14:17 +02001050 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001051 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
Takashi Iwai1ac32932013-10-26 00:24:14 +02001052 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001053 {}
1054};
1055
1056
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001057static int patch_ad1884(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001058{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001059 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001060 int err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001061
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001062 err = alloc_ad_spec(codec);
1063 if (err < 0)
1064 return err;
1065 spec = codec->spec;
1066
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001067 spec->gen.mixer_nid = 0x20;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001068 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001069 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01001070
1071 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1072 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1073
Takashi Iwaicbd209f2014-01-13 12:40:07 +01001074 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001075 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001076 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001077 err = ad1983_add_spdif_mux_ctl(codec);
1078 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001079 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001080
1081 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1082
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001083 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001084
1085 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001086 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001087 return err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001088}
1089
Takashi Iwaic5059252008-02-16 09:43:56 +01001090/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001091 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02001092 *
1093 * port-A - front hp-out
1094 * port-B - front mic-in
1095 * port-C - rear line-in, shared surr-out (3stack)
1096 * port-D - rear line-out
1097 * port-E - rear mic-in, shared clfe-out (3stack)
1098 * port-F - rear surr-out (6stack)
1099 * port-G - rear clfe-out (6stack)
1100 */
1101
Takashi Iwaiaa95d612013-07-04 15:16:31 +02001102static int patch_ad1882(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001103{
Takashi Iwai0ac85512007-06-20 15:46:13 +02001104 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001105 int err;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001106
Takashi Iwai361dab32012-05-09 14:35:27 +02001107 err = alloc_ad_spec(codec);
1108 if (err < 0)
1109 return err;
1110 spec = codec->spec;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001111
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001112 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01001113 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001114 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001115 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaicbd209f2014-01-13 12:40:07 +01001116 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001117 if (err < 0)
1118 goto error;
1119 err = ad1988_add_spdif_mux_ctl(codec);
1120 if (err < 0)
1121 goto error;
1122 return 0;
1123
1124 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001125 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001126 return err;
1127}
1128
Takashi Iwai0ac85512007-06-20 15:46:13 +02001129
1130/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 * patch entries
1132 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001133static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001134 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
Takashi Iwai0ac85512007-06-20 15:46:13 +02001135 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001136 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02001137 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001138 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1139 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001140 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1141 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001142 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001144 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02001145 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001146 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02001147 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1148 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 {} /* terminator */
1150};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001151
1152MODULE_ALIAS("snd-hda-codec-id:11d4*");
1153
1154MODULE_LICENSE("GPL");
1155MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1156
1157static struct hda_codec_preset_list analog_list = {
1158 .preset = snd_hda_preset_analog,
1159 .owner = THIS_MODULE,
1160};
1161
1162static int __init patch_analog_init(void)
1163{
1164 return snd_hda_add_codec_preset(&analog_list);
1165}
1166
1167static void __exit patch_analog_exit(void)
1168{
1169 snd_hda_delete_codec_preset(&analog_list);
1170}
1171
1172module_init(patch_analog_init)
1173module_exit(patch_analog_exit)