blob: 699262a3e07abcd9558bb538de0916d96bc63bcd [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
188static int ad198x_parse_auto_config(struct hda_codec *codec)
189{
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
198 spec->gen.indep_hp = 1;
199
200 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
201 if (err < 0)
202 return err;
203 err = snd_hda_gen_parse_auto_config(codec, cfg);
204 if (err < 0)
205 return err;
206
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100207 codec->patch_ops = ad198x_auto_patch_ops;
208
209 return 0;
210}
211
212/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200213 * AD1986A specific
214 */
215
Takashi Iwai361dab32012-05-09 14:35:27 +0200216static int alloc_ad_spec(struct hda_codec *codec)
217{
218 struct ad198x_spec *spec;
219
220 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
221 if (!spec)
222 return -ENOMEM;
223 codec->spec = spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100224 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +0200225 return 0;
226}
227
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100228/*
Takashi Iwaia928bd22013-01-22 18:18:42 +0100229 * AD1986A fixup codes
230 */
231
232/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
233static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
234 const struct hda_fixup *fix, int action)
235{
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100236 struct ad198x_spec *spec = codec->spec;
237
238 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaia928bd22013-01-22 18:18:42 +0100239 codec->inv_jack_detect = 1;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100240 spec->gen.keep_eapd_on = 1;
Takashi Iwaif710a9f2013-11-13 09:42:56 +0100241 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
242 spec->eapd_nid = 0x1b;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100243 }
Takashi Iwaia928bd22013-01-22 18:18:42 +0100244}
245
246enum {
247 AD1986A_FIXUP_INV_JACK_DETECT,
Takashi Iwaie0b27162013-07-04 16:50:46 +0200248 AD1986A_FIXUP_ULTRA,
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200249 AD1986A_FIXUP_SAMSUNG,
Takashi Iwai632408a2013-07-05 14:14:14 +0200250 AD1986A_FIXUP_3STACK,
251 AD1986A_FIXUP_LAPTOP,
252 AD1986A_FIXUP_LAPTOP_IMIC,
Takashi Iwaia928bd22013-01-22 18:18:42 +0100253};
254
255static const struct hda_fixup ad1986a_fixups[] = {
256 [AD1986A_FIXUP_INV_JACK_DETECT] = {
257 .type = HDA_FIXUP_FUNC,
258 .v.func = ad_fixup_inv_jack_detect,
259 },
Takashi Iwaie0b27162013-07-04 16:50:46 +0200260 [AD1986A_FIXUP_ULTRA] = {
261 .type = HDA_FIXUP_PINS,
262 .v.pins = (const struct hda_pintbl[]) {
263 { 0x1b, 0x90170110 }, /* speaker */
264 { 0x1d, 0x90a7013e }, /* int mic */
265 {}
266 },
267 },
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200268 [AD1986A_FIXUP_SAMSUNG] = {
269 .type = HDA_FIXUP_PINS,
270 .v.pins = (const struct hda_pintbl[]) {
271 { 0x1b, 0x90170110 }, /* speaker */
272 { 0x1d, 0x90a7013e }, /* int mic */
273 { 0x20, 0x411111f0 }, /* N/A */
274 { 0x24, 0x411111f0 }, /* N/A */
275 {}
276 },
277 },
Takashi Iwai632408a2013-07-05 14:14:14 +0200278 [AD1986A_FIXUP_3STACK] = {
279 .type = HDA_FIXUP_PINS,
280 .v.pins = (const struct hda_pintbl[]) {
281 { 0x1a, 0x02214021 }, /* headphone */
282 { 0x1b, 0x01014011 }, /* front */
283 { 0x1c, 0x01013012 }, /* surround */
284 { 0x1d, 0x01019015 }, /* clfe */
285 { 0x1e, 0x411111f0 }, /* N/A */
286 { 0x1f, 0x02a190f0 }, /* mic */
287 { 0x20, 0x018130f0 }, /* line-in */
288 {}
289 },
290 },
291 [AD1986A_FIXUP_LAPTOP] = {
292 .type = HDA_FIXUP_PINS,
293 .v.pins = (const struct hda_pintbl[]) {
294 { 0x1a, 0x02214021 }, /* headphone */
295 { 0x1b, 0x90170110 }, /* speaker */
296 { 0x1c, 0x411111f0 }, /* N/A */
297 { 0x1d, 0x411111f0 }, /* N/A */
298 { 0x1e, 0x411111f0 }, /* N/A */
299 { 0x1f, 0x02a191f0 }, /* mic */
300 { 0x20, 0x411111f0 }, /* N/A */
301 {}
302 },
303 },
304 [AD1986A_FIXUP_LAPTOP_IMIC] = {
305 .type = HDA_FIXUP_PINS,
306 .v.pins = (const struct hda_pintbl[]) {
307 { 0x1d, 0x90a7013e }, /* int mic */
308 {}
309 },
310 .chained_before = 1,
311 .chain_id = AD1986A_FIXUP_LAPTOP,
312 },
Takashi Iwaia928bd22013-01-22 18:18:42 +0100313};
314
315static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
Takashi Iwai632408a2013-07-05 14:14:14 +0200316 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
317 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
318 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
319 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
320 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200321 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
Takashi Iwaie0b27162013-07-04 16:50:46 +0200322 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
Takashi Iwaia928bd22013-01-22 18:18:42 +0100323 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
Takashi Iwai632408a2013-07-05 14:14:14 +0200324 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
325 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
326 {}
327};
328
329static const struct hda_model_fixup ad1986a_fixup_models[] = {
330 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
331 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
332 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
333 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
Takashi Iwaia928bd22013-01-22 18:18:42 +0100334 {}
335};
336
337/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100338 */
Takashi Iwai632408a2013-07-05 14:14:14 +0200339static int patch_ad1986a(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100340{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100341 int err;
342 struct ad198x_spec *spec;
Takashi Iwai36907392013-12-10 17:29:26 +0100343 static hda_nid_t preferred_pairs[] = {
344 0x1a, 0x03,
345 0x1b, 0x03,
346 0x1c, 0x04,
347 0x1d, 0x05,
348 0x1e, 0x03,
349 0
350 };
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100351
352 err = alloc_ad_spec(codec);
353 if (err < 0)
354 return err;
355 spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100356
357 /* AD1986A has the inverted EAPD implementation */
358 codec->inv_eapd = 1;
359
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100360 spec->gen.mixer_nid = 0x07;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100361 spec->gen.beep_nid = 0x19;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100362 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
363
364 /* AD1986A has a hardware problem that it can't share a stream
365 * with multiple output pins. The copy of front to surrounds
366 * causes noisy or silent outputs at a certain timing, e.g.
367 * changing the volume.
368 * So, let's disable the shared stream.
369 */
370 spec->gen.multiout.no_share_stream = 1;
Takashi Iwai36907392013-12-10 17:29:26 +0100371 /* give fixed DAC/pin pairs */
372 spec->gen.preferred_dacs = preferred_pairs;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100373
Takashi Iwaib3bd4fc2013-12-02 15:04:03 +0100374 /* AD1986A can't manage the dynamic pin on/off smoothly */
375 spec->gen.auto_mute_via_amp = 1;
376
Takashi Iwai632408a2013-07-05 14:14:14 +0200377 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
378 ad1986a_fixups);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100379 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
380
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100381 err = ad198x_parse_auto_config(codec);
382 if (err < 0) {
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100383 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100384 return err;
385 }
386
Takashi Iwaia928bd22013-01-22 18:18:42 +0100387 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
388
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100389 return 0;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100390}
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200394 * AD1983 specific
395 */
396
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100397/*
398 * SPDIF mux control for AD1983 auto-parser
399 */
400static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
401 struct snd_ctl_elem_info *uinfo)
402{
403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
404 struct ad198x_spec *spec = codec->spec;
405 static const char * const texts2[] = { "PCM", "ADC" };
406 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
407 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
408 int num_conns = snd_hda_get_num_conns(codec, dig_out);
409
410 if (num_conns == 2)
411 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
412 else if (num_conns == 3)
413 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
414 else
415 return -EINVAL;
416}
417
418static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
419 struct snd_ctl_elem_value *ucontrol)
420{
421 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
422 struct ad198x_spec *spec = codec->spec;
423
424 ucontrol->value.enumerated.item[0] = spec->cur_smux;
425 return 0;
426}
427
428static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
429 struct snd_ctl_elem_value *ucontrol)
430{
431 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
432 struct ad198x_spec *spec = codec->spec;
433 unsigned int val = ucontrol->value.enumerated.item[0];
434 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
435 int num_conns = snd_hda_get_num_conns(codec, dig_out);
436
437 if (val >= num_conns)
438 return -EINVAL;
439 if (spec->cur_smux == val)
440 return 0;
441 spec->cur_smux = val;
442 snd_hda_codec_write_cache(codec, dig_out, 0,
443 AC_VERB_SET_CONNECT_SEL, val);
444 return 1;
445}
446
447static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
448 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
449 .name = "IEC958 Playback Source",
450 .info = ad1983_auto_smux_enum_info,
451 .get = ad1983_auto_smux_enum_get,
452 .put = ad1983_auto_smux_enum_put,
453};
454
455static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
456{
457 struct ad198x_spec *spec = codec->spec;
458 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
459 int num_conns;
460
461 if (!dig_out)
462 return 0;
463 num_conns = snd_hda_get_num_conns(codec, dig_out);
464 if (num_conns != 2 && num_conns != 3)
465 return 0;
466 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
467 return -ENOMEM;
468 return 0;
469}
470
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200471static int patch_ad1983(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100472{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200473 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100474 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200475
Takashi Iwai361dab32012-05-09 14:35:27 +0200476 err = alloc_ad_spec(codec);
477 if (err < 0)
478 return err;
479 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200480
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100481 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100482 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
483 err = ad198x_parse_auto_config(codec);
484 if (err < 0)
485 goto error;
486 err = ad1983_add_spdif_mux_ctl(codec);
487 if (err < 0)
488 goto error;
489 return 0;
490
491 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100492 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100493 return err;
494}
495
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200496
497/*
498 * AD1981 HD specific
499 */
500
Takashi Iwaia928bd22013-01-22 18:18:42 +0100501static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
502 const struct hda_fixup *fix, int action)
503{
504 struct ad198x_spec *spec = codec->spec;
505
506 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
507 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
508 spec->eapd_nid = 0x05;
509 }
510}
511
512/* set the upper-limit for mixer amp to 0dB for avoiding the possible
513 * damage by overloading
514 */
515static void ad1981_fixup_amp_override(struct hda_codec *codec,
516 const struct hda_fixup *fix, int action)
517{
518 if (action == HDA_FIXUP_ACT_PRE_PROBE)
519 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
520 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
521 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
522 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
523 (1 << AC_AMPCAP_MUTE_SHIFT));
524}
525
526enum {
527 AD1981_FIXUP_AMP_OVERRIDE,
528 AD1981_FIXUP_HP_EAPD,
529};
530
531static const struct hda_fixup ad1981_fixups[] = {
532 [AD1981_FIXUP_AMP_OVERRIDE] = {
533 .type = HDA_FIXUP_FUNC,
534 .v.func = ad1981_fixup_amp_override,
535 },
536 [AD1981_FIXUP_HP_EAPD] = {
537 .type = HDA_FIXUP_FUNC,
538 .v.func = ad1981_fixup_hp_eapd,
539 .chained = true,
540 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
541 },
542};
543
544static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
545 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
546 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
547 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
548 /* HP nx6320 (reversed SSID, H/W bug) */
549 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
550 {}
551};
552
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200553static int patch_ad1981(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100554{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200555 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100556 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200557
Takashi Iwai361dab32012-05-09 14:35:27 +0200558 err = alloc_ad_spec(codec);
559 if (err < 0)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200560 return -ENOMEM;
Takashi Iwai361dab32012-05-09 14:35:27 +0200561 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200562
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100563 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100564 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100565 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100566
567 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
568 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
569
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100570 err = ad198x_parse_auto_config(codec);
571 if (err < 0)
572 goto error;
573 err = ad1983_add_spdif_mux_ctl(codec);
574 if (err < 0)
575 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100576
577 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
578
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100579 return 0;
580
581 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100582 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100583 return err;
584}
585
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200586
587/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100588 * AD1988
589 *
590 * Output pins and routes
591 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100592 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100593 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
594 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
595 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
596 * port-D 0x12 (mute/hp) <- 0x29 <- 04
597 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
598 * port-F 0x16 (mute) <- 0x2a <- 06
599 * port-G 0x24 (mute) <- 0x27 <- 05
600 * port-H 0x25 (mute) <- 0x28 <- 0a
601 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
602 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100603 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
604 * (*) 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 +0100605 *
606 * Input pins and routes
607 *
608 * pin boost mix input # / adc input #
609 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
610 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
611 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
612 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
613 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
614 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
615 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
616 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
617 *
618 *
619 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +0100620 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +0100621 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100622 *
623 * Inputs of Analog Mix (0x20)
624 * 0:Port-B (front mic)
625 * 1:Port-C/G/H (line-in)
626 * 2:Port-A
627 * 3:Port-D (line-in/2)
628 * 4:Port-E/G/H (mic-in)
629 * 5:Port-F (mic2-in)
630 * 6:CD
631 * 7:Beep
632 *
633 * ADC selection
634 * 0:Port-A
635 * 1:Port-B (front mic-in)
636 * 2:Port-C (line-in)
637 * 3:Port-F (mic2-in)
638 * 4:Port-E (mic-in)
639 * 5:CD
640 * 6:Port-G
641 * 7:Port-H
642 * 8:Port-D (line-in/2)
643 * 9:Mix
644 *
645 * Proposed pin assignments by the datasheet
646 *
647 * 6-stack
648 * Port-A front headphone
649 * B front mic-in
650 * C rear line-in
651 * D rear front-out
652 * E rear mic-in
653 * F rear surround
654 * G rear CLFE
655 * H rear side
656 *
657 * 3-stack
658 * Port-A front headphone
659 * B front mic
660 * C rear line-in/surround
661 * D rear front-out
662 * E rear mic-in/CLFE
663 *
664 * laptop
665 * Port-A headphone
666 * B mic-in
667 * C docking station
668 * D internal speaker (with EAPD)
669 * E/F quad mic array
670 */
671
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100672#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100673static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_info *uinfo)
675{
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct ad198x_spec *spec = codec->spec;
678 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
679 spec->num_channel_mode);
680}
681
682static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
684{
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct ad198x_spec *spec = codec->spec;
687 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
688 spec->num_channel_mode, spec->multiout.max_channels);
689}
690
691static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
693{
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200696 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
697 spec->num_channel_mode,
698 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +0200699 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +0200700 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200701 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100702}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100703#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100704
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100705static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_info *uinfo)
707{
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 static const char * const texts[] = {
710 "PCM", "ADC1", "ADC2", "ADC3",
711 };
712 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
713 if (num_conns > 4)
714 num_conns = 4;
715 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
716}
717
718static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
719 struct snd_ctl_elem_value *ucontrol)
720{
721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722 struct ad198x_spec *spec = codec->spec;
723
724 ucontrol->value.enumerated.item[0] = spec->cur_smux;
725 return 0;
726}
727
728static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct ad198x_spec *spec = codec->spec;
733 unsigned int val = ucontrol->value.enumerated.item[0];
734 struct nid_path *path;
735 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
736
737 if (val >= num_conns)
738 return -EINVAL;
739 if (spec->cur_smux == val)
740 return 0;
741
742 mutex_lock(&codec->control_mutex);
743 codec->cached_write = 1;
744 path = snd_hda_get_path_from_idx(codec,
745 spec->smux_paths[spec->cur_smux]);
746 if (path)
747 snd_hda_activate_path(codec, path, false, true);
748 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
749 if (path)
750 snd_hda_activate_path(codec, path, true, true);
751 spec->cur_smux = val;
752 codec->cached_write = 0;
753 mutex_unlock(&codec->control_mutex);
754 snd_hda_codec_flush_cache(codec); /* flush the updates */
755 return 1;
756}
757
758static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
759 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
760 .name = "IEC958 Playback Source",
761 .info = ad1988_auto_smux_enum_info,
762 .get = ad1988_auto_smux_enum_get,
763 .put = ad1988_auto_smux_enum_put,
764};
765
766static int ad1988_auto_init(struct hda_codec *codec)
767{
768 struct ad198x_spec *spec = codec->spec;
769 int i, err;
770
771 err = snd_hda_gen_init(codec);
772 if (err < 0)
773 return err;
774 if (!spec->gen.autocfg.dig_outs)
775 return 0;
776
777 for (i = 0; i < 4; i++) {
778 struct nid_path *path;
779 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
780 if (path)
781 snd_hda_activate_path(codec, path, path->active, false);
782 }
783
784 return 0;
785}
786
787static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
788{
789 struct ad198x_spec *spec = codec->spec;
790 int i, num_conns;
791 /* we create four static faked paths, since AD codecs have odd
792 * widget connections regarding the SPDIF out source
793 */
794 static struct nid_path fake_paths[4] = {
795 {
796 .depth = 3,
797 .path = { 0x02, 0x1d, 0x1b },
798 .idx = { 0, 0, 0 },
799 .multi = { 0, 0, 0 },
800 },
801 {
802 .depth = 4,
803 .path = { 0x08, 0x0b, 0x1d, 0x1b },
804 .idx = { 0, 0, 1, 0 },
805 .multi = { 0, 1, 0, 0 },
806 },
807 {
808 .depth = 4,
809 .path = { 0x09, 0x0b, 0x1d, 0x1b },
810 .idx = { 0, 1, 1, 0 },
811 .multi = { 0, 1, 0, 0 },
812 },
813 {
814 .depth = 4,
815 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
816 .idx = { 0, 2, 1, 0 },
817 .multi = { 0, 1, 0, 0 },
818 },
819 };
820
821 /* SPDIF source mux appears to be present only on AD1988A */
822 if (!spec->gen.autocfg.dig_outs ||
823 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
824 return 0;
825
826 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
827 if (num_conns != 3 && num_conns != 4)
828 return 0;
829
830 for (i = 0; i < num_conns; i++) {
831 struct nid_path *path = snd_array_new(&spec->gen.paths);
832 if (!path)
833 return -ENOMEM;
834 *path = fake_paths[i];
835 if (!i)
836 path->active = 1;
837 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
838 }
839
840 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
841 return -ENOMEM;
842
843 codec->patch_ops.init = ad1988_auto_init;
844
845 return 0;
846}
847
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100848/*
Takashi Iwaid32410b12005-11-24 16:06:23 +0100849 */
850
Takashi Iwai36ad4532013-07-04 16:34:20 +0200851enum {
852 AD1988_FIXUP_6STACK_DIG,
853};
854
855static const struct hda_fixup ad1988_fixups[] = {
856 [AD1988_FIXUP_6STACK_DIG] = {
857 .type = HDA_FIXUP_PINS,
858 .v.pins = (const struct hda_pintbl[]) {
859 { 0x11, 0x02214130 }, /* front-hp */
860 { 0x12, 0x01014010 }, /* line-out */
861 { 0x14, 0x02a19122 }, /* front-mic */
862 { 0x15, 0x01813021 }, /* line-in */
863 { 0x16, 0x01011012 }, /* line-out */
864 { 0x17, 0x01a19020 }, /* mic */
865 { 0x1b, 0x0145f1f0 }, /* SPDIF */
866 { 0x24, 0x01016011 }, /* line-out */
867 { 0x25, 0x01012013 }, /* line-out */
868 { }
869 }
870 },
871};
872
873static const struct hda_model_fixup ad1988_fixup_models[] = {
874 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
875 {}
876};
877
878static int patch_ad1988(struct hda_codec *codec)
Takashi Iwaid32410b12005-11-24 16:06:23 +0100879{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100880 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100881 int err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100882
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100883 err = alloc_ad_spec(codec);
884 if (err < 0)
885 return err;
886 spec = codec->spec;
887
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100888 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +0100889 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100890 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100891 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai36ad4532013-07-04 16:34:20 +0200892
893 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
894 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
895
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100896 err = ad198x_parse_auto_config(codec);
897 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100898 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100899 err = ad1988_add_spdif_mux_ctl(codec);
900 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100901 goto error;
Takashi Iwai36ad4532013-07-04 16:34:20 +0200902
903 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
904
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100905 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100906
907 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100908 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100909 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100910}
911
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100912
913/*
Takashi Iwai2bac6472007-05-18 18:21:41 +0200914 * AD1884 / AD1984
915 *
916 * port-B - front line/mic-in
917 * port-E - aux in/out
918 * port-F - aux in/out
919 * port-C - rear line/mic-in
920 * port-D - rear line/hp-out
921 * port-A - front line/hp-out
922 *
923 * AD1984 = AD1884 + two digital mic-ins
924 *
Takashi Iwai5ccc6182013-07-04 15:36:56 +0200925 * AD1883 / AD1884A / AD1984A / AD1984B
926 *
927 * port-B (0x14) - front mic-in
928 * port-E (0x1c) - rear mic-in
929 * port-F (0x16) - CD / ext out
930 * port-C (0x15) - rear line-in
931 * port-D (0x12) - rear line-out
932 * port-A (0x11) - front hp-out
933 *
934 * AD1984A = AD1884A + digital-mic
935 * AD1883 = equivalent with AD1984A
936 * AD1984B = AD1984A + extra SPDIF-out
Takashi Iwai2bac6472007-05-18 18:21:41 +0200937 */
938
Takashi Iwaia928bd22013-01-22 18:18:42 +0100939/* set the upper-limit for mixer amp to 0dB for avoiding the possible
940 * damage by overloading
941 */
942static void ad1884_fixup_amp_override(struct hda_codec *codec,
943 const struct hda_fixup *fix, int action)
944{
945 if (action == HDA_FIXUP_ACT_PRE_PROBE)
946 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
947 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
948 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
949 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
950 (1 << AC_AMPCAP_MUTE_SHIFT));
951}
952
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200953/* toggle GPIO1 according to the mute state */
954static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
955{
956 struct hda_codec *codec = private_data;
957 struct ad198x_spec *spec = codec->spec;
958
959 if (spec->eapd_nid)
960 ad_vmaster_eapd_hook(private_data, enabled);
961 snd_hda_codec_update_cache(codec, 0x01, 0,
962 AC_VERB_SET_GPIO_DATA,
963 enabled ? 0x00 : 0x02);
964}
965
Takashi Iwaia928bd22013-01-22 18:18:42 +0100966static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
967 const struct hda_fixup *fix, int action)
968{
969 struct ad198x_spec *spec = codec->spec;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200970 static const struct hda_verb gpio_init_verbs[] = {
971 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
972 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
973 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
974 {},
975 };
Takashi Iwaia928bd22013-01-22 18:18:42 +0100976
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200977 switch (action) {
978 case HDA_FIXUP_ACT_PRE_PROBE:
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200979 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
Takashi Iwai1cd9b2f2013-12-02 13:19:45 +0100980 spec->gen.own_eapd_ctl = 1;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200981 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200982 break;
983 case HDA_FIXUP_ACT_PROBE:
Takashi Iwaia928bd22013-01-22 18:18:42 +0100984 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
985 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
986 else
987 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200988 break;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100989 }
990}
991
Takashi Iwai1ac32932013-10-26 00:24:14 +0200992static void ad1884_fixup_thinkpad(struct hda_codec *codec,
993 const struct hda_fixup *fix, int action)
994{
995 struct ad198x_spec *spec = codec->spec;
996
Takashi Iwaiafb5a772013-10-26 00:33:58 +0200997 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwai1ac32932013-10-26 00:24:14 +0200998 spec->gen.keep_eapd_on = 1;
Takashi Iwaiafb5a772013-10-26 00:33:58 +0200999 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1000 spec->eapd_nid = 0x12;
1001 }
Takashi Iwai1ac32932013-10-26 00:24:14 +02001002}
1003
Takashi Iwai6a699be2013-07-04 14:45:37 +02001004/* set magic COEFs for dmic */
1005static const struct hda_verb ad1884_dmic_init_verbs[] = {
1006 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1007 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1008 {}
1009};
1010
Takashi Iwaia928bd22013-01-22 18:18:42 +01001011enum {
1012 AD1884_FIXUP_AMP_OVERRIDE,
1013 AD1884_FIXUP_HP_EAPD,
Takashi Iwai6a699be2013-07-04 14:45:37 +02001014 AD1884_FIXUP_DMIC_COEF,
Takashi Iwai1ac32932013-10-26 00:24:14 +02001015 AD1884_FIXUP_THINKPAD,
Takashi Iwaif4046272013-07-04 15:14:17 +02001016 AD1884_FIXUP_HP_TOUCHSMART,
Takashi Iwaia928bd22013-01-22 18:18:42 +01001017};
1018
1019static const struct hda_fixup ad1884_fixups[] = {
1020 [AD1884_FIXUP_AMP_OVERRIDE] = {
1021 .type = HDA_FIXUP_FUNC,
1022 .v.func = ad1884_fixup_amp_override,
1023 },
1024 [AD1884_FIXUP_HP_EAPD] = {
1025 .type = HDA_FIXUP_FUNC,
1026 .v.func = ad1884_fixup_hp_eapd,
1027 .chained = true,
1028 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1029 },
Takashi Iwai6a699be2013-07-04 14:45:37 +02001030 [AD1884_FIXUP_DMIC_COEF] = {
1031 .type = HDA_FIXUP_VERBS,
1032 .v.verbs = ad1884_dmic_init_verbs,
1033 },
Takashi Iwai1ac32932013-10-26 00:24:14 +02001034 [AD1884_FIXUP_THINKPAD] = {
1035 .type = HDA_FIXUP_FUNC,
1036 .v.func = ad1884_fixup_thinkpad,
1037 .chained = true,
1038 .chain_id = AD1884_FIXUP_DMIC_COEF,
1039 },
Takashi Iwaif4046272013-07-04 15:14:17 +02001040 [AD1884_FIXUP_HP_TOUCHSMART] = {
1041 .type = HDA_FIXUP_VERBS,
1042 .v.verbs = ad1884_dmic_init_verbs,
1043 .chained = true,
1044 .chain_id = AD1884_FIXUP_HP_EAPD,
1045 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01001046};
1047
1048static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
Takashi Iwaif4046272013-07-04 15:14:17 +02001049 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001050 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
Takashi Iwai1ac32932013-10-26 00:24:14 +02001051 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001052 {}
1053};
1054
1055
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001056static int patch_ad1884(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001057{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001058 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001059 int err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001060
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001061 err = alloc_ad_spec(codec);
1062 if (err < 0)
1063 return err;
1064 spec = codec->spec;
1065
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001066 spec->gen.mixer_nid = 0x20;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001067 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001068 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01001069
1070 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1071 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1072
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001073 err = ad198x_parse_auto_config(codec);
1074 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001075 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001076 err = ad1983_add_spdif_mux_ctl(codec);
1077 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001078 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001079
1080 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1081
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001082 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001083
1084 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001085 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001086 return err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001087}
1088
Takashi Iwaic5059252008-02-16 09:43:56 +01001089/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001090 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02001091 *
1092 * port-A - front hp-out
1093 * port-B - front mic-in
1094 * port-C - rear line-in, shared surr-out (3stack)
1095 * port-D - rear line-out
1096 * port-E - rear mic-in, shared clfe-out (3stack)
1097 * port-F - rear surr-out (6stack)
1098 * port-G - rear clfe-out (6stack)
1099 */
1100
Takashi Iwaiaa95d612013-07-04 15:16:31 +02001101static int patch_ad1882(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001102{
Takashi Iwai0ac85512007-06-20 15:46:13 +02001103 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001104 int err;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001105
Takashi Iwai361dab32012-05-09 14:35:27 +02001106 err = alloc_ad_spec(codec);
1107 if (err < 0)
1108 return err;
1109 spec = codec->spec;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001110
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001111 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01001112 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001113 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001114 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1115 err = ad198x_parse_auto_config(codec);
1116 if (err < 0)
1117 goto error;
1118 err = ad1988_add_spdif_mux_ctl(codec);
1119 if (err < 0)
1120 goto error;
1121 return 0;
1122
1123 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001124 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001125 return err;
1126}
1127
Takashi Iwai0ac85512007-06-20 15:46:13 +02001128
1129/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 * patch entries
1131 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001132static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001133 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
Takashi Iwai0ac85512007-06-20 15:46:13 +02001134 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001135 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02001136 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001137 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1138 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001139 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1140 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001141 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001143 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02001144 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001145 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02001146 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1147 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 {} /* terminator */
1149};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001150
1151MODULE_ALIAS("snd-hda-codec-id:11d4*");
1152
1153MODULE_LICENSE("GPL");
1154MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1155
1156static struct hda_codec_preset_list analog_list = {
1157 .preset = snd_hda_preset_analog,
1158 .owner = THIS_MODULE,
1159};
1160
1161static int __init patch_analog_init(void)
1162{
1163 return snd_hda_add_codec_preset(&analog_list);
1164}
1165
1166static void __exit patch_analog_exit(void)
1167{
1168 snd_hda_delete_codec_preset(&analog_list);
1169}
1170
1171module_init(patch_analog_init)
1172module_exit(patch_analog_exit)