blob: 8ed0bcc0138637e69e19ff7056b99a86fac09fa6 [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
Takashi Iwai4528eb12014-02-04 07:39:06 +0100247/* Toshiba Satellite L40 implements EAPD in a standard way unlike others */
248static void ad1986a_fixup_eapd(struct hda_codec *codec,
249 const struct hda_fixup *fix, int action)
250{
251 struct ad198x_spec *spec = codec->spec;
252
253 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
254 codec->inv_eapd = 0;
255 spec->gen.keep_eapd_on = 1;
256 spec->eapd_nid = 0x1b;
257 }
258}
259
Takashi Iwaia928bd22013-01-22 18:18:42 +0100260enum {
261 AD1986A_FIXUP_INV_JACK_DETECT,
Takashi Iwaie0b27162013-07-04 16:50:46 +0200262 AD1986A_FIXUP_ULTRA,
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200263 AD1986A_FIXUP_SAMSUNG,
Takashi Iwai632408a2013-07-05 14:14:14 +0200264 AD1986A_FIXUP_3STACK,
265 AD1986A_FIXUP_LAPTOP,
266 AD1986A_FIXUP_LAPTOP_IMIC,
Takashi Iwai4528eb12014-02-04 07:39:06 +0100267 AD1986A_FIXUP_EAPD,
Takashi Iwaia928bd22013-01-22 18:18:42 +0100268};
269
270static const struct hda_fixup ad1986a_fixups[] = {
271 [AD1986A_FIXUP_INV_JACK_DETECT] = {
272 .type = HDA_FIXUP_FUNC,
273 .v.func = ad_fixup_inv_jack_detect,
274 },
Takashi Iwaie0b27162013-07-04 16:50:46 +0200275 [AD1986A_FIXUP_ULTRA] = {
276 .type = HDA_FIXUP_PINS,
277 .v.pins = (const struct hda_pintbl[]) {
278 { 0x1b, 0x90170110 }, /* speaker */
279 { 0x1d, 0x90a7013e }, /* int mic */
280 {}
281 },
282 },
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200283 [AD1986A_FIXUP_SAMSUNG] = {
284 .type = HDA_FIXUP_PINS,
285 .v.pins = (const struct hda_pintbl[]) {
286 { 0x1b, 0x90170110 }, /* speaker */
287 { 0x1d, 0x90a7013e }, /* int mic */
288 { 0x20, 0x411111f0 }, /* N/A */
289 { 0x24, 0x411111f0 }, /* N/A */
290 {}
291 },
292 },
Takashi Iwai632408a2013-07-05 14:14:14 +0200293 [AD1986A_FIXUP_3STACK] = {
294 .type = HDA_FIXUP_PINS,
295 .v.pins = (const struct hda_pintbl[]) {
296 { 0x1a, 0x02214021 }, /* headphone */
297 { 0x1b, 0x01014011 }, /* front */
Takashi Iwaied0e0d02014-01-07 17:48:11 +0100298 { 0x1c, 0x01813030 }, /* line-in */
299 { 0x1d, 0x01a19020 }, /* rear mic */
Takashi Iwai632408a2013-07-05 14:14:14 +0200300 { 0x1e, 0x411111f0 }, /* N/A */
301 { 0x1f, 0x02a190f0 }, /* mic */
Takashi Iwaied0e0d02014-01-07 17:48:11 +0100302 { 0x20, 0x411111f0 }, /* N/A */
Takashi Iwai632408a2013-07-05 14:14:14 +0200303 {}
304 },
305 },
306 [AD1986A_FIXUP_LAPTOP] = {
307 .type = HDA_FIXUP_PINS,
308 .v.pins = (const struct hda_pintbl[]) {
309 { 0x1a, 0x02214021 }, /* headphone */
310 { 0x1b, 0x90170110 }, /* speaker */
311 { 0x1c, 0x411111f0 }, /* N/A */
312 { 0x1d, 0x411111f0 }, /* N/A */
313 { 0x1e, 0x411111f0 }, /* N/A */
314 { 0x1f, 0x02a191f0 }, /* mic */
315 { 0x20, 0x411111f0 }, /* N/A */
316 {}
317 },
318 },
319 [AD1986A_FIXUP_LAPTOP_IMIC] = {
320 .type = HDA_FIXUP_PINS,
321 .v.pins = (const struct hda_pintbl[]) {
322 { 0x1d, 0x90a7013e }, /* int mic */
323 {}
324 },
325 .chained_before = 1,
326 .chain_id = AD1986A_FIXUP_LAPTOP,
327 },
Takashi Iwai4528eb12014-02-04 07:39:06 +0100328 [AD1986A_FIXUP_EAPD] = {
329 .type = HDA_FIXUP_FUNC,
330 .v.func = ad1986a_fixup_eapd,
331 },
Takashi Iwaia928bd22013-01-22 18:18:42 +0100332};
333
334static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
Takashi Iwai632408a2013-07-05 14:14:14 +0200335 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
336 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
337 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
338 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
Takashi Iwai4528eb12014-02-04 07:39:06 +0100339 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
Takashi Iwai632408a2013-07-05 14:14:14 +0200340 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200341 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
Takashi Iwaie0b27162013-07-04 16:50:46 +0200342 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
Takashi Iwaia928bd22013-01-22 18:18:42 +0100343 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
Takashi Iwai632408a2013-07-05 14:14:14 +0200344 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
345 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
346 {}
347};
348
349static const struct hda_model_fixup ad1986a_fixup_models[] = {
350 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
351 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
352 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
353 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
Takashi Iwaia928bd22013-01-22 18:18:42 +0100354 {}
355};
356
357/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100358 */
Takashi Iwai632408a2013-07-05 14:14:14 +0200359static int patch_ad1986a(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100360{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100361 int err;
362 struct ad198x_spec *spec;
Takashi Iwai36907392013-12-10 17:29:26 +0100363 static hda_nid_t preferred_pairs[] = {
364 0x1a, 0x03,
365 0x1b, 0x03,
366 0x1c, 0x04,
367 0x1d, 0x05,
368 0x1e, 0x03,
369 0
370 };
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100371
372 err = alloc_ad_spec(codec);
373 if (err < 0)
374 return err;
375 spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100376
377 /* AD1986A has the inverted EAPD implementation */
378 codec->inv_eapd = 1;
379
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100380 spec->gen.mixer_nid = 0x07;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100381 spec->gen.beep_nid = 0x19;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100382 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
383
384 /* AD1986A has a hardware problem that it can't share a stream
385 * with multiple output pins. The copy of front to surrounds
386 * causes noisy or silent outputs at a certain timing, e.g.
387 * changing the volume.
388 * So, let's disable the shared stream.
389 */
390 spec->gen.multiout.no_share_stream = 1;
Takashi Iwai36907392013-12-10 17:29:26 +0100391 /* give fixed DAC/pin pairs */
392 spec->gen.preferred_dacs = preferred_pairs;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100393
Takashi Iwaib3bd4fc2013-12-02 15:04:03 +0100394 /* AD1986A can't manage the dynamic pin on/off smoothly */
395 spec->gen.auto_mute_via_amp = 1;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100396
Takashi Iwai632408a2013-07-05 14:14:14 +0200397 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
398 ad1986a_fixups);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100399 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
400
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100401 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100402 if (err < 0) {
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100403 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100404 return err;
405 }
406
Takashi Iwaia928bd22013-01-22 18:18:42 +0100407 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
408
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100409 return 0;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100410}
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200414 * AD1983 specific
415 */
416
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100417/*
418 * SPDIF mux control for AD1983 auto-parser
419 */
420static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_info *uinfo)
422{
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct ad198x_spec *spec = codec->spec;
425 static const char * const texts2[] = { "PCM", "ADC" };
426 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
427 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
428 int num_conns = snd_hda_get_num_conns(codec, dig_out);
429
430 if (num_conns == 2)
431 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
432 else if (num_conns == 3)
433 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
434 else
435 return -EINVAL;
436}
437
438static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
439 struct snd_ctl_elem_value *ucontrol)
440{
441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
442 struct ad198x_spec *spec = codec->spec;
443
444 ucontrol->value.enumerated.item[0] = spec->cur_smux;
445 return 0;
446}
447
448static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
449 struct snd_ctl_elem_value *ucontrol)
450{
451 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
452 struct ad198x_spec *spec = codec->spec;
453 unsigned int val = ucontrol->value.enumerated.item[0];
454 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
455 int num_conns = snd_hda_get_num_conns(codec, dig_out);
456
457 if (val >= num_conns)
458 return -EINVAL;
459 if (spec->cur_smux == val)
460 return 0;
461 spec->cur_smux = val;
462 snd_hda_codec_write_cache(codec, dig_out, 0,
463 AC_VERB_SET_CONNECT_SEL, val);
464 return 1;
465}
466
467static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "IEC958 Playback Source",
470 .info = ad1983_auto_smux_enum_info,
471 .get = ad1983_auto_smux_enum_get,
472 .put = ad1983_auto_smux_enum_put,
473};
474
475static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
476{
477 struct ad198x_spec *spec = codec->spec;
478 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
479 int num_conns;
480
481 if (!dig_out)
482 return 0;
483 num_conns = snd_hda_get_num_conns(codec, dig_out);
484 if (num_conns != 2 && num_conns != 3)
485 return 0;
486 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
487 return -ENOMEM;
488 return 0;
489}
490
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200491static int patch_ad1983(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100492{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200493 struct ad198x_spec *spec;
Takashi Iwai276ab332014-02-05 08:49:41 +0100494 static hda_nid_t conn_0c[] = { 0x08 };
495 static hda_nid_t conn_0d[] = { 0x09 };
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100496 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200497
Takashi Iwai361dab32012-05-09 14:35:27 +0200498 err = alloc_ad_spec(codec);
499 if (err < 0)
500 return err;
501 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200502
Takashi Iwaic7579fe2014-02-05 07:28:10 +0100503 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100504 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100505 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai276ab332014-02-05 08:49:41 +0100506
507 /* limit the loopback routes not to confuse the parser */
508 snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c);
509 snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d);
510
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100511 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100512 if (err < 0)
513 goto error;
514 err = ad1983_add_spdif_mux_ctl(codec);
515 if (err < 0)
516 goto error;
517 return 0;
518
519 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100520 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100521 return err;
522}
523
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200524
525/*
526 * AD1981 HD specific
527 */
528
Takashi Iwaia928bd22013-01-22 18:18:42 +0100529static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
530 const struct hda_fixup *fix, int action)
531{
532 struct ad198x_spec *spec = codec->spec;
533
534 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
535 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
536 spec->eapd_nid = 0x05;
537 }
538}
539
540/* set the upper-limit for mixer amp to 0dB for avoiding the possible
541 * damage by overloading
542 */
543static void ad1981_fixup_amp_override(struct hda_codec *codec,
544 const struct hda_fixup *fix, int action)
545{
546 if (action == HDA_FIXUP_ACT_PRE_PROBE)
547 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
548 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
549 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
550 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
551 (1 << AC_AMPCAP_MUTE_SHIFT));
552}
553
554enum {
555 AD1981_FIXUP_AMP_OVERRIDE,
556 AD1981_FIXUP_HP_EAPD,
557};
558
559static const struct hda_fixup ad1981_fixups[] = {
560 [AD1981_FIXUP_AMP_OVERRIDE] = {
561 .type = HDA_FIXUP_FUNC,
562 .v.func = ad1981_fixup_amp_override,
563 },
564 [AD1981_FIXUP_HP_EAPD] = {
565 .type = HDA_FIXUP_FUNC,
566 .v.func = ad1981_fixup_hp_eapd,
567 .chained = true,
568 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
569 },
570};
571
572static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
573 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
574 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
575 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
576 /* HP nx6320 (reversed SSID, H/W bug) */
577 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
578 {}
579};
580
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200581static int patch_ad1981(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100582{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200583 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100584 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200585
Takashi Iwai361dab32012-05-09 14:35:27 +0200586 err = alloc_ad_spec(codec);
587 if (err < 0)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200588 return -ENOMEM;
Takashi Iwai361dab32012-05-09 14:35:27 +0200589 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200590
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100591 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100592 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100593 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100594
595 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
596 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
597
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100598 err = ad198x_parse_auto_config(codec, false);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100599 if (err < 0)
600 goto error;
601 err = ad1983_add_spdif_mux_ctl(codec);
602 if (err < 0)
603 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100604
605 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
606
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100607 return 0;
608
609 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100610 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100611 return err;
612}
613
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200614
615/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100616 * AD1988
617 *
618 * Output pins and routes
619 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100620 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100621 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
622 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
623 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
624 * port-D 0x12 (mute/hp) <- 0x29 <- 04
625 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
626 * port-F 0x16 (mute) <- 0x2a <- 06
627 * port-G 0x24 (mute) <- 0x27 <- 05
628 * port-H 0x25 (mute) <- 0x28 <- 0a
629 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
630 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100631 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
632 * (*) 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 +0100633 *
634 * Input pins and routes
635 *
636 * pin boost mix input # / adc input #
637 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
638 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
639 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
640 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
641 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
642 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
643 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
644 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
645 *
646 *
647 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +0100648 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +0100649 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100650 *
651 * Inputs of Analog Mix (0x20)
652 * 0:Port-B (front mic)
653 * 1:Port-C/G/H (line-in)
654 * 2:Port-A
655 * 3:Port-D (line-in/2)
656 * 4:Port-E/G/H (mic-in)
657 * 5:Port-F (mic2-in)
658 * 6:CD
659 * 7:Beep
660 *
661 * ADC selection
662 * 0:Port-A
663 * 1:Port-B (front mic-in)
664 * 2:Port-C (line-in)
665 * 3:Port-F (mic2-in)
666 * 4:Port-E (mic-in)
667 * 5:CD
668 * 6:Port-G
669 * 7:Port-H
670 * 8:Port-D (line-in/2)
671 * 9:Mix
672 *
673 * Proposed pin assignments by the datasheet
674 *
675 * 6-stack
676 * Port-A front headphone
677 * B front mic-in
678 * C rear line-in
679 * D rear front-out
680 * E rear mic-in
681 * F rear surround
682 * G rear CLFE
683 * H rear side
684 *
685 * 3-stack
686 * Port-A front headphone
687 * B front mic
688 * C rear line-in/surround
689 * D rear front-out
690 * E rear mic-in/CLFE
691 *
692 * laptop
693 * Port-A headphone
694 * B mic-in
695 * C docking station
696 * D internal speaker (with EAPD)
697 * E/F quad mic array
698 */
699
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100700#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100701static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_info *uinfo)
703{
704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
705 struct ad198x_spec *spec = codec->spec;
706 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
707 spec->num_channel_mode);
708}
709
710static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
712{
713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714 struct ad198x_spec *spec = codec->spec;
715 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
716 spec->num_channel_mode, spec->multiout.max_channels);
717}
718
719static int ad198x_ch_mode_put(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;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200724 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
725 spec->num_channel_mode,
726 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +0200727 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +0200728 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200729 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100730}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100731#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100732
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100733static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
734 struct snd_ctl_elem_info *uinfo)
735{
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 static const char * const texts[] = {
738 "PCM", "ADC1", "ADC2", "ADC3",
739 };
740 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
741 if (num_conns > 4)
742 num_conns = 4;
743 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
744}
745
746static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
747 struct snd_ctl_elem_value *ucontrol)
748{
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct ad198x_spec *spec = codec->spec;
751
752 ucontrol->value.enumerated.item[0] = spec->cur_smux;
753 return 0;
754}
755
756static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
757 struct snd_ctl_elem_value *ucontrol)
758{
759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct ad198x_spec *spec = codec->spec;
761 unsigned int val = ucontrol->value.enumerated.item[0];
762 struct nid_path *path;
763 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
764
765 if (val >= num_conns)
766 return -EINVAL;
767 if (spec->cur_smux == val)
768 return 0;
769
770 mutex_lock(&codec->control_mutex);
771 codec->cached_write = 1;
772 path = snd_hda_get_path_from_idx(codec,
773 spec->smux_paths[spec->cur_smux]);
774 if (path)
775 snd_hda_activate_path(codec, path, false, true);
776 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
777 if (path)
778 snd_hda_activate_path(codec, path, true, true);
779 spec->cur_smux = val;
780 codec->cached_write = 0;
781 mutex_unlock(&codec->control_mutex);
782 snd_hda_codec_flush_cache(codec); /* flush the updates */
783 return 1;
784}
785
786static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
788 .name = "IEC958 Playback Source",
789 .info = ad1988_auto_smux_enum_info,
790 .get = ad1988_auto_smux_enum_get,
791 .put = ad1988_auto_smux_enum_put,
792};
793
794static int ad1988_auto_init(struct hda_codec *codec)
795{
796 struct ad198x_spec *spec = codec->spec;
797 int i, err;
798
799 err = snd_hda_gen_init(codec);
800 if (err < 0)
801 return err;
802 if (!spec->gen.autocfg.dig_outs)
803 return 0;
804
805 for (i = 0; i < 4; i++) {
806 struct nid_path *path;
807 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
808 if (path)
809 snd_hda_activate_path(codec, path, path->active, false);
810 }
811
812 return 0;
813}
814
815static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
816{
817 struct ad198x_spec *spec = codec->spec;
818 int i, num_conns;
819 /* we create four static faked paths, since AD codecs have odd
820 * widget connections regarding the SPDIF out source
821 */
822 static struct nid_path fake_paths[4] = {
823 {
824 .depth = 3,
825 .path = { 0x02, 0x1d, 0x1b },
826 .idx = { 0, 0, 0 },
827 .multi = { 0, 0, 0 },
828 },
829 {
830 .depth = 4,
831 .path = { 0x08, 0x0b, 0x1d, 0x1b },
832 .idx = { 0, 0, 1, 0 },
833 .multi = { 0, 1, 0, 0 },
834 },
835 {
836 .depth = 4,
837 .path = { 0x09, 0x0b, 0x1d, 0x1b },
838 .idx = { 0, 1, 1, 0 },
839 .multi = { 0, 1, 0, 0 },
840 },
841 {
842 .depth = 4,
843 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
844 .idx = { 0, 2, 1, 0 },
845 .multi = { 0, 1, 0, 0 },
846 },
847 };
848
849 /* SPDIF source mux appears to be present only on AD1988A */
850 if (!spec->gen.autocfg.dig_outs ||
851 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
852 return 0;
853
854 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
855 if (num_conns != 3 && num_conns != 4)
856 return 0;
857
858 for (i = 0; i < num_conns; i++) {
859 struct nid_path *path = snd_array_new(&spec->gen.paths);
860 if (!path)
861 return -ENOMEM;
862 *path = fake_paths[i];
863 if (!i)
864 path->active = 1;
865 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
866 }
867
868 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
869 return -ENOMEM;
870
871 codec->patch_ops.init = ad1988_auto_init;
872
873 return 0;
874}
875
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100876/*
Takashi Iwaid32410b12005-11-24 16:06:23 +0100877 */
878
Takashi Iwai36ad4532013-07-04 16:34:20 +0200879enum {
880 AD1988_FIXUP_6STACK_DIG,
881};
882
883static const struct hda_fixup ad1988_fixups[] = {
884 [AD1988_FIXUP_6STACK_DIG] = {
885 .type = HDA_FIXUP_PINS,
886 .v.pins = (const struct hda_pintbl[]) {
887 { 0x11, 0x02214130 }, /* front-hp */
888 { 0x12, 0x01014010 }, /* line-out */
889 { 0x14, 0x02a19122 }, /* front-mic */
890 { 0x15, 0x01813021 }, /* line-in */
891 { 0x16, 0x01011012 }, /* line-out */
892 { 0x17, 0x01a19020 }, /* mic */
893 { 0x1b, 0x0145f1f0 }, /* SPDIF */
894 { 0x24, 0x01016011 }, /* line-out */
895 { 0x25, 0x01012013 }, /* line-out */
896 { }
897 }
898 },
899};
900
901static const struct hda_model_fixup ad1988_fixup_models[] = {
902 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
903 {}
904};
905
906static int patch_ad1988(struct hda_codec *codec)
Takashi Iwaid32410b12005-11-24 16:06:23 +0100907{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100908 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100909 int err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100910
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100911 err = alloc_ad_spec(codec);
912 if (err < 0)
913 return err;
914 spec = codec->spec;
915
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100916 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +0100917 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100918 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100919 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai36ad4532013-07-04 16:34:20 +0200920
921 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
922 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
923
Takashi Iwaicbd209f2014-01-13 12:40:07 +0100924 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100925 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100926 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100927 err = ad1988_add_spdif_mux_ctl(codec);
928 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100929 goto error;
Takashi Iwai36ad4532013-07-04 16:34:20 +0200930
931 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
932
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100933 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100934
935 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100936 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100937 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100938}
939
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100940
941/*
Takashi Iwai2bac6472007-05-18 18:21:41 +0200942 * AD1884 / AD1984
943 *
944 * port-B - front line/mic-in
945 * port-E - aux in/out
946 * port-F - aux in/out
947 * port-C - rear line/mic-in
948 * port-D - rear line/hp-out
949 * port-A - front line/hp-out
950 *
951 * AD1984 = AD1884 + two digital mic-ins
952 *
Takashi Iwai5ccc6182013-07-04 15:36:56 +0200953 * AD1883 / AD1884A / AD1984A / AD1984B
954 *
955 * port-B (0x14) - front mic-in
956 * port-E (0x1c) - rear mic-in
957 * port-F (0x16) - CD / ext out
958 * port-C (0x15) - rear line-in
959 * port-D (0x12) - rear line-out
960 * port-A (0x11) - front hp-out
961 *
962 * AD1984A = AD1884A + digital-mic
963 * AD1883 = equivalent with AD1984A
964 * AD1984B = AD1984A + extra SPDIF-out
Takashi Iwai2bac6472007-05-18 18:21:41 +0200965 */
966
Takashi Iwaia928bd22013-01-22 18:18:42 +0100967/* set the upper-limit for mixer amp to 0dB for avoiding the possible
968 * damage by overloading
969 */
970static void ad1884_fixup_amp_override(struct hda_codec *codec,
971 const struct hda_fixup *fix, int action)
972{
973 if (action == HDA_FIXUP_ACT_PRE_PROBE)
974 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
975 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
976 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
977 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
978 (1 << AC_AMPCAP_MUTE_SHIFT));
979}
980
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200981/* toggle GPIO1 according to the mute state */
982static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
983{
984 struct hda_codec *codec = private_data;
985 struct ad198x_spec *spec = codec->spec;
986
987 if (spec->eapd_nid)
988 ad_vmaster_eapd_hook(private_data, enabled);
989 snd_hda_codec_update_cache(codec, 0x01, 0,
990 AC_VERB_SET_GPIO_DATA,
991 enabled ? 0x00 : 0x02);
992}
993
Takashi Iwaia928bd22013-01-22 18:18:42 +0100994static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
995 const struct hda_fixup *fix, int action)
996{
997 struct ad198x_spec *spec = codec->spec;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200998 static const struct hda_verb gpio_init_verbs[] = {
999 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
1000 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
1001 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
1002 {},
1003 };
Takashi Iwaia928bd22013-01-22 18:18:42 +01001004
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02001005 switch (action) {
1006 case HDA_FIXUP_ACT_PRE_PROBE:
Takashi Iwai1a39b5e2013-07-04 14:32:16 +02001007 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
Takashi Iwai1cd9b2f2013-12-02 13:19:45 +01001008 spec->gen.own_eapd_ctl = 1;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +02001009 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02001010 break;
1011 case HDA_FIXUP_ACT_PROBE:
Takashi Iwaia928bd22013-01-22 18:18:42 +01001012 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1013 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1014 else
1015 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
Takashi Iwai8f0b3b72013-07-04 12:54:22 +02001016 break;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001017 }
1018}
1019
Takashi Iwai1ac32932013-10-26 00:24:14 +02001020static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1021 const struct hda_fixup *fix, int action)
1022{
1023 struct ad198x_spec *spec = codec->spec;
1024
Takashi Iwaiafb5a772013-10-26 00:33:58 +02001025 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwai1ac32932013-10-26 00:24:14 +02001026 spec->gen.keep_eapd_on = 1;
Takashi Iwaiafb5a772013-10-26 00:33:58 +02001027 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1028 spec->eapd_nid = 0x12;
Takashi Iwaif3e9b592014-03-05 12:00:29 +01001029 /* Analog PC Beeper - allow firmware/ACPI beeps */
1030 spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT);
1031 spec->gen.beep_nid = 0; /* no digital beep */
Takashi Iwaiafb5a772013-10-26 00:33:58 +02001032 }
Takashi Iwai1ac32932013-10-26 00:24:14 +02001033}
1034
Takashi Iwai6a699be2013-07-04 14:45:37 +02001035/* set magic COEFs for dmic */
1036static const struct hda_verb ad1884_dmic_init_verbs[] = {
1037 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1038 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1039 {}
1040};
1041
Takashi Iwaia928bd22013-01-22 18:18:42 +01001042enum {
1043 AD1884_FIXUP_AMP_OVERRIDE,
1044 AD1884_FIXUP_HP_EAPD,
Takashi Iwai6a699be2013-07-04 14:45:37 +02001045 AD1884_FIXUP_DMIC_COEF,
Takashi Iwai1ac32932013-10-26 00:24:14 +02001046 AD1884_FIXUP_THINKPAD,
Takashi Iwaif4046272013-07-04 15:14:17 +02001047 AD1884_FIXUP_HP_TOUCHSMART,
Takashi Iwaia928bd22013-01-22 18:18:42 +01001048};
1049
1050static const struct hda_fixup ad1884_fixups[] = {
1051 [AD1884_FIXUP_AMP_OVERRIDE] = {
1052 .type = HDA_FIXUP_FUNC,
1053 .v.func = ad1884_fixup_amp_override,
1054 },
1055 [AD1884_FIXUP_HP_EAPD] = {
1056 .type = HDA_FIXUP_FUNC,
1057 .v.func = ad1884_fixup_hp_eapd,
1058 .chained = true,
1059 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1060 },
Takashi Iwai6a699be2013-07-04 14:45:37 +02001061 [AD1884_FIXUP_DMIC_COEF] = {
1062 .type = HDA_FIXUP_VERBS,
1063 .v.verbs = ad1884_dmic_init_verbs,
1064 },
Takashi Iwai1ac32932013-10-26 00:24:14 +02001065 [AD1884_FIXUP_THINKPAD] = {
1066 .type = HDA_FIXUP_FUNC,
1067 .v.func = ad1884_fixup_thinkpad,
1068 .chained = true,
1069 .chain_id = AD1884_FIXUP_DMIC_COEF,
1070 },
Takashi Iwaif4046272013-07-04 15:14:17 +02001071 [AD1884_FIXUP_HP_TOUCHSMART] = {
1072 .type = HDA_FIXUP_VERBS,
1073 .v.verbs = ad1884_dmic_init_verbs,
1074 .chained = true,
1075 .chain_id = AD1884_FIXUP_HP_EAPD,
1076 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01001077};
1078
1079static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
Takashi Iwaif4046272013-07-04 15:14:17 +02001080 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001081 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
Takashi Iwai1ac32932013-10-26 00:24:14 +02001082 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001083 {}
1084};
1085
1086
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001087static int patch_ad1884(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001088{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001089 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001090 int err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001091
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001092 err = alloc_ad_spec(codec);
1093 if (err < 0)
1094 return err;
1095 spec = codec->spec;
1096
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001097 spec->gen.mixer_nid = 0x20;
Takashi Iwaic5eda4c2014-03-05 11:52:24 +01001098 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001099 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001100 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01001101
1102 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1103 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1104
Takashi Iwaicbd209f2014-01-13 12:40:07 +01001105 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001106 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001107 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001108 err = ad1983_add_spdif_mux_ctl(codec);
1109 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001110 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001111
1112 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1113
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001114 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001115
1116 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001117 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001118 return err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001119}
1120
Takashi Iwaic5059252008-02-16 09:43:56 +01001121/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001122 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02001123 *
1124 * port-A - front hp-out
1125 * port-B - front mic-in
1126 * port-C - rear line-in, shared surr-out (3stack)
1127 * port-D - rear line-out
1128 * port-E - rear mic-in, shared clfe-out (3stack)
1129 * port-F - rear surr-out (6stack)
1130 * port-G - rear clfe-out (6stack)
1131 */
1132
Takashi Iwaiaa95d612013-07-04 15:16:31 +02001133static int patch_ad1882(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001134{
Takashi Iwai0ac85512007-06-20 15:46:13 +02001135 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001136 int err;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001137
Takashi Iwai361dab32012-05-09 14:35:27 +02001138 err = alloc_ad_spec(codec);
1139 if (err < 0)
1140 return err;
1141 spec = codec->spec;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001142
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001143 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01001144 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001145 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001146 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaicbd209f2014-01-13 12:40:07 +01001147 err = ad198x_parse_auto_config(codec, true);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001148 if (err < 0)
1149 goto error;
1150 err = ad1988_add_spdif_mux_ctl(codec);
1151 if (err < 0)
1152 goto error;
1153 return 0;
1154
1155 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001156 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001157 return err;
1158}
1159
Takashi Iwai0ac85512007-06-20 15:46:13 +02001160
1161/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 * patch entries
1163 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001164static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001165 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
Takashi Iwai0ac85512007-06-20 15:46:13 +02001166 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001167 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02001168 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001169 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1170 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001171 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1172 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001173 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001175 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02001176 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001177 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02001178 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1179 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 {} /* terminator */
1181};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001182
1183MODULE_ALIAS("snd-hda-codec-id:11d4*");
1184
1185MODULE_LICENSE("GPL");
1186MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1187
1188static struct hda_codec_preset_list analog_list = {
1189 .preset = snd_hda_preset_analog,
1190 .owner = THIS_MODULE,
1191};
1192
1193static int __init patch_analog_init(void)
1194{
1195 return snd_hda_add_codec_preset(&analog_list);
1196}
1197
1198static void __exit patch_analog_exit(void)
1199{
1200 snd_hda_delete_codec_preset(&analog_list);
1201}
1202
1203module_init(patch_analog_init)
1204module_exit(patch_analog_exit)