ALSA: hda - Fix missing VREF setup for Mac Pro 1,1
[deliverable/linux.git] / sound / pci / hda / patch_analog.c
CommitLineData
1da177e4 1/*
0ac8551e
TI
2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
1da177e4 4 *
2bac647c 5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
1da177e4
LT
6 *
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
1da177e4 22#include <linux/init.h>
1da177e4
LT
23#include <linux/slab.h>
24#include <linux/pci.h>
da155d5b 25#include <linux/module.h>
62932df8 26
1da177e4
LT
27#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
128bc4ba 30#include "hda_auto_parser.h"
c5a4bcd0 31#include "hda_beep.h"
1835a0f9 32#include "hda_jack.h"
78bb3cb0 33#include "hda_generic.h"
1da177e4 34
9ff4bc8f 35
4a3fdf3d 36struct ad198x_spec {
78bb3cb0
TI
37 struct hda_gen_spec gen;
38
272f3ea3
TI
39 /* for auto parser */
40 int smux_paths[4];
41 unsigned int cur_smux;
a928bd2c 42 hda_nid_t eapd_nid;
272f3ea3 43
c5a4bcd0 44 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
2134ea4f
TI
45};
46
2134ea4f 47
67d634c0 48#ifdef CONFIG_SND_HDA_INPUT_BEEP
c5a4bcd0 49/* additional beep mixers; the actual parameters are overwritten at build */
498f5b17 50static const struct snd_kcontrol_new ad_beep_mixer[] = {
c5a4bcd0 51 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
123c07ae 52 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
c5a4bcd0
TI
53 { } /* 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 */
67d634c0
TI
58#else
59#define set_beep_amp(spec, nid, idx, dir) /* NOP */
60#endif
c5a4bcd0 61
78bb3cb0
TI
62#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
632408ad 71 for (knew = ad_beep_mixer ; knew->name; knew++) {
78bb3cb0
TI
72 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
4a3fdf3d 88
ea52bf26
DC
89static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
90 hda_nid_t hp)
91{
a01ef051
RY
92 if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
93 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
78bb3cb0 94 !codec->inv_eapd ? 0x00 : 0x02);
a01ef051
RY
95 if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
96 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
78bb3cb0 97 !codec->inv_eapd ? 0x00 : 0x02);
ea52bf26
DC
98}
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:
4dffbe03
TI
112 case 0x11d41988:
113 case 0x11d4198b:
114 case 0x11d4989a:
115 case 0x11d4989b:
ea52bf26
DC
116 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;
ea52bf26
DC
125 }
126}
127
0da26922
TI
128static void ad198x_shutup(struct hda_codec *codec)
129{
130 snd_hda_shutup_pins(codec);
131 ad198x_power_eapd(codec);
132}
133
2a43952a 134#ifdef CONFIG_PM
68cb2b55 135static int ad198x_suspend(struct hda_codec *codec)
ea52bf26
DC
136{
137 ad198x_shutup(codec);
ea52bf26
DC
138 return 0;
139}
ea52bf26
DC
140#endif
141
f710a9fb
TI
142/* 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;
ce8e0fd2
TI
150 if (codec->inv_eapd)
151 enabled = !enabled;
f710a9fb
TI
152 snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
153 AC_VERB_SET_EAPD_BTLENABLE,
154 enabled ? 0x02 : 0x00);
155}
9230d214 156
78bb3cb0
TI
157/*
158 * 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,
7504b6cd 178 .free = snd_hda_gen_free,
8a6c21ae 179 .unsol_event = snd_hda_jack_unsol_event,
78bb3cb0
TI
180#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
cbd209f4 188static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp)
78bb3cb0
TI
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
cbd209f4 198 spec->gen.indep_hp = indep_hp;
f1e762dd 199 spec->gen.add_stereo_mix_input = 1;
78bb3cb0
TI
200
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
78bb3cb0
TI
208 codec->patch_ops = ad198x_auto_patch_ops;
209
210 return 0;
211}
212
4a3fdf3d
TI
213/*
214 * AD1986A specific
215 */
216
361dab3e 217static int alloc_ad_spec(struct hda_codec *codec)
1da177e4 218{
4a3fdf3d 219 struct ad198x_spec *spec;
1da177e4 220
e560d8d8 221 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
361dab3e 222 if (!spec)
4a3fdf3d 223 return -ENOMEM;
4a3fdf3d 224 codec->spec = spec;
78bb3cb0 225 snd_hda_gen_spec_init(&spec->gen);
361dab3e
TI
226 return 0;
227}
228
a928bd2c
TI
229/*
230 * 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{
7a3e6107
TI
237 struct ad198x_spec *spec = codec->spec;
238
239 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
a928bd2c 240 codec->inv_jack_detect = 1;
7a3e6107 241 spec->gen.keep_eapd_on = 1;
f710a9fb
TI
242 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
243 spec->eapd_nid = 0x1b;
7a3e6107 244 }
a928bd2c
TI
245}
246
4528eb19
TI
247/* 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
a928bd2c
TI
260enum {
261 AD1986A_FIXUP_INV_JACK_DETECT,
e0b27167 262 AD1986A_FIXUP_ULTRA,
f8c0ab17 263 AD1986A_FIXUP_SAMSUNG,
632408ad
TI
264 AD1986A_FIXUP_3STACK,
265 AD1986A_FIXUP_LAPTOP,
266 AD1986A_FIXUP_LAPTOP_IMIC,
4528eb19 267 AD1986A_FIXUP_EAPD,
a928bd2c
TI
268};
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 },
e0b27167
TI
275 [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 },
f8c0ab17
TI
283 [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 },
632408ad
TI
293 [AD1986A_FIXUP_3STACK] = {
294 .type = HDA_FIXUP_PINS,
295 .v.pins = (const struct hda_pintbl[]) {
296 { 0x1a, 0x02214021 }, /* headphone */
297 { 0x1b, 0x01014011 }, /* front */
ed0e0d06
TI
298 { 0x1c, 0x01813030 }, /* line-in */
299 { 0x1d, 0x01a19020 }, /* rear mic */
632408ad
TI
300 { 0x1e, 0x411111f0 }, /* N/A */
301 { 0x1f, 0x02a190f0 }, /* mic */
ed0e0d06 302 { 0x20, 0x411111f0 }, /* N/A */
632408ad
TI
303 {}
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 },
4528eb19
TI
328 [AD1986A_FIXUP_EAPD] = {
329 .type = HDA_FIXUP_FUNC,
330 .v.func = ad1986a_fixup_eapd,
331 },
a928bd2c
TI
332};
333
334static const struct snd_pci_quirk ad1986a_fixup_tbl[] = {
632408ad
TI
335 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),
4528eb19 339 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD),
632408ad 340 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP),
f8c0ab17 341 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG),
e0b27167 342 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA),
a928bd2c 343 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT),
632408ad
TI
344 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 */
a928bd2c
TI
354 {}
355};
356
78bb3cb0
TI
357/*
358 */
632408ad 359static int patch_ad1986a(struct hda_codec *codec)
78bb3cb0 360{
9ff4bc8f
TI
361 int err;
362 struct ad198x_spec *spec;
3690739b
TI
363 static hda_nid_t preferred_pairs[] = {
364 0x1a, 0x03,
365 0x1b, 0x03,
366 0x1c, 0x04,
367 0x1d, 0x05,
368 0x1e, 0x03,
369 0
370 };
9ff4bc8f
TI
371
372 err = alloc_ad_spec(codec);
373 if (err < 0)
374 return err;
375 spec = codec->spec;
78bb3cb0
TI
376
377 /* AD1986A has the inverted EAPD implementation */
378 codec->inv_eapd = 1;
379
f2f8be43 380 spec->gen.mixer_nid = 0x07;
7504b6cd 381 spec->gen.beep_nid = 0x19;
78bb3cb0
TI
382 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;
3690739b
TI
391 /* give fixed DAC/pin pairs */
392 spec->gen.preferred_dacs = preferred_pairs;
78bb3cb0 393
b3bd4fc3
TI
394 /* AD1986A can't manage the dynamic pin on/off smoothly */
395 spec->gen.auto_mute_via_amp = 1;
78bb3cb0 396
632408ad
TI
397 snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl,
398 ad1986a_fixups);
a928bd2c
TI
399 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
400
cbd209f4 401 err = ad198x_parse_auto_config(codec, false);
9ff4bc8f 402 if (err < 0) {
7504b6cd 403 snd_hda_gen_free(codec);
9ff4bc8f
TI
404 return err;
405 }
406
a928bd2c
TI
407 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
408
9ff4bc8f 409 return 0;
78bb3cb0
TI
410}
411
1da177e4
LT
412
413/*
4a3fdf3d 414 * AD1983 specific
1da177e4 415 */
1da177e4 416
272f3ea3
TI
417/*
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
bd450dcc 491static int patch_ad1983(struct hda_codec *codec)
78bb3cb0 492{
9ff4bc8f 493 struct ad198x_spec *spec;
272f3ea3 494 int err;
78bb3cb0 495
9ff4bc8f
TI
496 err = alloc_ad_spec(codec);
497 if (err < 0)
498 return err;
499 spec = codec->spec;
500
c7579fed 501 spec->gen.mixer_nid = 0x0e;
7504b6cd 502 spec->gen.beep_nid = 0x10;
78bb3cb0 503 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
cbd209f4 504 err = ad198x_parse_auto_config(codec, false);
272f3ea3 505 if (err < 0)
9ff4bc8f 506 goto error;
272f3ea3
TI
507 err = ad1983_add_spdif_mux_ctl(codec);
508 if (err < 0)
9ff4bc8f 509 goto error;
272f3ea3 510 return 0;
9ff4bc8f
TI
511
512 error:
7504b6cd 513 snd_hda_gen_free(codec);
9ff4bc8f 514 return err;
78bb3cb0
TI
515}
516
1da177e4 517
4a3fdf3d
TI
518/*
519 * AD1981 HD specific
520 */
1da177e4 521
a928bd2c
TI
522static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
523 const struct hda_fixup *fix, int action)
524{
525 struct ad198x_spec *spec = codec->spec;
526
527 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
528 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
529 spec->eapd_nid = 0x05;
530 }
531}
532
533/* set the upper-limit for mixer amp to 0dB for avoiding the possible
534 * damage by overloading
535 */
536static void ad1981_fixup_amp_override(struct hda_codec *codec,
537 const struct hda_fixup *fix, int action)
538{
539 if (action == HDA_FIXUP_ACT_PRE_PROBE)
540 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
541 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
542 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
543 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
544 (1 << AC_AMPCAP_MUTE_SHIFT));
545}
546
547enum {
548 AD1981_FIXUP_AMP_OVERRIDE,
549 AD1981_FIXUP_HP_EAPD,
550};
551
552static const struct hda_fixup ad1981_fixups[] = {
553 [AD1981_FIXUP_AMP_OVERRIDE] = {
554 .type = HDA_FIXUP_FUNC,
555 .v.func = ad1981_fixup_amp_override,
556 },
557 [AD1981_FIXUP_HP_EAPD] = {
558 .type = HDA_FIXUP_FUNC,
559 .v.func = ad1981_fixup_hp_eapd,
560 .chained = true,
561 .chain_id = AD1981_FIXUP_AMP_OVERRIDE,
562 },
563};
564
565static const struct snd_pci_quirk ad1981_fixup_tbl[] = {
566 SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
567 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD),
568 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE),
569 /* HP nx6320 (reversed SSID, H/W bug) */
570 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD),
571 {}
572};
573
bd450dcc 574static int patch_ad1981(struct hda_codec *codec)
78bb3cb0 575{
9ff4bc8f 576 struct ad198x_spec *spec;
272f3ea3 577 int err;
78bb3cb0 578
9ff4bc8f
TI
579 err = alloc_ad_spec(codec);
580 if (err < 0)
581 return -ENOMEM;
582 spec = codec->spec;
583
f2f8be43 584 spec->gen.mixer_nid = 0x0e;
7504b6cd 585 spec->gen.beep_nid = 0x10;
78bb3cb0 586 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
a928bd2c
TI
587
588 snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups);
589 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
590
cbd209f4 591 err = ad198x_parse_auto_config(codec, false);
272f3ea3 592 if (err < 0)
9ff4bc8f 593 goto error;
272f3ea3
TI
594 err = ad1983_add_spdif_mux_ctl(codec);
595 if (err < 0)
9ff4bc8f 596 goto error;
a928bd2c
TI
597
598 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
599
272f3ea3 600 return 0;
9ff4bc8f
TI
601
602 error:
7504b6cd 603 snd_hda_gen_free(codec);
9ff4bc8f 604 return err;
78bb3cb0
TI
605}
606
4a3fdf3d 607
fd66e0d0
TI
608/*
609 * AD1988
610 *
611 * Output pins and routes
612 *
d32410b1 613 * Pin Mix Sel DAC (*)
fd66e0d0
TI
614 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
615 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
616 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
617 * port-D 0x12 (mute/hp) <- 0x29 <- 04
618 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
619 * port-F 0x16 (mute) <- 0x2a <- 06
620 * port-G 0x24 (mute) <- 0x27 <- 05
621 * port-H 0x25 (mute) <- 0x28 <- 0a
622 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
623 *
d32410b1
TI
624 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
625 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
fd66e0d0
TI
626 *
627 * Input pins and routes
628 *
629 * pin boost mix input # / adc input #
630 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
631 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
632 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
633 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
634 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
635 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
636 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
637 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
638 *
639 *
640 * DAC assignment
d32410b1 641 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
f8c7c7b8 642 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
fd66e0d0
TI
643 *
644 * Inputs of Analog Mix (0x20)
645 * 0:Port-B (front mic)
646 * 1:Port-C/G/H (line-in)
647 * 2:Port-A
648 * 3:Port-D (line-in/2)
649 * 4:Port-E/G/H (mic-in)
650 * 5:Port-F (mic2-in)
651 * 6:CD
652 * 7:Beep
653 *
654 * ADC selection
655 * 0:Port-A
656 * 1:Port-B (front mic-in)
657 * 2:Port-C (line-in)
658 * 3:Port-F (mic2-in)
659 * 4:Port-E (mic-in)
660 * 5:CD
661 * 6:Port-G
662 * 7:Port-H
663 * 8:Port-D (line-in/2)
664 * 9:Mix
665 *
666 * Proposed pin assignments by the datasheet
667 *
668 * 6-stack
669 * Port-A front headphone
670 * B front mic-in
671 * C rear line-in
672 * D rear front-out
673 * E rear mic-in
674 * F rear surround
675 * G rear CLFE
676 * H rear side
677 *
678 * 3-stack
679 * Port-A front headphone
680 * B front mic
681 * C rear line-in/surround
682 * D rear front-out
683 * E rear mic-in/CLFE
684 *
685 * laptop
686 * Port-A headphone
687 * B mic-in
688 * C docking station
689 * D internal speaker (with EAPD)
690 * E/F quad mic array
691 */
692
9ff4bc8f 693#ifdef ENABLE_AD_STATIC_QUIRKS
fd66e0d0
TI
694static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_info *uinfo)
696{
697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
698 struct ad198x_spec *spec = codec->spec;
699 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
700 spec->num_channel_mode);
701}
702
703static int ad198x_ch_mode_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 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
709 spec->num_channel_mode, spec->multiout.max_channels);
710}
711
712static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
713 struct snd_ctl_elem_value *ucontrol)
714{
715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
716 struct ad198x_spec *spec = codec->spec;
4e195a7b
TI
717 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
718 spec->num_channel_mode,
719 &spec->multiout.max_channels);
bd2033f2 720 if (err >= 0 && spec->need_dac_fix)
2125cad2 721 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4e195a7b 722 return err;
fd66e0d0 723}
9ff4bc8f 724#endif /* ENABLE_AD_STATIC_QUIRKS */
fd66e0d0 725
272f3ea3
TI
726static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol,
727 struct snd_ctl_elem_info *uinfo)
728{
729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730 static const char * const texts[] = {
731 "PCM", "ADC1", "ADC2", "ADC3",
732 };
733 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
734 if (num_conns > 4)
735 num_conns = 4;
736 return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts);
737}
738
739static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol,
740 struct snd_ctl_elem_value *ucontrol)
741{
742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
743 struct ad198x_spec *spec = codec->spec;
744
745 ucontrol->value.enumerated.item[0] = spec->cur_smux;
746 return 0;
747}
748
749static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
751{
752 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
753 struct ad198x_spec *spec = codec->spec;
754 unsigned int val = ucontrol->value.enumerated.item[0];
755 struct nid_path *path;
756 int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
757
758 if (val >= num_conns)
759 return -EINVAL;
760 if (spec->cur_smux == val)
761 return 0;
762
763 mutex_lock(&codec->control_mutex);
764 codec->cached_write = 1;
765 path = snd_hda_get_path_from_idx(codec,
766 spec->smux_paths[spec->cur_smux]);
767 if (path)
768 snd_hda_activate_path(codec, path, false, true);
769 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]);
770 if (path)
771 snd_hda_activate_path(codec, path, true, true);
772 spec->cur_smux = val;
773 codec->cached_write = 0;
774 mutex_unlock(&codec->control_mutex);
775 snd_hda_codec_flush_cache(codec); /* flush the updates */
776 return 1;
777}
778
779static struct snd_kcontrol_new ad1988_auto_smux_mixer = {
780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
781 .name = "IEC958 Playback Source",
782 .info = ad1988_auto_smux_enum_info,
783 .get = ad1988_auto_smux_enum_get,
784 .put = ad1988_auto_smux_enum_put,
785};
786
787static int ad1988_auto_init(struct hda_codec *codec)
788{
789 struct ad198x_spec *spec = codec->spec;
790 int i, err;
791
792 err = snd_hda_gen_init(codec);
793 if (err < 0)
794 return err;
795 if (!spec->gen.autocfg.dig_outs)
796 return 0;
797
798 for (i = 0; i < 4; i++) {
799 struct nid_path *path;
800 path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]);
801 if (path)
802 snd_hda_activate_path(codec, path, path->active, false);
803 }
804
805 return 0;
806}
807
808static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec)
809{
810 struct ad198x_spec *spec = codec->spec;
811 int i, num_conns;
812 /* we create four static faked paths, since AD codecs have odd
813 * widget connections regarding the SPDIF out source
814 */
815 static struct nid_path fake_paths[4] = {
816 {
817 .depth = 3,
818 .path = { 0x02, 0x1d, 0x1b },
819 .idx = { 0, 0, 0 },
820 .multi = { 0, 0, 0 },
821 },
822 {
823 .depth = 4,
824 .path = { 0x08, 0x0b, 0x1d, 0x1b },
825 .idx = { 0, 0, 1, 0 },
826 .multi = { 0, 1, 0, 0 },
827 },
828 {
829 .depth = 4,
830 .path = { 0x09, 0x0b, 0x1d, 0x1b },
831 .idx = { 0, 1, 1, 0 },
832 .multi = { 0, 1, 0, 0 },
833 },
834 {
835 .depth = 4,
836 .path = { 0x0f, 0x0b, 0x1d, 0x1b },
837 .idx = { 0, 2, 1, 0 },
838 .multi = { 0, 1, 0, 0 },
839 },
840 };
841
842 /* SPDIF source mux appears to be present only on AD1988A */
843 if (!spec->gen.autocfg.dig_outs ||
844 get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX)
845 return 0;
846
847 num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1;
848 if (num_conns != 3 && num_conns != 4)
849 return 0;
850
851 for (i = 0; i < num_conns; i++) {
852 struct nid_path *path = snd_array_new(&spec->gen.paths);
853 if (!path)
854 return -ENOMEM;
855 *path = fake_paths[i];
856 if (!i)
857 path->active = 1;
858 spec->smux_paths[i] = snd_hda_get_path_idx(codec, path);
859 }
860
861 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer))
862 return -ENOMEM;
863
864 codec->patch_ops.init = ad1988_auto_init;
865
866 return 0;
867}
868
d32410b1 869/*
d32410b1
TI
870 */
871
36ad4530
TI
872enum {
873 AD1988_FIXUP_6STACK_DIG,
874};
875
876static const struct hda_fixup ad1988_fixups[] = {
877 [AD1988_FIXUP_6STACK_DIG] = {
878 .type = HDA_FIXUP_PINS,
879 .v.pins = (const struct hda_pintbl[]) {
880 { 0x11, 0x02214130 }, /* front-hp */
881 { 0x12, 0x01014010 }, /* line-out */
882 { 0x14, 0x02a19122 }, /* front-mic */
883 { 0x15, 0x01813021 }, /* line-in */
884 { 0x16, 0x01011012 }, /* line-out */
885 { 0x17, 0x01a19020 }, /* mic */
886 { 0x1b, 0x0145f1f0 }, /* SPDIF */
887 { 0x24, 0x01016011 }, /* line-out */
888 { 0x25, 0x01012013 }, /* line-out */
889 { }
890 }
891 },
892};
893
894static const struct hda_model_fixup ad1988_fixup_models[] = {
895 { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" },
896 {}
897};
898
899static int patch_ad1988(struct hda_codec *codec)
d32410b1 900{
9ff4bc8f 901 struct ad198x_spec *spec;
272f3ea3 902 int err;
d32410b1 903
9ff4bc8f
TI
904 err = alloc_ad_spec(codec);
905 if (err < 0)
906 return err;
907 spec = codec->spec;
908
f2f8be43 909 spec->gen.mixer_nid = 0x20;
e4a395e7 910 spec->gen.mixer_merge_nid = 0x21;
7504b6cd 911 spec->gen.beep_nid = 0x10;
78bb3cb0 912 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
36ad4530
TI
913
914 snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups);
915 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
916
cbd209f4 917 err = ad198x_parse_auto_config(codec, true);
272f3ea3 918 if (err < 0)
9ff4bc8f 919 goto error;
272f3ea3
TI
920 err = ad1988_add_spdif_mux_ctl(codec);
921 if (err < 0)
9ff4bc8f 922 goto error;
36ad4530
TI
923
924 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
925
272f3ea3 926 return 0;
9ff4bc8f
TI
927
928 error:
7504b6cd 929 snd_hda_gen_free(codec);
9ff4bc8f 930 return err;
d32410b1
TI
931}
932
fd66e0d0 933
2bac647c
TI
934/*
935 * AD1884 / AD1984
936 *
937 * port-B - front line/mic-in
938 * port-E - aux in/out
939 * port-F - aux in/out
940 * port-C - rear line/mic-in
941 * port-D - rear line/hp-out
942 * port-A - front line/hp-out
943 *
944 * AD1984 = AD1884 + two digital mic-ins
945 *
5ccc618f
TI
946 * AD1883 / AD1884A / AD1984A / AD1984B
947 *
948 * port-B (0x14) - front mic-in
949 * port-E (0x1c) - rear mic-in
950 * port-F (0x16) - CD / ext out
951 * port-C (0x15) - rear line-in
952 * port-D (0x12) - rear line-out
953 * port-A (0x11) - front hp-out
954 *
955 * AD1984A = AD1884A + digital-mic
956 * AD1883 = equivalent with AD1984A
957 * AD1984B = AD1984A + extra SPDIF-out
2bac647c 958 */
a928bd2c
TI
959
960/* set the upper-limit for mixer amp to 0dB for avoiding the possible
961 * damage by overloading
962 */
963static void ad1884_fixup_amp_override(struct hda_codec *codec,
964 const struct hda_fixup *fix, int action)
965{
966 if (action == HDA_FIXUP_ACT_PRE_PROBE)
967 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
968 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
969 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
970 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
971 (1 << AC_AMPCAP_MUTE_SHIFT));
972}
973
1a39b5e1
TI
974/* toggle GPIO1 according to the mute state */
975static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled)
976{
977 struct hda_codec *codec = private_data;
978 struct ad198x_spec *spec = codec->spec;
979
980 if (spec->eapd_nid)
981 ad_vmaster_eapd_hook(private_data, enabled);
982 snd_hda_codec_update_cache(codec, 0x01, 0,
983 AC_VERB_SET_GPIO_DATA,
984 enabled ? 0x00 : 0x02);
985}
986
a928bd2c
TI
987static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
988 const struct hda_fixup *fix, int action)
989{
990 struct ad198x_spec *spec = codec->spec;
1a39b5e1
TI
991 static const struct hda_verb gpio_init_verbs[] = {
992 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
993 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
994 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
995 {},
996 };
a928bd2c 997
8f0b3b7e
TI
998 switch (action) {
999 case HDA_FIXUP_ACT_PRE_PROBE:
1a39b5e1 1000 spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook;
1cd9b2f7 1001 spec->gen.own_eapd_ctl = 1;
1a39b5e1 1002 snd_hda_sequence_write_cache(codec, gpio_init_verbs);
8f0b3b7e
TI
1003 break;
1004 case HDA_FIXUP_ACT_PROBE:
a928bd2c
TI
1005 if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1006 spec->eapd_nid = spec->gen.autocfg.line_out_pins[0];
1007 else
1008 spec->eapd_nid = spec->gen.autocfg.speaker_pins[0];
8f0b3b7e 1009 break;
a928bd2c
TI
1010 }
1011}
1012
1ac32930
TI
1013static void ad1884_fixup_thinkpad(struct hda_codec *codec,
1014 const struct hda_fixup *fix, int action)
1015{
1016 struct ad198x_spec *spec = codec->spec;
1017
afb5a779 1018 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1ac32930 1019 spec->gen.keep_eapd_on = 1;
afb5a779
TI
1020 spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
1021 spec->eapd_nid = 0x12;
1022 }
1ac32930
TI
1023}
1024
6a699bec
TI
1025/* set magic COEFs for dmic */
1026static const struct hda_verb ad1884_dmic_init_verbs[] = {
1027 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
1028 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
1029 {}
1030};
1031
a928bd2c
TI
1032enum {
1033 AD1884_FIXUP_AMP_OVERRIDE,
1034 AD1884_FIXUP_HP_EAPD,
6a699bec 1035 AD1884_FIXUP_DMIC_COEF,
1ac32930 1036 AD1884_FIXUP_THINKPAD,
f404627d 1037 AD1884_FIXUP_HP_TOUCHSMART,
a928bd2c
TI
1038};
1039
1040static const struct hda_fixup ad1884_fixups[] = {
1041 [AD1884_FIXUP_AMP_OVERRIDE] = {
1042 .type = HDA_FIXUP_FUNC,
1043 .v.func = ad1884_fixup_amp_override,
1044 },
1045 [AD1884_FIXUP_HP_EAPD] = {
1046 .type = HDA_FIXUP_FUNC,
1047 .v.func = ad1884_fixup_hp_eapd,
1048 .chained = true,
1049 .chain_id = AD1884_FIXUP_AMP_OVERRIDE,
1050 },
6a699bec
TI
1051 [AD1884_FIXUP_DMIC_COEF] = {
1052 .type = HDA_FIXUP_VERBS,
1053 .v.verbs = ad1884_dmic_init_verbs,
1054 },
1ac32930
TI
1055 [AD1884_FIXUP_THINKPAD] = {
1056 .type = HDA_FIXUP_FUNC,
1057 .v.func = ad1884_fixup_thinkpad,
1058 .chained = true,
1059 .chain_id = AD1884_FIXUP_DMIC_COEF,
1060 },
f404627d
TI
1061 [AD1884_FIXUP_HP_TOUCHSMART] = {
1062 .type = HDA_FIXUP_VERBS,
1063 .v.verbs = ad1884_dmic_init_verbs,
1064 .chained = true,
1065 .chain_id = AD1884_FIXUP_HP_EAPD,
1066 },
a928bd2c
TI
1067};
1068
1069static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
f404627d 1070 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
a928bd2c 1071 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1ac32930 1072 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
a928bd2c
TI
1073 {}
1074};
1075
1076
5ccc618f 1077static int patch_ad1884(struct hda_codec *codec)
78bb3cb0 1078{
9ff4bc8f 1079 struct ad198x_spec *spec;
272f3ea3 1080 int err;
78bb3cb0 1081
9ff4bc8f
TI
1082 err = alloc_ad_spec(codec);
1083 if (err < 0)
1084 return err;
1085 spec = codec->spec;
1086
f2f8be43 1087 spec->gen.mixer_nid = 0x20;
7504b6cd 1088 spec->gen.beep_nid = 0x10;
78bb3cb0 1089 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
a928bd2c
TI
1090
1091 snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups);
1092 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1093
cbd209f4 1094 err = ad198x_parse_auto_config(codec, true);
272f3ea3 1095 if (err < 0)
9ff4bc8f 1096 goto error;
272f3ea3
TI
1097 err = ad1983_add_spdif_mux_ctl(codec);
1098 if (err < 0)
9ff4bc8f 1099 goto error;
a928bd2c
TI
1100
1101 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1102
272f3ea3 1103 return 0;
78bb3cb0 1104
9ff4bc8f 1105 error:
7504b6cd 1106 snd_hda_gen_free(codec);
9ff4bc8f 1107 return err;
78bb3cb0
TI
1108}
1109
0ac8551e 1110/*
9e44c6e4 1111 * AD1882 / AD1882A
0ac8551e
TI
1112 *
1113 * port-A - front hp-out
1114 * port-B - front mic-in
1115 * port-C - rear line-in, shared surr-out (3stack)
1116 * port-D - rear line-out
1117 * port-E - rear mic-in, shared clfe-out (3stack)
1118 * port-F - rear surr-out (6stack)
1119 * port-G - rear clfe-out (6stack)
1120 */
1121
aa95d61b 1122static int patch_ad1882(struct hda_codec *codec)
78bb3cb0 1123{
9ff4bc8f 1124 struct ad198x_spec *spec;
272f3ea3 1125 int err;
78bb3cb0 1126
9ff4bc8f
TI
1127 err = alloc_ad_spec(codec);
1128 if (err < 0)
1129 return err;
1130 spec = codec->spec;
1131
f2f8be43 1132 spec->gen.mixer_nid = 0x20;
e4a395e7 1133 spec->gen.mixer_merge_nid = 0x21;
7504b6cd 1134 spec->gen.beep_nid = 0x10;
78bb3cb0 1135 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
cbd209f4 1136 err = ad198x_parse_auto_config(codec, true);
272f3ea3 1137 if (err < 0)
9ff4bc8f 1138 goto error;
272f3ea3
TI
1139 err = ad1988_add_spdif_mux_ctl(codec);
1140 if (err < 0)
9ff4bc8f 1141 goto error;
272f3ea3 1142 return 0;
9ff4bc8f
TI
1143
1144 error:
7504b6cd 1145 snd_hda_gen_free(codec);
9ff4bc8f 1146 return err;
78bb3cb0 1147}
0ac8551e 1148
0ac8551e 1149
1da177e4
LT
1150/*
1151 * patch entries
1152 */
498f5b17 1153static const struct hda_codec_preset snd_hda_preset_analog[] = {
5ccc618f 1154 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 },
0ac8551e 1155 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
5ccc618f 1156 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 },
2bac647c 1157 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
5ccc618f
TI
1158 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 },
1159 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 },
4a3fdf3d
TI
1160 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
1161 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
5ccc618f 1162 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 },
1da177e4 1163 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
fd66e0d0 1164 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
71b2ccc3 1165 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
9e44c6e4 1166 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
3adb8abc
TI
1167 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
1168 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1da177e4
LT
1169 {} /* terminator */
1170};
1289e9e8
TI
1171
1172MODULE_ALIAS("snd-hda-codec-id:11d4*");
1173
1174MODULE_LICENSE("GPL");
1175MODULE_DESCRIPTION("Analog Devices HD-audio codec");
1176
1177static struct hda_codec_preset_list analog_list = {
1178 .preset = snd_hda_preset_analog,
1179 .owner = THIS_MODULE,
1180};
1181
1182static int __init patch_analog_init(void)
1183{
1184 return snd_hda_add_codec_preset(&analog_list);
1185}
1186
1187static void __exit patch_analog_exit(void)
1188{
1189 snd_hda_delete_codec_preset(&analog_list);
1190}
1191
1192module_init(patch_analog_init)
1193module_exit(patch_analog_exit)
This page took 0.721042 seconds and 5 git commands to generate.