blob: 1a83559f4cbd27e455a941adaddc6d0513d9dd81 [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;
150 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
151 AC_VERB_SET_EAPD_BTLENABLE,
152 enabled ? 0x02 : 0x00);
153}
Takashi Iwai9230d212006-03-13 13:49:49 +0100154
Takashi Iwai18a815d2006-03-01 19:54:39 +0100155/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100156 * Automatic parse of I/O pins from the BIOS configuration
157 */
158
159static int ad198x_auto_build_controls(struct hda_codec *codec)
160{
161 int err;
162
163 err = snd_hda_gen_build_controls(codec);
164 if (err < 0)
165 return err;
166 err = create_beep_ctls(codec);
167 if (err < 0)
168 return err;
169 return 0;
170}
171
172static const struct hda_codec_ops ad198x_auto_patch_ops = {
173 .build_controls = ad198x_auto_build_controls,
174 .build_pcms = snd_hda_gen_build_pcms,
175 .init = snd_hda_gen_init,
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100176 .free = snd_hda_gen_free,
Takashi Iwai8a6c21a2013-01-18 07:51:17 +0100177 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100178#ifdef CONFIG_PM
179 .check_power_status = snd_hda_gen_check_power_status,
180 .suspend = ad198x_suspend,
181#endif
182 .reboot_notify = ad198x_shutup,
183};
184
185
186static int ad198x_parse_auto_config(struct hda_codec *codec)
187{
188 struct ad198x_spec *spec = codec->spec;
189 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
190 int err;
191
192 codec->spdif_status_reset = 1;
193 codec->no_trigger_sense = 1;
194 codec->no_sticky_stream = 1;
195
196 spec->gen.indep_hp = 1;
197
198 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
199 if (err < 0)
200 return err;
201 err = snd_hda_gen_parse_auto_config(codec, cfg);
202 if (err < 0)
203 return err;
204
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100205 codec->patch_ops = ad198x_auto_patch_ops;
206
207 return 0;
208}
209
210/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200211 * AD1986A specific
212 */
213
Takashi Iwai361dab32012-05-09 14:35:27 +0200214static int alloc_ad_spec(struct hda_codec *codec)
215{
216 struct ad198x_spec *spec;
217
218 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
219 if (!spec)
220 return -ENOMEM;
221 codec->spec = spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100222 snd_hda_gen_spec_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +0200223 return 0;
224}
225
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100226/*
Takashi Iwaia928bd22013-01-22 18:18:42 +0100227 * AD1986A fixup codes
228 */
229
230/* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
231static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
232 const struct hda_fixup *fix, int action)
233{
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100234 struct ad198x_spec *spec = codec->spec;
235
236 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaia928bd22013-01-22 18:18:42 +0100237 codec->inv_jack_detect = 1;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100238 spec->gen.keep_eapd_on = 1;
Takashi Iwaif710a9f2013-11-13 09:42:56 +0100239 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
240 spec->eapd_nid = 0x1b;
Takashi Iwai7a3e6102013-11-13 09:39:08 +0100241 }
Takashi Iwaia928bd22013-01-22 18:18:42 +0100242}
243
244enum {
245 AD1986A_FIXUP_INV_JACK_DETECT,
Takashi Iwaie0b27162013-07-04 16:50:46 +0200246 AD1986A_FIXUP_ULTRA,
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200247 AD1986A_FIXUP_SAMSUNG,
Takashi Iwai632408a2013-07-05 14:14:14 +0200248 AD1986A_FIXUP_3STACK,
249 AD1986A_FIXUP_LAPTOP,
250 AD1986A_FIXUP_LAPTOP_IMIC,
Takashi Iwaia928bd22013-01-22 18:18:42 +0100251};
252
253static const struct hda_fixup ad1986a_fixups[] = {
254 [AD1986A_FIXUP_INV_JACK_DETECT] = {
255 .type = HDA_FIXUP_FUNC,
256 .v.func = ad_fixup_inv_jack_detect,
257 },
Takashi Iwaie0b27162013-07-04 16:50:46 +0200258 [AD1986A_FIXUP_ULTRA] = {
259 .type = HDA_FIXUP_PINS,
260 .v.pins = (const struct hda_pintbl[]) {
261 { 0x1b, 0x90170110 }, /* speaker */
262 { 0x1d, 0x90a7013e }, /* int mic */
263 {}
264 },
265 },
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200266 [AD1986A_FIXUP_SAMSUNG] = {
267 .type = HDA_FIXUP_PINS,
268 .v.pins = (const struct hda_pintbl[]) {
269 { 0x1b, 0x90170110 }, /* speaker */
270 { 0x1d, 0x90a7013e }, /* int mic */
271 { 0x20, 0x411111f0 }, /* N/A */
272 { 0x24, 0x411111f0 }, /* N/A */
273 {}
274 },
275 },
Takashi Iwai632408a2013-07-05 14:14:14 +0200276 [AD1986A_FIXUP_3STACK] = {
277 .type = HDA_FIXUP_PINS,
278 .v.pins = (const struct hda_pintbl[]) {
279 { 0x1a, 0x02214021 }, /* headphone */
280 { 0x1b, 0x01014011 }, /* front */
281 { 0x1c, 0x01013012 }, /* surround */
282 { 0x1d, 0x01019015 }, /* clfe */
283 { 0x1e, 0x411111f0 }, /* N/A */
284 { 0x1f, 0x02a190f0 }, /* mic */
285 { 0x20, 0x018130f0 }, /* line-in */
286 {}
287 },
288 },
289 [AD1986A_FIXUP_LAPTOP] = {
290 .type = HDA_FIXUP_PINS,
291 .v.pins = (const struct hda_pintbl[]) {
292 { 0x1a, 0x02214021 }, /* headphone */
293 { 0x1b, 0x90170110 }, /* speaker */
294 { 0x1c, 0x411111f0 }, /* N/A */
295 { 0x1d, 0x411111f0 }, /* N/A */
296 { 0x1e, 0x411111f0 }, /* N/A */
297 { 0x1f, 0x02a191f0 }, /* mic */
298 { 0x20, 0x411111f0 }, /* N/A */
299 {}
300 },
301 },
302 [AD1986A_FIXUP_LAPTOP_IMIC] = {
303 .type = HDA_FIXUP_PINS,
304 .v.pins = (const struct hda_pintbl[]) {
305 { 0x1d, 0x90a7013e }, /* int mic */
306 {}
307 },
308 .chained_before = 1,
309 .chain_id = AD1986A_FIXUP_LAPTOP,
310 },
Takashi Iwaia928bd22013-01-22 18:18:42 +0100311};
312
313static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
Takashi Iwai632408a2013-07-05 14:14:14 +0200314 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC),
315 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK),
316 SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK),
317 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK),
318 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
Takashi Iwaif8c0ab12013-07-04 17:06:04 +0200319 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
Takashi Iwaie0b27162013-07-04 16:50:46 +0200320 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
Takashi Iwaia928bd22013-01-22 18:18:42 +0100321 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
Takashi Iwai632408a2013-07-05 14:14:14 +0200322 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK),
323 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK),
324 {}
325};
326
327static const struct hda_model_fixup ad1986a_fixup_models[] = {
328 { .id = AD1986A_FIXUP_3STACK, .name = "3stack" },
329 { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" },
330 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" },
331 { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */
Takashi Iwaia928bd22013-01-22 18:18:42 +0100332 {}
333};
334
335/*
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100336 */
Takashi Iwai632408a2013-07-05 14:14:14 +0200337static int patch_ad1986a(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100338{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100339 int err;
340 struct ad198x_spec *spec;
341
342 err = alloc_ad_spec(codec);
343 if (err < 0)
344 return err;
345 spec = codec->spec;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100346
347 /* AD1986A has the inverted EAPD implementation */
348 codec->inv_eapd = 1;
349
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100350 spec->gen.mixer_nid = 0x07;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100351 spec->gen.beep_nid = 0x19;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100352 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
353
354 /* AD1986A has a hardware problem that it can't share a stream
355 * with multiple output pins. The copy of front to surrounds
356 * causes noisy or silent outputs at a certain timing, e.g.
357 * changing the volume.
358 * So, let's disable the shared stream.
359 */
360 spec->gen.multiout.no_share_stream = 1;
361
Takashi Iwai632408a2013-07-05 14:14:14 +0200362 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
363 ad1986a_fixups);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100364 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
365
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100366 err = ad198x_parse_auto_config(codec);
367 if (err < 0) {
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100368 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100369 return err;
370 }
371
Takashi Iwaia928bd22013-01-22 18:18:42 +0100372 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
373
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100374 return 0;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100375}
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200379 * AD1983 specific
380 */
381
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100382/*
383 * SPDIF mux control for AD1983 auto-parser
384 */
385static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_info *uinfo)
387{
388 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
389 struct ad198x_spec *spec = codec->spec;
390 static const char * const texts2[] = { "PCM", "ADC" };
391 static const char * const texts3[] = { "PCM", "ADC1", "ADC2" };
392 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
393 int num_conns = snd_hda_get_num_conns(codec, dig_out);
394
395 if (num_conns == 2)
396 return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2);
397 else if (num_conns == 3)
398 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
399 else
400 return -EINVAL;
401}
402
403static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct ad198x_spec *spec = codec->spec;
408
409 ucontrol->value.enumerated.item[0] = spec->cur_smux;
410 return 0;
411}
412
413static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
414 struct snd_ctl_elem_value *ucontrol)
415{
416 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
417 struct ad198x_spec *spec = codec->spec;
418 unsigned int val = ucontrol->value.enumerated.item[0];
419 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
420 int num_conns = snd_hda_get_num_conns(codec, dig_out);
421
422 if (val >= num_conns)
423 return -EINVAL;
424 if (spec->cur_smux == val)
425 return 0;
426 spec->cur_smux = val;
427 snd_hda_codec_write_cache(codec, dig_out, 0,
428 AC_VERB_SET_CONNECT_SEL, val);
429 return 1;
430}
431
432static struct snd_kcontrol_new ad1983_auto_smux_mixer = {
433 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
434 .name = "IEC958 Playback Source",
435 .info = ad1983_auto_smux_enum_info,
436 .get = ad1983_auto_smux_enum_get,
437 .put = ad1983_auto_smux_enum_put,
438};
439
440static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec)
441{
442 struct ad198x_spec *spec = codec->spec;
443 hda_nid_t dig_out = spec->gen.multiout.dig_out_nid;
444 int num_conns;
445
446 if (!dig_out)
447 return 0;
448 num_conns = snd_hda_get_num_conns(codec, dig_out);
449 if (num_conns != 2 && num_conns != 3)
450 return 0;
451 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer))
452 return -ENOMEM;
453 return 0;
454}
455
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200456static int patch_ad1983(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100457{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200458 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100459 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200460
Takashi Iwai361dab32012-05-09 14:35:27 +0200461 err = alloc_ad_spec(codec);
462 if (err < 0)
463 return err;
464 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200465
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100466 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100467 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
468 err = ad198x_parse_auto_config(codec);
469 if (err < 0)
470 goto error;
471 err = ad1983_add_spdif_mux_ctl(codec);
472 if (err < 0)
473 goto error;
474 return 0;
475
476 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100477 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100478 return err;
479}
480
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200481
482/*
483 * AD1981 HD specific
484 */
485
Takashi Iwaia928bd22013-01-22 18:18:42 +0100486static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
487 const struct hda_fixup *fix, int action)
488{
489 struct ad198x_spec *spec = codec->spec;
490
491 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
492 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
493 spec->eapd_nid = 0x05;
494 }
495}
496
497/* set the upper-limit for mixer amp to 0dB for avoiding the possible
498 * damage by overloading
499 */
500static void ad1981_fixup_amp_override(struct hda_codec *codec,
501 const struct hda_fixup *fix, int action)
502{
503 if (action == HDA_FIXUP_ACT_PRE_PROBE)
504 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
505 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
506 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
507 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
508 (1 << AC_AMPCAP_MUTE_SHIFT));
509}
510
511enum {
512 AD1981_FIXUP_AMP_OVERRIDE,
513 AD1981_FIXUP_HP_EAPD,
514};
515
516static const struct hda_fixup ad1981_fixups[] = {
517 [AD1981_FIXUP_AMP_OVERRIDE] = {
518 .type = HDA_FIXUP_FUNC,
519 .v.func = ad1981_fixup_amp_override,
520 },
521 [AD1981_FIXUP_HP_EAPD] = {
522 .type = HDA_FIXUP_FUNC,
523 .v.func = ad1981_fixup_hp_eapd,
524 .chained = true,
525 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
526 },
527};
528
529static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
530 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
531 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
532 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
533 /* HP nx6320 (reversed SSID, H/W bug) */
534 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
535 {}
536};
537
Takashi Iwaibd450dc2013-07-04 15:48:04 +0200538static int patch_ad1981(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100539{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200540 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100541 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200542
Takashi Iwai361dab32012-05-09 14:35:27 +0200543 err = alloc_ad_spec(codec);
544 if (err < 0)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200545 return -ENOMEM;
Takashi Iwai361dab32012-05-09 14:35:27 +0200546 spec = codec->spec;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200547
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100548 spec->gen.mixer_nid = 0x0e;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100549 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100550 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +0100551
552 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
553 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
554
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100555 err = ad198x_parse_auto_config(codec);
556 if (err < 0)
557 goto error;
558 err = ad1983_add_spdif_mux_ctl(codec);
559 if (err < 0)
560 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100561
562 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
563
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100564 return 0;
565
566 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100567 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100568 return err;
569}
570
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200571
572/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100573 * AD1988
574 *
575 * Output pins and routes
576 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100577 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100578 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
579 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
580 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
581 * port-D 0x12 (mute/hp) <- 0x29 <- 04
582 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
583 * port-F 0x16 (mute) <- 0x2a <- 06
584 * port-G 0x24 (mute) <- 0x27 <- 05
585 * port-H 0x25 (mute) <- 0x28 <- 0a
586 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
587 *
Takashi Iwaid32410b12005-11-24 16:06:23 +0100588 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
589 * (*) 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 +0100590 *
591 * Input pins and routes
592 *
593 * pin boost mix input # / adc input #
594 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
595 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
596 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
597 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
598 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
599 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
600 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
601 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
602 *
603 *
604 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +0100605 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +0100606 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100607 *
608 * Inputs of Analog Mix (0x20)
609 * 0:Port-B (front mic)
610 * 1:Port-C/G/H (line-in)
611 * 2:Port-A
612 * 3:Port-D (line-in/2)
613 * 4:Port-E/G/H (mic-in)
614 * 5:Port-F (mic2-in)
615 * 6:CD
616 * 7:Beep
617 *
618 * ADC selection
619 * 0:Port-A
620 * 1:Port-B (front mic-in)
621 * 2:Port-C (line-in)
622 * 3:Port-F (mic2-in)
623 * 4:Port-E (mic-in)
624 * 5:CD
625 * 6:Port-G
626 * 7:Port-H
627 * 8:Port-D (line-in/2)
628 * 9:Mix
629 *
630 * Proposed pin assignments by the datasheet
631 *
632 * 6-stack
633 * Port-A front headphone
634 * B front mic-in
635 * C rear line-in
636 * D rear front-out
637 * E rear mic-in
638 * F rear surround
639 * G rear CLFE
640 * H rear side
641 *
642 * 3-stack
643 * Port-A front headphone
644 * B front mic
645 * C rear line-in/surround
646 * D rear front-out
647 * E rear mic-in/CLFE
648 *
649 * laptop
650 * Port-A headphone
651 * B mic-in
652 * C docking station
653 * D internal speaker (with EAPD)
654 * E/F quad mic array
655 */
656
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100657#ifdef ENABLE_AD_STATIC_QUIRKS
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100658static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_info *uinfo)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct ad198x_spec *spec = codec->spec;
663 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
664 spec->num_channel_mode);
665}
666
667static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct ad198x_spec *spec = codec->spec;
672 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
673 spec->num_channel_mode, spec->multiout.max_channels);
674}
675
676static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200681 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
682 spec->num_channel_mode,
683 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +0200684 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +0200685 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200686 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100687}
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100688#endif /* ENABLE_AD_STATIC_QUIRKS */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100689
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100690static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
691 struct snd_ctl_elem_info *uinfo)
692{
693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
694 static const char * const texts[] = {
695 "PCM", "ADC1", "ADC2", "ADC3",
696 };
697 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
698 if (num_conns > 4)
699 num_conns = 4;
700 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
701}
702
703static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
704 struct snd_ctl_elem_value *ucontrol)
705{
706 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
707 struct ad198x_spec *spec = codec->spec;
708
709 ucontrol->value.enumerated.item[0] = spec->cur_smux;
710 return 0;
711}
712
713static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
714 struct snd_ctl_elem_value *ucontrol)
715{
716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
717 struct ad198x_spec *spec = codec->spec;
718 unsigned int val = ucontrol->value.enumerated.item[0];
719 struct nid_path *path;
720 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
721
722 if (val >= num_conns)
723 return -EINVAL;
724 if (spec->cur_smux == val)
725 return 0;
726
727 mutex_lock(&codec->control_mutex);
728 codec->cached_write = 1;
729 path = snd_hda_get_path_from_idx(codec,
730 spec->smux_paths[spec->cur_smux]);
731 if (path)
732 snd_hda_activate_path(codec, path, false, true);
733 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
734 if (path)
735 snd_hda_activate_path(codec, path, true, true);
736 spec->cur_smux = val;
737 codec->cached_write = 0;
738 mutex_unlock(&codec->control_mutex);
739 snd_hda_codec_flush_cache(codec); /* flush the updates */
740 return 1;
741}
742
743static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
744 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
745 .name = "IEC958 Playback Source",
746 .info = ad1988_auto_smux_enum_info,
747 .get = ad1988_auto_smux_enum_get,
748 .put = ad1988_auto_smux_enum_put,
749};
750
751static int ad1988_auto_init(struct hda_codec *codec)
752{
753 struct ad198x_spec *spec = codec->spec;
754 int i, err;
755
756 err = snd_hda_gen_init(codec);
757 if (err < 0)
758 return err;
759 if (!spec->gen.autocfg.dig_outs)
760 return 0;
761
762 for (i = 0; i < 4; i++) {
763 struct nid_path *path;
764 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
765 if (path)
766 snd_hda_activate_path(codec, path, path->active, false);
767 }
768
769 return 0;
770}
771
772static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
773{
774 struct ad198x_spec *spec = codec->spec;
775 int i, num_conns;
776 /* we create four static faked paths, since AD codecs have odd
777 * widget connections regarding the SPDIF out source
778 */
779 static struct nid_path fake_paths[4] = {
780 {
781 .depth = 3,
782 .path = { 0x02, 0x1d, 0x1b },
783 .idx = { 0, 0, 0 },
784 .multi = { 0, 0, 0 },
785 },
786 {
787 .depth = 4,
788 .path = { 0x08, 0x0b, 0x1d, 0x1b },
789 .idx = { 0, 0, 1, 0 },
790 .multi = { 0, 1, 0, 0 },
791 },
792 {
793 .depth = 4,
794 .path = { 0x09, 0x0b, 0x1d, 0x1b },
795 .idx = { 0, 1, 1, 0 },
796 .multi = { 0, 1, 0, 0 },
797 },
798 {
799 .depth = 4,
800 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
801 .idx = { 0, 2, 1, 0 },
802 .multi = { 0, 1, 0, 0 },
803 },
804 };
805
806 /* SPDIF source mux appears to be present only on AD1988A */
807 if (!spec->gen.autocfg.dig_outs ||
808 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
809 return 0;
810
811 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
812 if (num_conns != 3 && num_conns != 4)
813 return 0;
814
815 for (i = 0; i < num_conns; i++) {
816 struct nid_path *path = snd_array_new(&spec->gen.paths);
817 if (!path)
818 return -ENOMEM;
819 *path = fake_paths[i];
820 if (!i)
821 path->active = 1;
822 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
823 }
824
825 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
826 return -ENOMEM;
827
828 codec->patch_ops.init = ad1988_auto_init;
829
830 return 0;
831}
832
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100833/*
Takashi Iwaid32410b12005-11-24 16:06:23 +0100834 */
835
Takashi Iwai36ad4532013-07-04 16:34:20 +0200836enum {
837 AD1988_FIXUP_6STACK_DIG,
838};
839
840static const struct hda_fixup ad1988_fixups[] = {
841 [AD1988_FIXUP_6STACK_DIG] = {
842 .type = HDA_FIXUP_PINS,
843 .v.pins = (const struct hda_pintbl[]) {
844 { 0x11, 0x02214130 }, /* front-hp */
845 { 0x12, 0x01014010 }, /* line-out */
846 { 0x14, 0x02a19122 }, /* front-mic */
847 { 0x15, 0x01813021 }, /* line-in */
848 { 0x16, 0x01011012 }, /* line-out */
849 { 0x17, 0x01a19020 }, /* mic */
850 { 0x1b, 0x0145f1f0 }, /* SPDIF */
851 { 0x24, 0x01016011 }, /* line-out */
852 { 0x25, 0x01012013 }, /* line-out */
853 { }
854 }
855 },
856};
857
858static const struct hda_model_fixup ad1988_fixup_models[] = {
859 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
860 {}
861};
862
863static int patch_ad1988(struct hda_codec *codec)
Takashi Iwaid32410b12005-11-24 16:06:23 +0100864{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100865 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100866 int err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100867
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100868 err = alloc_ad_spec(codec);
869 if (err < 0)
870 return err;
871 spec = codec->spec;
872
Takashi Iwaif2f8be42013-01-21 16:40:16 +0100873 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +0100874 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100875 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +0100876 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwai36ad4532013-07-04 16:34:20 +0200877
878 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
879 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
880
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100881 err = ad198x_parse_auto_config(codec);
882 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100883 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100884 err = ad1988_add_spdif_mux_ctl(codec);
885 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100886 goto error;
Takashi Iwai36ad4532013-07-04 16:34:20 +0200887
888 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
889
Takashi Iwai272f3ea2013-01-22 15:31:33 +0100890 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100891
892 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +0100893 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +0100894 return err;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100895}
896
Takashi Iwaifd66e0d2005-11-17 15:31:34 +0100897
898/*
Takashi Iwai2bac6472007-05-18 18:21:41 +0200899 * AD1884 / AD1984
900 *
901 * port-B - front line/mic-in
902 * port-E - aux in/out
903 * port-F - aux in/out
904 * port-C - rear line/mic-in
905 * port-D - rear line/hp-out
906 * port-A - front line/hp-out
907 *
908 * AD1984 = AD1884 + two digital mic-ins
909 *
Takashi Iwai5ccc6182013-07-04 15:36:56 +0200910 * AD1883 / AD1884A / AD1984A / AD1984B
911 *
912 * port-B (0x14) - front mic-in
913 * port-E (0x1c) - rear mic-in
914 * port-F (0x16) - CD / ext out
915 * port-C (0x15) - rear line-in
916 * port-D (0x12) - rear line-out
917 * port-A (0x11) - front hp-out
918 *
919 * AD1984A = AD1884A + digital-mic
920 * AD1883 = equivalent with AD1984A
921 * AD1984B = AD1984A + extra SPDIF-out
Takashi Iwai2bac6472007-05-18 18:21:41 +0200922 */
923
Takashi Iwaia928bd22013-01-22 18:18:42 +0100924/* set the upper-limit for mixer amp to 0dB for avoiding the possible
925 * damage by overloading
926 */
927static void ad1884_fixup_amp_override(struct hda_codec *codec,
928 const struct hda_fixup *fix, int action)
929{
930 if (action == HDA_FIXUP_ACT_PRE_PROBE)
931 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
932 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
933 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
934 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
935 (1 << AC_AMPCAP_MUTE_SHIFT));
936}
937
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200938/* toggle GPIO1 according to the mute state */
939static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
940{
941 struct hda_codec *codec = private_data;
942 struct ad198x_spec *spec = codec->spec;
943
944 if (spec->eapd_nid)
945 ad_vmaster_eapd_hook(private_data, enabled);
946 snd_hda_codec_update_cache(codec, 0x01, 0,
947 AC_VERB_SET_GPIO_DATA,
948 enabled ? 0x00 : 0x02);
949}
950
Takashi Iwaia928bd22013-01-22 18:18:42 +0100951static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
952 const struct hda_fixup *fix, int action)
953{
954 struct ad198x_spec *spec = codec->spec;
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200955 static const struct hda_verb gpio_init_verbs[] = {
956 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
957 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
958 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
959 {},
960 };
Takashi Iwaia928bd22013-01-22 18:18:42 +0100961
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200962 switch (action) {
963 case HDA_FIXUP_ACT_PRE_PROBE:
Takashi Iwai1a39b5e2013-07-04 14:32:16 +0200964 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
965 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200966 break;
967 case HDA_FIXUP_ACT_PROBE:
Takashi Iwaia928bd22013-01-22 18:18:42 +0100968 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
969 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
970 else
971 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
Takashi Iwai8f0b3b72013-07-04 12:54:22 +0200972 break;
Takashi Iwaia928bd22013-01-22 18:18:42 +0100973 }
974}
975
Takashi Iwai1ac32932013-10-26 00:24:14 +0200976static void ad1884_fixup_thinkpad(struct hda_codec *codec,
977 const struct hda_fixup *fix, int action)
978{
979 struct ad198x_spec *spec = codec->spec;
980
Takashi Iwaiafb5a772013-10-26 00:33:58 +0200981 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
Takashi Iwai1ac32932013-10-26 00:24:14 +0200982 spec->gen.keep_eapd_on = 1;
Takashi Iwaiafb5a772013-10-26 00:33:58 +0200983 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
984 spec->eapd_nid = 0x12;
985 }
Takashi Iwai1ac32932013-10-26 00:24:14 +0200986}
987
Takashi Iwai6a699be2013-07-04 14:45:37 +0200988/* set magic COEFs for dmic */
989static const struct hda_verb ad1884_dmic_init_verbs[] = {
990 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
991 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
992 {}
993};
994
Takashi Iwaia928bd22013-01-22 18:18:42 +0100995enum {
996 AD1884_FIXUP_AMP_OVERRIDE,
997 AD1884_FIXUP_HP_EAPD,
Takashi Iwai6a699be2013-07-04 14:45:37 +0200998 AD1884_FIXUP_DMIC_COEF,
Takashi Iwai1ac32932013-10-26 00:24:14 +0200999 AD1884_FIXUP_THINKPAD,
Takashi Iwaif4046272013-07-04 15:14:17 +02001000 AD1884_FIXUP_HP_TOUCHSMART,
Takashi Iwaia928bd22013-01-22 18:18:42 +01001001};
1002
1003static const struct hda_fixup ad1884_fixups[] = {
1004 [AD1884_FIXUP_AMP_OVERRIDE] = {
1005 .type = HDA_FIXUP_FUNC,
1006 .v.func = ad1884_fixup_amp_override,
1007 },
1008 [AD1884_FIXUP_HP_EAPD] = {
1009 .type = HDA_FIXUP_FUNC,
1010 .v.func = ad1884_fixup_hp_eapd,
1011 .chained = true,
1012 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1013 },
Takashi Iwai6a699be2013-07-04 14:45:37 +02001014 [AD1884_FIXUP_DMIC_COEF] = {
1015 .type = HDA_FIXUP_VERBS,
1016 .v.verbs = ad1884_dmic_init_verbs,
1017 },
Takashi Iwai1ac32932013-10-26 00:24:14 +02001018 [AD1884_FIXUP_THINKPAD] = {
1019 .type = HDA_FIXUP_FUNC,
1020 .v.func = ad1884_fixup_thinkpad,
1021 .chained = true,
1022 .chain_id = AD1884_FIXUP_DMIC_COEF,
1023 },
Takashi Iwaif4046272013-07-04 15:14:17 +02001024 [AD1884_FIXUP_HP_TOUCHSMART] = {
1025 .type = HDA_FIXUP_VERBS,
1026 .v.verbs = ad1884_dmic_init_verbs,
1027 .chained = true,
1028 .chain_id = AD1884_FIXUP_HP_EAPD,
1029 },
Takashi Iwaia928bd22013-01-22 18:18:42 +01001030};
1031
1032static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
Takashi Iwaif4046272013-07-04 15:14:17 +02001033 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001034 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
Takashi Iwai1ac32932013-10-26 00:24:14 +02001035 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
Takashi Iwaia928bd22013-01-22 18:18:42 +01001036 {}
1037};
1038
1039
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001040static int patch_ad1884(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001041{
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001042 struct ad198x_spec *spec;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001043 int err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001044
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001045 err = alloc_ad_spec(codec);
1046 if (err < 0)
1047 return err;
1048 spec = codec->spec;
1049
Takashi Iwaif2f8be42013-01-21 16:40:16 +01001050 spec->gen.mixer_nid = 0x20;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001051 spec->gen.beep_nid = 0x10;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001052 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
Takashi Iwaia928bd22013-01-22 18:18:42 +01001053
1054 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1055 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1056
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001057 err = ad198x_parse_auto_config(codec);
1058 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001059 goto error;
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001060 err = ad1983_add_spdif_mux_ctl(codec);
1061 if (err < 0)
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001062 goto error;
Takashi Iwaia928bd22013-01-22 18:18:42 +01001063
1064 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1065
Takashi Iwai272f3ea2013-01-22 15:31:33 +01001066 return 0;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001067
1068 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001069 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001070 return err;
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001071}
1072
Takashi Iwaic5059252008-02-16 09:43:56 +01001073/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001074 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02001075 *
1076 * port-A - front hp-out
1077 * port-B - front mic-in
1078 * port-C - rear line-in, shared surr-out (3stack)
1079 * port-D - rear line-out
1080 * port-E - rear mic-in, shared clfe-out (3stack)
1081 * port-F - rear surr-out (6stack)
1082 * port-G - rear clfe-out (6stack)
1083 */
1084
Takashi Iwaiaa95d612013-07-04 15:16:31 +02001085static int patch_ad1882(struct hda_codec *codec)
Takashi Iwai78bb3cb2012-12-21 15:17:06 +01001086{
Takashi Iwai0ac85512007-06-20 15:46:13 +02001087 struct ad198x_spec *spec;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001088 int err;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001089
Takashi Iwai361dab32012-05-09 14:35:27 +02001090 err = alloc_ad_spec(codec);
1091 if (err < 0)
1092 return err;
1093 spec = codec->spec;
Takashi Iwai0ac85512007-06-20 15:46:13 +02001094
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001095 spec->gen.mixer_nid = 0x20;
Takashi Iwaie4a395e2013-01-23 17:00:31 +01001096 spec->gen.mixer_merge_nid = 0x21;
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001097 spec->gen.beep_nid = 0x10;
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001098 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1099 err = ad198x_parse_auto_config(codec);
1100 if (err < 0)
1101 goto error;
1102 err = ad1988_add_spdif_mux_ctl(codec);
1103 if (err < 0)
1104 goto error;
1105 return 0;
1106
1107 error:
Takashi Iwai7504b6c2013-03-18 11:25:51 +01001108 snd_hda_gen_free(codec);
Takashi Iwai9ff4bc82013-01-22 16:45:58 +01001109 return err;
1110}
1111
Takashi Iwai0ac85512007-06-20 15:46:13 +02001112
1113/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 * patch entries
1115 */
Takashi Iwai498f5b12011-05-02 11:33:15 +02001116static const struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001117 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
Takashi Iwai0ac85512007-06-20 15:46:13 +02001118 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001119 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02001120 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001121 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1122 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001123 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1124 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai5ccc6182013-07-04 15:36:56 +02001125 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001127 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02001128 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02001129 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02001130 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1131 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 {} /* terminator */
1133};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001134
1135MODULE_ALIAS("snd-hda-codec-id:11d4*");
1136
1137MODULE_LICENSE("GPL");
1138MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1139
1140static struct hda_codec_preset_list analog_list = {
1141 .preset = snd_hda_preset_analog,
1142 .owner = THIS_MODULE,
1143};
1144
1145static int __init patch_analog_init(void)
1146{
1147 return snd_hda_add_codec_preset(&analog_list);
1148}
1149
1150static void __exit patch_analog_exit(void)
1151{
1152 snd_hda_delete_codec_preset(&analog_list);
1153}
1154
1155module_init(patch_analog_init)
1156module_exit(patch_analog_exit)