2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for SigmaTel STAC92xx
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
7 * Matt Porter <mporter@embeddedalley.com>
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <sound/driver.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
32 #include <sound/core.h>
33 #include <sound/asoundef.h>
34 #include "hda_codec.h"
35 #include "hda_local.h"
37 #define NUM_CONTROL_ALLOC 32
38 #define STAC_HP_EVENT 0x37
81 /* for backward compatibility */
103 struct sigmatel_spec {
104 struct snd_kcontrol_new *mixers[4];
105 unsigned int num_mixers;
108 unsigned int surr_switch: 1;
109 unsigned int line_switch: 1;
110 unsigned int mic_switch: 1;
111 unsigned int alt_switch: 1;
112 unsigned int hp_detect: 1;
113 unsigned int gpio_mute: 1;
115 unsigned int gpio_mask, gpio_data;
118 struct hda_multi_out multiout;
119 hda_nid_t dac_nids[5];
123 unsigned int num_adcs;
125 unsigned int num_muxes;
126 hda_nid_t *dmic_nids;
127 unsigned int num_dmics;
129 hda_nid_t dig_in_nid;
133 unsigned int num_pins;
134 unsigned int *pin_configs;
135 unsigned int *bios_pin_configs;
137 /* codec specific stuff */
138 struct hda_verb *init;
139 struct snd_kcontrol_new *mixer;
142 struct hda_input_mux *dinput_mux;
143 unsigned int cur_dmux;
144 struct hda_input_mux *input_mux;
145 unsigned int cur_mux[3];
148 unsigned int io_switch[2];
149 unsigned int clfe_swap;
151 struct hda_pcm pcm_rec[2]; /* PCM information */
153 /* dynamic controls and input_mux */
154 struct auto_pin_cfg autocfg;
155 unsigned int num_kctl_alloc, num_kctl_used;
156 struct snd_kcontrol_new *kctl_alloc;
157 struct hda_input_mux private_dimux;
158 struct hda_input_mux private_imux;
161 static hda_nid_t stac9200_adc_nids[1] = {
165 static hda_nid_t stac9200_mux_nids[1] = {
169 static hda_nid_t stac9200_dac_nids[1] = {
173 static hda_nid_t stac925x_adc_nids[1] = {
177 static hda_nid_t stac925x_mux_nids[1] = {
181 static hda_nid_t stac925x_dac_nids[1] = {
185 static hda_nid_t stac925x_dmic_nids[1] = {
189 static hda_nid_t stac922x_adc_nids[2] = {
193 static hda_nid_t stac922x_mux_nids[2] = {
197 static hda_nid_t stac927x_adc_nids[3] = {
201 static hda_nid_t stac927x_mux_nids[3] = {
205 static hda_nid_t stac9205_adc_nids[2] = {
209 static hda_nid_t stac9205_mux_nids[2] = {
213 static hda_nid_t stac9205_dmic_nids[2] = {
217 static hda_nid_t stac9200_pin_nids[8] = {
218 0x08, 0x09, 0x0d, 0x0e,
219 0x0f, 0x10, 0x11, 0x12,
222 static hda_nid_t stac925x_pin_nids[8] = {
223 0x07, 0x08, 0x0a, 0x0b,
224 0x0c, 0x0d, 0x10, 0x11,
227 static hda_nid_t stac922x_pin_nids[10] = {
228 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
229 0x0f, 0x10, 0x11, 0x15, 0x1b,
232 static hda_nid_t stac927x_pin_nids[14] = {
233 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
234 0x0f, 0x10, 0x11, 0x12, 0x13,
235 0x14, 0x21, 0x22, 0x23,
238 static hda_nid_t stac9205_pin_nids[12] = {
239 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
240 0x0f, 0x14, 0x16, 0x17, 0x18,
244 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_info *uinfo)
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct sigmatel_spec *spec = codec->spec;
249 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
252 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
253 struct snd_ctl_elem_value *ucontrol)
255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
256 struct sigmatel_spec *spec = codec->spec;
258 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
262 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
265 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
266 struct sigmatel_spec *spec = codec->spec;
268 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
269 spec->dmux_nid, &spec->cur_dmux);
272 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
274 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
275 struct sigmatel_spec *spec = codec->spec;
276 return snd_hda_input_mux_info(spec->input_mux, uinfo);
279 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
282 struct sigmatel_spec *spec = codec->spec;
283 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
285 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
289 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
292 struct sigmatel_spec *spec = codec->spec;
293 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
295 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
296 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
299 static struct hda_verb stac9200_core_init[] = {
300 /* set dac0mux for dac converter */
301 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
305 static struct hda_verb stac925x_core_init[] = {
306 /* set dac0mux for dac converter */
307 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
311 static struct hda_verb stac922x_core_init[] = {
312 /* set master volume and direct control */
313 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
317 static struct hda_verb d965_core_init[] = {
318 /* set master volume and direct control */
319 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
320 /* unmute node 0x1b */
321 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
322 /* select node 0x03 as DAC */
323 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
327 static struct hda_verb stac927x_core_init[] = {
328 /* set master volume and direct control */
329 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
333 static struct hda_verb stac9205_core_init[] = {
334 /* set master volume and direct control */
335 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
339 #define STAC_INPUT_SOURCE \
341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
342 .name = "Input Source", \
344 .info = stac92xx_mux_enum_info, \
345 .get = stac92xx_mux_enum_get, \
346 .put = stac92xx_mux_enum_put, \
350 static struct snd_kcontrol_new stac9200_mixer[] = {
351 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
352 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
354 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
355 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
356 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
360 static struct snd_kcontrol_new stac925x_mixer[] = {
362 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
363 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
364 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
368 /* This needs to be generated dynamically based on sequence */
369 static struct snd_kcontrol_new stac922x_mixer[] = {
371 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
372 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
373 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
377 /* This needs to be generated dynamically based on sequence */
378 static struct snd_kcontrol_new stac9227_mixer[] = {
380 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
381 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
385 static struct snd_kcontrol_new stac927x_mixer[] = {
387 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
388 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
389 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
393 static struct snd_kcontrol_new stac9205_mixer[] = {
395 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
396 .name = "Digital Input Source",
398 .info = stac92xx_dmux_enum_info,
399 .get = stac92xx_dmux_enum_get,
400 .put = stac92xx_dmux_enum_put,
403 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
404 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
405 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
409 static int stac92xx_build_controls(struct hda_codec *codec)
411 struct sigmatel_spec *spec = codec->spec;
415 err = snd_hda_add_new_ctls(codec, spec->mixer);
419 for (i = 0; i < spec->num_mixers; i++) {
420 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
425 if (spec->multiout.dig_out_nid) {
426 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
430 if (spec->dig_in_nid) {
431 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
438 static unsigned int ref9200_pin_configs[8] = {
439 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
440 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
444 STAC 9200 pin configs for
449 static unsigned int dell9200_d21_pin_configs[8] = {
450 0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
451 0x01813122, 0x02214030, 0x01014010, 0x02a19020,
455 STAC 9200 pin configs for
459 static unsigned int dell9200_d22_pin_configs[8] = {
460 0x400001f0, 0x400001f1, 0x02a19021, 0x90100140,
461 0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
465 STAC 9200 pin configs for
466 102801C4 (Dell Dimension E310)
473 static unsigned int dell9200_d23_pin_configs[8] = {
474 0x400001f0, 0x400001f1, 0x01a19021, 0x90100140,
475 0x400001f2, 0x0221401f, 0x01014010, 0x01813020,
480 STAC 9200-32 pin configs for
481 102801B5 (Dell Inspiron 630m)
482 102801D8 (Dell Inspiron 640m)
484 static unsigned int dell9200_m21_pin_configs[8] = {
485 0x40c003fa, 0x03441340, 0x03a11020, 0x401003fc,
486 0x403003fd, 0x0321121f, 0x0321121f, 0x408003fb,
490 STAC 9200-32 pin configs for
491 102801C2 (Dell Latitude D620)
493 102801CC (Dell Latitude D820)
497 static unsigned int dell9200_m22_pin_configs[8] = {
498 0x40c003fa, 0x0144131f, 0x03A11020, 0x401003fb,
499 0x40f000fc, 0x0321121f, 0x90170310, 0x90a70321,
503 STAC 9200-32 pin configs for
504 102801CE (Dell XPS M1710)
505 102801CF (Dell Precision M90)
507 static unsigned int dell9200_m23_pin_configs[8] = {
508 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
509 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
513 STAC 9200-32 pin configs for
516 102801CB (Dell Latitude 120L)
519 static unsigned int dell9200_m24_pin_configs[8] = {
520 0x40c003fa, 0x404003fb, 0x03a11020, 0x401003fd,
521 0x403003fe, 0x0321121f, 0x90170310, 0x408003fc,
525 STAC 9200-32 pin configs for
526 102801BD (Dell Inspiron E1505n)
530 static unsigned int dell9200_m25_pin_configs[8] = {
531 0x40c003fa, 0x01441340, 0x04a11020, 0x401003fc,
532 0x403003fd, 0x0421121f, 0x90170310, 0x408003fb,
536 STAC 9200-32 pin configs for
537 102801F5 (Dell Inspiron 1501)
540 static unsigned int dell9200_m26_pin_configs[8] = {
541 0x40c003fa, 0x404003fb, 0x04a11020, 0x401003fd,
542 0x403003fe, 0x0421121f, 0x90170310, 0x408003fc,
547 102801CD (Dell Inspiron E1705/9400)
549 static unsigned int dell9200_m27_pin_configs[8] = {
550 0x40c003fa, 0x01441340, 0x04a11020, 0x90170310,
551 0x40f003fc, 0x0421121f, 0x90170310, 0x408003fb,
555 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
556 [STAC_REF] = ref9200_pin_configs,
557 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
558 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
559 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
560 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
561 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
562 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
563 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
564 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
565 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
566 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
569 static const char *stac9200_models[STAC_9200_MODELS] = {
571 [STAC_9200_DELL_D21] = "dell-d21",
572 [STAC_9200_DELL_D22] = "dell-d22",
573 [STAC_9200_DELL_D23] = "dell-d23",
574 [STAC_9200_DELL_M21] = "dell-m21",
575 [STAC_9200_DELL_M22] = "dell-m22",
576 [STAC_9200_DELL_M23] = "dell-m23",
577 [STAC_9200_DELL_M24] = "dell-m24",
578 [STAC_9200_DELL_M25] = "dell-m25",
579 [STAC_9200_DELL_M26] = "dell-m26",
580 [STAC_9200_DELL_M27] = "dell-m27",
583 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
584 /* SigmaTel reference board */
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
586 "DFI LanParty", STAC_REF),
587 /* Dell laptops have BIOS problem */
588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
589 "unknown Dell", STAC_9200_DELL_D21),
590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
591 "Dell Inspiron 630m", STAC_9200_DELL_M21),
592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
593 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
595 "unknown Dell", STAC_9200_DELL_D22),
596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
597 "unknown Dell", STAC_9200_DELL_D22),
598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
599 "Dell Latitude D620", STAC_9200_DELL_M22),
600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
601 "unknown Dell", STAC_9200_DELL_D23),
602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
603 "unknown Dell", STAC_9200_DELL_D23),
604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
605 "unknown Dell", STAC_9200_DELL_M22),
606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
607 "unknown Dell", STAC_9200_DELL_M24),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
609 "unknown Dell", STAC_9200_DELL_M24),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
611 "Dell Latitude 120L", STAC_9200_DELL_M24),
612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
613 "Dell Latitude D820", STAC_9200_DELL_M22),
614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
615 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
617 "Dell XPS M1710", STAC_9200_DELL_M23),
618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
619 "Dell Precision M90", STAC_9200_DELL_M23),
620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
621 "unknown Dell", STAC_9200_DELL_M22),
622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
623 "unknown Dell", STAC_9200_DELL_M22),
624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
625 "unknown Dell", STAC_9200_DELL_M22),
626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
627 "Dell Inspiron 640m", STAC_9200_DELL_M21),
628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
629 "unknown Dell", STAC_9200_DELL_D23),
630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
631 "unknown Dell", STAC_9200_DELL_D23),
632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
633 "unknown Dell", STAC_9200_DELL_D21),
634 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
635 "unknown Dell", STAC_9200_DELL_D23),
636 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
637 "unknown Dell", STAC_9200_DELL_D21),
638 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
639 "unknown Dell", STAC_9200_DELL_M25),
640 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
641 "unknown Dell", STAC_9200_DELL_M25),
642 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
643 "Dell Inspiron 1501", STAC_9200_DELL_M26),
644 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
645 "unknown Dell", STAC_9200_DELL_M26),
647 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
652 static unsigned int ref925x_pin_configs[8] = {
653 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
654 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
657 static unsigned int stac925x_MA6_pin_configs[8] = {
658 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
659 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
662 static unsigned int stac925x_PA6_pin_configs[8] = {
663 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
664 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
667 static unsigned int stac925xM2_2_pin_configs[8] = {
668 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
669 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
672 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
673 [STAC_REF] = ref925x_pin_configs,
674 [STAC_M2_2] = stac925xM2_2_pin_configs,
675 [STAC_MA6] = stac925x_MA6_pin_configs,
676 [STAC_PA6] = stac925x_PA6_pin_configs,
679 static const char *stac925x_models[STAC_925x_MODELS] = {
681 [STAC_M2_2] = "m2-2",
686 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
687 /* SigmaTel reference board */
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
689 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
690 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
691 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
692 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
693 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
694 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
698 static unsigned int ref922x_pin_configs[10] = {
699 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
700 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
701 0x40000100, 0x40000100,
705 STAC 922X pin configs for
712 static unsigned int dell_922x_d81_pin_configs[10] = {
713 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
714 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
715 0x01813122, 0x400001f2,
719 STAC 922X pin configs for
723 static unsigned int dell_922x_d82_pin_configs[10] = {
724 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
725 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
726 0x01813122, 0x400001f1,
730 STAC 922X pin configs for
733 static unsigned int dell_922x_m81_pin_configs[10] = {
734 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
735 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
736 0x40C003f1, 0x405003f0,
740 STAC 9221 A1 pin configs for
741 102801D7 (Dell XPS M1210)
743 static unsigned int dell_922x_m82_pin_configs[10] = {
744 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
745 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
746 0x508003f3, 0x405003f4,
749 static unsigned int d945gtp3_pin_configs[10] = {
750 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
751 0x40000100, 0x40000100, 0x40000100, 0x40000100,
752 0x02a19120, 0x40000100,
755 static unsigned int d945gtp5_pin_configs[10] = {
756 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
757 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
758 0x02a19320, 0x40000100,
761 static unsigned int intel_mac_v1_pin_configs[10] = {
762 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
763 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
764 0x400000fc, 0x400000fb,
767 static unsigned int intel_mac_v2_pin_configs[10] = {
768 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
769 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
770 0x400000fc, 0x400000fb,
773 static unsigned int intel_mac_v3_pin_configs[10] = {
774 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
775 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
776 0x400000fc, 0x400000fb,
779 static unsigned int intel_mac_v4_pin_configs[10] = {
780 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
781 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
782 0x400000fc, 0x400000fb,
785 static unsigned int intel_mac_v5_pin_configs[10] = {
786 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
787 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
788 0x400000fc, 0x400000fb,
792 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
793 [STAC_D945_REF] = ref922x_pin_configs,
794 [STAC_D945GTP3] = d945gtp3_pin_configs,
795 [STAC_D945GTP5] = d945gtp5_pin_configs,
796 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
797 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
798 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
799 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
800 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
801 /* for backward compatibility */
802 [STAC_MACMINI] = intel_mac_v3_pin_configs,
803 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
804 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
805 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
806 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
807 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
808 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
809 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
810 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
811 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
814 static const char *stac922x_models[STAC_922X_MODELS] = {
815 [STAC_D945_REF] = "ref",
816 [STAC_D945GTP5] = "5stack",
817 [STAC_D945GTP3] = "3stack",
818 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
819 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
820 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
821 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
822 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
823 /* for backward compatibility */
824 [STAC_MACMINI] = "macmini",
825 [STAC_MACBOOK] = "macbook",
826 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
827 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
828 [STAC_IMAC_INTEL] = "imac-intel",
829 [STAC_IMAC_INTEL_20] = "imac-intel-20",
830 [STAC_922X_DELL_D81] = "dell-d81",
831 [STAC_922X_DELL_D82] = "dell-d82",
832 [STAC_922X_DELL_M81] = "dell-m81",
833 [STAC_922X_DELL_M82] = "dell-m82",
836 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
837 /* SigmaTel reference board */
838 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
839 "DFI LanParty", STAC_D945_REF),
840 /* Intel 945G based systems */
841 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
842 "Intel D945G", STAC_D945GTP3),
843 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
844 "Intel D945G", STAC_D945GTP3),
845 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
846 "Intel D945G", STAC_D945GTP3),
847 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
848 "Intel D945G", STAC_D945GTP3),
849 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
850 "Intel D945G", STAC_D945GTP3),
851 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
852 "Intel D945G", STAC_D945GTP3),
853 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
854 "Intel D945G", STAC_D945GTP3),
855 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
856 "Intel D945G", STAC_D945GTP3),
857 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
858 "Intel D945G", STAC_D945GTP3),
859 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
860 "Intel D945G", STAC_D945GTP3),
861 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
862 "Intel D945G", STAC_D945GTP3),
863 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
864 "Intel D945G", STAC_D945GTP3),
865 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
866 "Intel D945G", STAC_D945GTP3),
867 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
868 "Intel D945G", STAC_D945GTP3),
869 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
870 "Intel D945G", STAC_D945GTP3),
871 /* Intel D945G 5-stack systems */
872 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
873 "Intel D945G", STAC_D945GTP5),
874 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
875 "Intel D945G", STAC_D945GTP5),
876 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
877 "Intel D945G", STAC_D945GTP5),
878 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
879 "Intel D945G", STAC_D945GTP5),
880 /* Intel 945P based systems */
881 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
882 "Intel D945P", STAC_D945GTP3),
883 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
884 "Intel D945P", STAC_D945GTP3),
885 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
886 "Intel D945P", STAC_D945GTP3),
887 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
888 "Intel D945P", STAC_D945GTP3),
889 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
890 "Intel D945P", STAC_D945GTP3),
891 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
892 "Intel D945P", STAC_D945GTP5),
894 /* Apple Mac Mini (early 2006) */
895 SND_PCI_QUIRK(0x8384, 0x7680,
896 "Mac Mini", STAC_INTEL_MAC_V3),
898 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
899 "unknown Dell", STAC_922X_DELL_D81),
900 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
901 "unknown Dell", STAC_922X_DELL_D81),
902 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
903 "unknown Dell", STAC_922X_DELL_D81),
904 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
905 "unknown Dell", STAC_922X_DELL_D82),
906 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
907 "unknown Dell", STAC_922X_DELL_M81),
908 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
909 "unknown Dell", STAC_922X_DELL_D82),
910 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
911 "unknown Dell", STAC_922X_DELL_D81),
912 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
913 "unknown Dell", STAC_922X_DELL_D81),
914 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
915 "Dell XPS M1210", STAC_922X_DELL_M82),
919 static unsigned int ref927x_pin_configs[14] = {
920 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
921 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
922 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
923 0x01c42190, 0x40000100,
926 static unsigned int d965_3st_pin_configs[14] = {
927 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
928 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
929 0x40000100, 0x40000100, 0x40000100, 0x40000100,
930 0x40000100, 0x40000100
933 static unsigned int d965_5st_pin_configs[14] = {
934 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
935 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
936 0x40000100, 0x40000100, 0x40000100, 0x01442070,
937 0x40000100, 0x40000100
940 static unsigned int dell_3st_pin_configs[14] = {
941 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
942 0x01111212, 0x01116211, 0x01813050, 0x01112214,
943 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
944 0x40c003fc, 0x40000100
947 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
948 [STAC_D965_REF] = ref927x_pin_configs,
949 [STAC_D965_3ST] = d965_3st_pin_configs,
950 [STAC_D965_5ST] = d965_5st_pin_configs,
951 [STAC_DELL_3ST] = dell_3st_pin_configs,
954 static const char *stac927x_models[STAC_927X_MODELS] = {
955 [STAC_D965_REF] = "ref",
956 [STAC_D965_3ST] = "3stack",
957 [STAC_D965_5ST] = "5stack",
958 [STAC_DELL_3ST] = "dell-3stack",
961 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
962 /* SigmaTel reference board */
963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
964 "DFI LanParty", STAC_D965_REF),
965 /* Intel 946 based systems */
966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
968 /* 965 based 3 stack systems */
969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
985 /* Dell 3 stack systems */
986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
988 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
989 /* 965 based 5 stack systems */
990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
1002 static unsigned int ref9205_pin_configs[12] = {
1003 0x40000100, 0x40000100, 0x01016011, 0x01014010,
1004 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1005 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
1009 STAC 9205 pin configs for
1017 static unsigned int dell_9205_m42_pin_configs[12] = {
1018 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1019 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1020 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1024 STAC 9205 pin configs for
1028 102801FF (Dell Precision M4300)
1033 static unsigned int dell_9205_m43_pin_configs[12] = {
1034 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1035 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1036 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1039 static unsigned int dell_9205_m44_pin_configs[12] = {
1040 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1041 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1042 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1045 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
1046 [STAC_9205_REF] = ref9205_pin_configs,
1047 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1048 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1049 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
1050 [STAC_9205_M43xx] = NULL,
1053 static const char *stac9205_models[STAC_9205_MODELS] = {
1054 [STAC_9205_REF] = "ref",
1055 [STAC_9205_DELL_M42] = "dell-m42",
1056 [STAC_9205_DELL_M43] = "dell-m43",
1057 [STAC_9205_DELL_M44] = "dell-m44",
1060 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1061 /* SigmaTel reference board */
1062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1063 "DFI LanParty", STAC_9205_REF),
1064 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1065 "unknown Dell", STAC_9205_DELL_M42),
1066 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1067 "unknown Dell", STAC_9205_DELL_M42),
1068 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
1069 "Dell Precision", STAC_9205_M43xx),
1070 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1071 "Dell Precision", STAC_9205_DELL_M43),
1072 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1073 "Dell Precision", STAC_9205_DELL_M43),
1074 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1075 "unknown Dell", STAC_9205_DELL_M42),
1076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1077 "unknown Dell", STAC_9205_DELL_M42),
1078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1079 "Dell Precision", STAC_9205_DELL_M43),
1080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
1081 "Dell Precision M4300", STAC_9205_DELL_M43),
1082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1083 "Dell Precision", STAC_9205_DELL_M43),
1084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1085 "Dell Inspiron", STAC_9205_DELL_M44),
1086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1087 "Dell Inspiron", STAC_9205_DELL_M44),
1088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1089 "Dell Inspiron", STAC_9205_DELL_M44),
1090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1091 "Dell Inspiron", STAC_9205_DELL_M44),
1092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1093 "unknown Dell", STAC_9205_DELL_M42),
1094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1095 "Dell Inspiron", STAC_9205_DELL_M44),
1099 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1102 struct sigmatel_spec *spec = codec->spec;
1104 if (! spec->bios_pin_configs) {
1105 spec->bios_pin_configs = kcalloc(spec->num_pins,
1106 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1107 if (! spec->bios_pin_configs)
1111 for (i = 0; i < spec->num_pins; i++) {
1112 hda_nid_t nid = spec->pin_nids[i];
1113 unsigned int pin_cfg;
1115 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1116 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1117 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1119 spec->bios_pin_configs[i] = pin_cfg;
1125 static void stac92xx_set_config_reg(struct hda_codec *codec,
1126 hda_nid_t pin_nid, unsigned int pin_config)
1129 snd_hda_codec_write(codec, pin_nid, 0,
1130 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1131 pin_config & 0x000000ff);
1132 snd_hda_codec_write(codec, pin_nid, 0,
1133 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1134 (pin_config & 0x0000ff00) >> 8);
1135 snd_hda_codec_write(codec, pin_nid, 0,
1136 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1137 (pin_config & 0x00ff0000) >> 16);
1138 snd_hda_codec_write(codec, pin_nid, 0,
1139 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1141 i = snd_hda_codec_read(codec, pin_nid, 0,
1142 AC_VERB_GET_CONFIG_DEFAULT,
1144 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1148 static void stac92xx_set_config_regs(struct hda_codec *codec)
1151 struct sigmatel_spec *spec = codec->spec;
1153 if (!spec->pin_configs)
1156 for (i = 0; i < spec->num_pins; i++)
1157 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1158 spec->pin_configs[i]);
1161 static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
1163 struct sigmatel_spec *spec = codec->spec;
1164 /* Configure GPIOx as output */
1165 snd_hda_codec_write_cache(codec, codec->afg, 0,
1166 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
1167 /* Configure GPIOx as CMOS */
1168 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
1170 snd_hda_codec_write_cache(codec, codec->afg, 0,
1171 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
1173 snd_hda_codec_write_cache(codec, codec->afg, 0,
1174 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
1178 * Analog playback callbacks
1180 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1181 struct hda_codec *codec,
1182 struct snd_pcm_substream *substream)
1184 struct sigmatel_spec *spec = codec->spec;
1185 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1188 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1189 struct hda_codec *codec,
1190 unsigned int stream_tag,
1191 unsigned int format,
1192 struct snd_pcm_substream *substream)
1194 struct sigmatel_spec *spec = codec->spec;
1195 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
1198 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1199 struct hda_codec *codec,
1200 struct snd_pcm_substream *substream)
1202 struct sigmatel_spec *spec = codec->spec;
1203 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1207 * Digital playback callbacks
1209 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1210 struct hda_codec *codec,
1211 struct snd_pcm_substream *substream)
1213 struct sigmatel_spec *spec = codec->spec;
1214 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1217 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1218 struct hda_codec *codec,
1219 struct snd_pcm_substream *substream)
1221 struct sigmatel_spec *spec = codec->spec;
1222 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1225 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1226 struct hda_codec *codec,
1227 unsigned int stream_tag,
1228 unsigned int format,
1229 struct snd_pcm_substream *substream)
1231 struct sigmatel_spec *spec = codec->spec;
1232 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1233 stream_tag, format, substream);
1238 * Analog capture callbacks
1240 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1241 struct hda_codec *codec,
1242 unsigned int stream_tag,
1243 unsigned int format,
1244 struct snd_pcm_substream *substream)
1246 struct sigmatel_spec *spec = codec->spec;
1248 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1249 stream_tag, 0, format);
1253 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1254 struct hda_codec *codec,
1255 struct snd_pcm_substream *substream)
1257 struct sigmatel_spec *spec = codec->spec;
1259 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1263 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1267 /* NID is set in stac92xx_build_pcms */
1269 .open = stac92xx_dig_playback_pcm_open,
1270 .close = stac92xx_dig_playback_pcm_close,
1271 .prepare = stac92xx_dig_playback_pcm_prepare
1275 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1279 /* NID is set in stac92xx_build_pcms */
1282 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1286 .nid = 0x02, /* NID to query formats and rates */
1288 .open = stac92xx_playback_pcm_open,
1289 .prepare = stac92xx_playback_pcm_prepare,
1290 .cleanup = stac92xx_playback_pcm_cleanup
1294 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1298 .nid = 0x06, /* NID to query formats and rates */
1300 .open = stac92xx_playback_pcm_open,
1301 .prepare = stac92xx_playback_pcm_prepare,
1302 .cleanup = stac92xx_playback_pcm_cleanup
1306 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
1310 /* NID is set in stac92xx_build_pcms */
1312 .prepare = stac92xx_capture_pcm_prepare,
1313 .cleanup = stac92xx_capture_pcm_cleanup
1317 static int stac92xx_build_pcms(struct hda_codec *codec)
1319 struct sigmatel_spec *spec = codec->spec;
1320 struct hda_pcm *info = spec->pcm_rec;
1322 codec->num_pcms = 1;
1323 codec->pcm_info = info;
1325 info->name = "STAC92xx Analog";
1326 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
1327 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
1328 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1330 if (spec->alt_switch) {
1333 info->name = "STAC92xx Analog Alt";
1334 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1337 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1340 info->name = "STAC92xx Digital";
1341 if (spec->multiout.dig_out_nid) {
1342 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1343 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1345 if (spec->dig_in_nid) {
1346 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1347 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1354 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1356 unsigned int pincap = snd_hda_param_read(codec, nid,
1358 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1359 if (pincap & AC_PINCAP_VREF_100)
1360 return AC_PINCTL_VREF_100;
1361 if (pincap & AC_PINCAP_VREF_80)
1362 return AC_PINCTL_VREF_80;
1363 if (pincap & AC_PINCAP_VREF_50)
1364 return AC_PINCTL_VREF_50;
1365 if (pincap & AC_PINCAP_VREF_GRD)
1366 return AC_PINCTL_VREF_GRD;
1370 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1373 snd_hda_codec_write_cache(codec, nid, 0,
1374 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1377 #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
1379 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1381 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1382 struct sigmatel_spec *spec = codec->spec;
1383 int io_idx = kcontrol-> private_value & 0xff;
1385 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1389 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1392 struct sigmatel_spec *spec = codec->spec;
1393 hda_nid_t nid = kcontrol->private_value >> 8;
1394 int io_idx = kcontrol-> private_value & 0xff;
1395 unsigned short val = ucontrol->value.integer.value[0];
1397 spec->io_switch[io_idx] = val;
1400 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1402 unsigned int pinctl = AC_PINCTL_IN_EN;
1403 if (io_idx) /* set VREF for mic */
1404 pinctl |= stac92xx_get_vref(codec, nid);
1405 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1410 #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1412 static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1413 struct snd_ctl_elem_value *ucontrol)
1415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1416 struct sigmatel_spec *spec = codec->spec;
1418 ucontrol->value.integer.value[0] = spec->clfe_swap;
1422 static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol)
1425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1426 struct sigmatel_spec *spec = codec->spec;
1427 hda_nid_t nid = kcontrol->private_value & 0xff;
1429 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1432 spec->clfe_swap = ucontrol->value.integer.value[0];
1434 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1435 spec->clfe_swap ? 0x4 : 0x0);
1440 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1441 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1444 .info = stac92xx_io_switch_info, \
1445 .get = stac92xx_io_switch_get, \
1446 .put = stac92xx_io_switch_put, \
1447 .private_value = xpval, \
1450 #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1451 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1454 .info = stac92xx_clfe_switch_info, \
1455 .get = stac92xx_clfe_switch_get, \
1456 .put = stac92xx_clfe_switch_put, \
1457 .private_value = xpval, \
1461 STAC_CTL_WIDGET_VOL,
1462 STAC_CTL_WIDGET_MUTE,
1463 STAC_CTL_WIDGET_IO_SWITCH,
1464 STAC_CTL_WIDGET_CLFE_SWITCH
1467 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1468 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1469 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1470 STAC_CODEC_IO_SWITCH(NULL, 0),
1471 STAC_CODEC_CLFE_SWITCH(NULL, 0),
1474 /* add dynamic controls */
1475 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1477 struct snd_kcontrol_new *knew;
1479 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1480 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1482 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1485 if (spec->kctl_alloc) {
1486 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1487 kfree(spec->kctl_alloc);
1489 spec->kctl_alloc = knew;
1490 spec->num_kctl_alloc = num;
1493 knew = &spec->kctl_alloc[spec->num_kctl_used];
1494 *knew = stac92xx_control_templates[type];
1495 knew->name = kstrdup(name, GFP_KERNEL);
1498 knew->private_value = val;
1499 spec->num_kctl_used++;
1503 /* flag inputs as additional dynamic lineouts */
1504 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1506 struct sigmatel_spec *spec = codec->spec;
1507 unsigned int wcaps, wtype;
1508 int i, num_dacs = 0;
1510 /* use the wcaps cache to count all DACs available for line-outs */
1511 for (i = 0; i < codec->num_nodes; i++) {
1512 wcaps = codec->wcaps[i];
1513 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1514 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1518 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1520 switch (cfg->line_outs) {
1522 /* add line-in as side */
1523 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1524 cfg->line_out_pins[cfg->line_outs] =
1525 cfg->input_pins[AUTO_PIN_LINE];
1526 spec->line_switch = 1;
1531 /* add line-in as clfe and mic as side */
1532 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1533 cfg->line_out_pins[cfg->line_outs] =
1534 cfg->input_pins[AUTO_PIN_LINE];
1535 spec->line_switch = 1;
1538 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1539 cfg->line_out_pins[cfg->line_outs] =
1540 cfg->input_pins[AUTO_PIN_MIC];
1541 spec->mic_switch = 1;
1546 /* add line-in as surr and mic as clfe */
1547 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1548 cfg->line_out_pins[cfg->line_outs] =
1549 cfg->input_pins[AUTO_PIN_LINE];
1550 spec->line_switch = 1;
1553 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1554 cfg->line_out_pins[cfg->line_outs] =
1555 cfg->input_pins[AUTO_PIN_MIC];
1556 spec->mic_switch = 1;
1566 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1570 for (i = 0; i < spec->multiout.num_dacs; i++) {
1571 if (spec->multiout.dac_nids[i] == nid)
1579 * Fill in the dac_nids table from the parsed pin configuration
1580 * This function only works when every pin in line_out_pins[]
1581 * contains atleast one DAC in its connection list. Some 92xx
1582 * codecs are not connected directly to a DAC, such as the 9200
1583 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1585 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1586 struct auto_pin_cfg *cfg)
1588 struct sigmatel_spec *spec = codec->spec;
1589 int i, j, conn_len = 0;
1590 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1591 unsigned int wcaps, wtype;
1593 for (i = 0; i < cfg->line_outs; i++) {
1594 nid = cfg->line_out_pins[i];
1595 conn_len = snd_hda_get_connections(codec, nid, conn,
1596 HDA_MAX_CONNECTIONS);
1597 for (j = 0; j < conn_len; j++) {
1598 wcaps = snd_hda_param_read(codec, conn[j],
1599 AC_PAR_AUDIO_WIDGET_CAP);
1600 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1602 if (wtype != AC_WID_AUD_OUT ||
1603 (wcaps & AC_WCAP_DIGITAL))
1605 /* conn[j] is a DAC routed to this line-out */
1606 if (!is_in_dac_nids(spec, conn[j]))
1610 if (j == conn_len) {
1611 if (spec->multiout.num_dacs > 0) {
1612 /* we have already working output pins,
1613 * so let's drop the broken ones again
1615 cfg->line_outs = spec->multiout.num_dacs;
1618 /* error out, no available DAC found */
1620 "%s: No available DAC for pin 0x%x\n",
1625 spec->multiout.dac_nids[i] = conn[j];
1626 spec->multiout.num_dacs++;
1628 /* select this DAC in the pin's input mux */
1629 snd_hda_codec_write_cache(codec, nid, 0,
1630 AC_VERB_SET_CONNECT_SEL, j);
1635 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1636 spec->multiout.num_dacs,
1637 spec->multiout.dac_nids[0],
1638 spec->multiout.dac_nids[1],
1639 spec->multiout.dac_nids[2],
1640 spec->multiout.dac_nids[3],
1641 spec->multiout.dac_nids[4]);
1645 /* create volume control/switch for the given prefx type */
1646 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1651 sprintf(name, "%s Playback Volume", pfx);
1652 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1653 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1656 sprintf(name, "%s Playback Switch", pfx);
1657 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1658 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1664 /* add playback controls from the parsed DAC table */
1665 static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
1666 const struct auto_pin_cfg *cfg)
1668 static const char *chname[4] = {
1669 "Front", "Surround", NULL /*CLFE*/, "Side"
1674 struct sigmatel_spec *spec = codec->spec;
1675 unsigned int wid_caps;
1678 for (i = 0; i < cfg->line_outs; i++) {
1679 if (!spec->multiout.dac_nids[i])
1682 nid = spec->multiout.dac_nids[i];
1686 err = create_controls(spec, "Center", nid, 1);
1689 err = create_controls(spec, "LFE", nid, 2);
1693 wid_caps = get_wcaps(codec, nid);
1695 if (wid_caps & AC_WCAP_LR_SWAP) {
1696 err = stac92xx_add_control(spec,
1697 STAC_CTL_WIDGET_CLFE_SWITCH,
1698 "Swap Center/LFE Playback Switch", nid);
1705 err = create_controls(spec, chname[i], nid, 3);
1711 if (spec->line_switch)
1712 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1715 if (spec->mic_switch)
1716 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1722 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1724 if (is_in_dac_nids(spec, nid))
1726 if (spec->multiout.hp_nid == nid)
1731 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1733 if (!spec->multiout.hp_nid)
1734 spec->multiout.hp_nid = nid;
1735 else if (spec->multiout.num_dacs > 4) {
1736 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1739 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1740 spec->multiout.num_dacs++;
1745 /* add playback controls for Speaker and HP outputs */
1746 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1747 struct auto_pin_cfg *cfg)
1749 struct sigmatel_spec *spec = codec->spec;
1751 int i, old_num_dacs, err;
1753 old_num_dacs = spec->multiout.num_dacs;
1754 for (i = 0; i < cfg->hp_outs; i++) {
1755 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1756 if (wid_caps & AC_WCAP_UNSOL_CAP)
1757 spec->hp_detect = 1;
1758 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1759 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1760 if (check_in_dac_nids(spec, nid))
1764 add_spec_dacs(spec, nid);
1766 for (i = 0; i < cfg->speaker_outs; i++) {
1767 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1768 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1769 if (check_in_dac_nids(spec, nid))
1773 add_spec_dacs(spec, nid);
1775 for (i = 0; i < cfg->line_outs; i++) {
1776 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1777 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1778 if (check_in_dac_nids(spec, nid))
1782 add_spec_dacs(spec, nid);
1784 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1785 static const char *pfxs[] = {
1786 "Speaker", "External Speaker", "Speaker2",
1788 err = create_controls(spec, pfxs[i - old_num_dacs],
1789 spec->multiout.dac_nids[i], 3);
1793 if (spec->multiout.hp_nid) {
1795 if (old_num_dacs == spec->multiout.num_dacs)
1799 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1807 /* labels for dmic mux inputs */
1808 static const char *stac92xx_dmic_labels[5] = {
1809 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1810 "Digital Mic 3", "Digital Mic 4"
1813 /* create playback/capture controls for input pins on dmic capable codecs */
1814 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1815 const struct auto_pin_cfg *cfg)
1817 struct sigmatel_spec *spec = codec->spec;
1818 struct hda_input_mux *dimux = &spec->private_dimux;
1819 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1822 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1823 dimux->items[dimux->num_items].index = 0;
1826 for (i = 0; i < spec->num_dmics; i++) {
1829 unsigned int def_conf;
1831 def_conf = snd_hda_codec_read(codec,
1834 AC_VERB_GET_CONFIG_DEFAULT,
1836 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1839 num_cons = snd_hda_get_connections(codec,
1842 HDA_MAX_NUM_INPUTS);
1843 for (j = 0; j < num_cons; j++)
1844 if (con_lst[j] == spec->dmic_nids[i]) {
1850 dimux->items[dimux->num_items].label =
1851 stac92xx_dmic_labels[dimux->num_items];
1852 dimux->items[dimux->num_items].index = index;
1859 /* create playback/capture controls for input pins */
1860 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1862 struct sigmatel_spec *spec = codec->spec;
1863 struct hda_input_mux *imux = &spec->private_imux;
1864 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1867 for (i = 0; i < AUTO_PIN_LAST; i++) {
1870 if (!cfg->input_pins[i])
1873 for (j = 0; j < spec->num_muxes; j++) {
1875 num_cons = snd_hda_get_connections(codec,
1878 HDA_MAX_NUM_INPUTS);
1879 for (k = 0; k < num_cons; k++)
1880 if (con_lst[k] == cfg->input_pins[i]) {
1887 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1888 imux->items[imux->num_items].index = index;
1892 if (imux->num_items) {
1894 * Set the current input for the muxes.
1895 * The STAC9221 has two input muxes with identical source
1896 * NID lists. Hopefully this won't get confused.
1898 for (i = 0; i < spec->num_muxes; i++) {
1899 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
1900 AC_VERB_SET_CONNECT_SEL,
1901 imux->items[0].index);
1908 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1910 struct sigmatel_spec *spec = codec->spec;
1913 for (i = 0; i < spec->autocfg.line_outs; i++) {
1914 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1915 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1919 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1921 struct sigmatel_spec *spec = codec->spec;
1924 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1926 pin = spec->autocfg.hp_pins[i];
1927 if (pin) /* connect to front */
1928 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1930 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1932 pin = spec->autocfg.speaker_pins[i];
1933 if (pin) /* connect to front */
1934 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1938 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1940 struct sigmatel_spec *spec = codec->spec;
1943 if ((err = snd_hda_parse_pin_def_config(codec,
1945 spec->dmic_nids)) < 0)
1947 if (! spec->autocfg.line_outs)
1948 return 0; /* can't find valid pin config */
1950 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1952 if (spec->multiout.num_dacs == 0)
1953 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1956 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
1961 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
1966 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
1971 if (spec->num_dmics > 0)
1972 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1973 &spec->autocfg)) < 0)
1976 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1977 if (spec->multiout.max_channels > 2)
1978 spec->surr_switch = 1;
1980 if (spec->autocfg.dig_out_pin)
1981 spec->multiout.dig_out_nid = dig_out;
1982 if (spec->autocfg.dig_in_pin)
1983 spec->dig_in_nid = dig_in;
1985 if (spec->kctl_alloc)
1986 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1988 spec->input_mux = &spec->private_imux;
1989 spec->dinput_mux = &spec->private_dimux;
1994 /* add playback controls for HP output */
1995 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1996 struct auto_pin_cfg *cfg)
1998 struct sigmatel_spec *spec = codec->spec;
1999 hda_nid_t pin = cfg->hp_pins[0];
2000 unsigned int wid_caps;
2005 wid_caps = get_wcaps(codec, pin);
2006 if (wid_caps & AC_WCAP_UNSOL_CAP)
2007 spec->hp_detect = 1;
2012 /* add playback controls for LFE output */
2013 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2014 struct auto_pin_cfg *cfg)
2016 struct sigmatel_spec *spec = codec->spec;
2018 hda_nid_t lfe_pin = 0x0;
2022 * search speaker outs and line outs for a mono speaker pin
2023 * with an amp. If one is found, add LFE controls
2026 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2027 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2028 unsigned long wcaps = get_wcaps(codec, pin);
2029 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2030 if (wcaps == AC_WCAP_OUT_AMP)
2031 /* found a mono speaker with an amp, must be lfe */
2035 /* if speaker_outs is 0, then speakers may be in line_outs */
2036 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2037 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2038 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2040 cfg = snd_hda_codec_read(codec, pin, 0,
2041 AC_VERB_GET_CONFIG_DEFAULT,
2043 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2044 unsigned long wcaps = get_wcaps(codec, pin);
2045 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2046 if (wcaps == AC_WCAP_OUT_AMP)
2047 /* found a mono speaker with an amp,
2055 err = create_controls(spec, "LFE", lfe_pin, 1);
2063 static int stac9200_parse_auto_config(struct hda_codec *codec)
2065 struct sigmatel_spec *spec = codec->spec;
2068 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2071 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2074 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2077 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2080 if (spec->autocfg.dig_out_pin)
2081 spec->multiout.dig_out_nid = 0x05;
2082 if (spec->autocfg.dig_in_pin)
2083 spec->dig_in_nid = 0x04;
2085 if (spec->kctl_alloc)
2086 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2088 spec->input_mux = &spec->private_imux;
2089 spec->dinput_mux = &spec->private_dimux;
2095 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2096 * funky external mute control using GPIO pins.
2099 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2101 unsigned int gpiostate, gpiomask, gpiodir;
2103 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2104 AC_VERB_GET_GPIO_DATA, 0);
2107 gpiostate |= (1 << pin);
2109 gpiostate &= ~(1 << pin);
2111 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2112 AC_VERB_GET_GPIO_MASK, 0);
2113 gpiomask |= (1 << pin);
2115 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2116 AC_VERB_GET_GPIO_DIRECTION, 0);
2117 gpiodir |= (1 << pin);
2119 /* AppleHDA seems to do this -- WTF is this verb?? */
2120 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2122 snd_hda_codec_write(codec, codec->afg, 0,
2123 AC_VERB_SET_GPIO_MASK, gpiomask);
2124 snd_hda_codec_write(codec, codec->afg, 0,
2125 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2129 snd_hda_codec_write(codec, codec->afg, 0,
2130 AC_VERB_SET_GPIO_DATA, gpiostate);
2133 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2136 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
2137 snd_hda_codec_write_cache(codec, nid, 0,
2138 AC_VERB_SET_UNSOLICITED_ENABLE,
2139 (AC_USRSP_EN | event));
2142 static int stac92xx_init(struct hda_codec *codec)
2144 struct sigmatel_spec *spec = codec->spec;
2145 struct auto_pin_cfg *cfg = &spec->autocfg;
2148 snd_hda_sequence_write(codec, spec->init);
2151 if (spec->hp_detect) {
2152 /* Enable unsolicited responses on the HP widget */
2153 for (i = 0; i < cfg->hp_outs; i++)
2154 enable_pin_detect(codec, cfg->hp_pins[i],
2156 /* force to enable the first line-out; the others are set up
2159 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2161 stac92xx_auto_init_hp_out(codec);
2162 /* fake event to set up pins */
2163 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2165 stac92xx_auto_init_multi_out(codec);
2166 stac92xx_auto_init_hp_out(codec);
2168 for (i = 0; i < AUTO_PIN_LAST; i++) {
2169 hda_nid_t nid = cfg->input_pins[i];
2171 unsigned int pinctl = AC_PINCTL_IN_EN;
2172 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2173 pinctl |= stac92xx_get_vref(codec, nid);
2174 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2177 if (spec->num_dmics > 0)
2178 for (i = 0; i < spec->num_dmics; i++)
2179 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2182 if (cfg->dig_out_pin)
2183 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2185 if (cfg->dig_in_pin)
2186 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2189 if (spec->gpio_mute) {
2190 stac922x_gpio_mute(codec, 0, 0);
2191 stac922x_gpio_mute(codec, 1, 0);
2197 static void stac92xx_free(struct hda_codec *codec)
2199 struct sigmatel_spec *spec = codec->spec;
2205 if (spec->kctl_alloc) {
2206 for (i = 0; i < spec->num_kctl_used; i++)
2207 kfree(spec->kctl_alloc[i].name);
2208 kfree(spec->kctl_alloc);
2211 if (spec->bios_pin_configs)
2212 kfree(spec->bios_pin_configs);
2217 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2220 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2221 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
2223 if (pin_ctl & AC_PINCTL_IN_EN) {
2225 * we need to check the current set-up direction of
2226 * shared input pins since they can be switched via
2227 * "xxx as Output" mixer switch
2229 struct sigmatel_spec *spec = codec->spec;
2230 struct auto_pin_cfg *cfg = &spec->autocfg;
2231 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2232 spec->line_switch) ||
2233 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2238 /* if setting pin direction bits, clear the current
2239 direction bits first */
2240 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2241 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2243 snd_hda_codec_write_cache(codec, nid, 0,
2244 AC_VERB_SET_PIN_WIDGET_CONTROL,
2248 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2251 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2252 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
2253 snd_hda_codec_write_cache(codec, nid, 0,
2254 AC_VERB_SET_PIN_WIDGET_CONTROL,
2258 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
2262 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
2268 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
2270 struct sigmatel_spec *spec = codec->spec;
2271 struct auto_pin_cfg *cfg = &spec->autocfg;
2275 for (i = 0; i < cfg->hp_outs; i++) {
2276 presence = get_pin_presence(codec, cfg->hp_pins[i]);
2282 /* disable lineouts, enable hp */
2283 for (i = 0; i < cfg->line_outs; i++)
2284 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2286 for (i = 0; i < cfg->speaker_outs; i++)
2287 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2290 /* enable lineouts, disable hp */
2291 for (i = 0; i < cfg->line_outs; i++)
2292 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2294 for (i = 0; i < cfg->speaker_outs; i++)
2295 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2300 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2302 switch (res >> 26) {
2304 stac92xx_hp_detect(codec, res);
2309 #ifdef SND_HDA_NEEDS_RESUME
2310 static int stac92xx_resume(struct hda_codec *codec)
2312 struct sigmatel_spec *spec = codec->spec;
2314 stac92xx_set_config_regs(codec);
2315 snd_hda_sequence_write(codec, spec->init);
2316 if (spec->gpio_mute) {
2317 stac922x_gpio_mute(codec, 0, 0);
2318 stac922x_gpio_mute(codec, 1, 0);
2320 snd_hda_codec_resume_amp(codec);
2321 snd_hda_codec_resume_cache(codec);
2322 /* invoke unsolicited event to reset the HP state */
2323 if (spec->hp_detect)
2324 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2329 static struct hda_codec_ops stac92xx_patch_ops = {
2330 .build_controls = stac92xx_build_controls,
2331 .build_pcms = stac92xx_build_pcms,
2332 .init = stac92xx_init,
2333 .free = stac92xx_free,
2334 .unsol_event = stac92xx_unsol_event,
2335 #ifdef SND_HDA_NEEDS_RESUME
2336 .resume = stac92xx_resume,
2340 static int patch_stac9200(struct hda_codec *codec)
2342 struct sigmatel_spec *spec;
2345 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2350 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
2351 spec->pin_nids = stac9200_pin_nids;
2352 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2355 if (spec->board_config < 0) {
2356 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2357 err = stac92xx_save_bios_config_regs(codec);
2359 stac92xx_free(codec);
2362 spec->pin_configs = spec->bios_pin_configs;
2364 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2365 stac92xx_set_config_regs(codec);
2368 spec->multiout.max_channels = 2;
2369 spec->multiout.num_dacs = 1;
2370 spec->multiout.dac_nids = stac9200_dac_nids;
2371 spec->adc_nids = stac9200_adc_nids;
2372 spec->mux_nids = stac9200_mux_nids;
2373 spec->num_muxes = 1;
2374 spec->num_dmics = 0;
2376 spec->init = stac9200_core_init;
2377 spec->mixer = stac9200_mixer;
2379 err = stac9200_parse_auto_config(codec);
2381 stac92xx_free(codec);
2385 codec->patch_ops = stac92xx_patch_ops;
2390 static int patch_stac925x(struct hda_codec *codec)
2392 struct sigmatel_spec *spec;
2395 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2400 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
2401 spec->pin_nids = stac925x_pin_nids;
2402 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2406 if (spec->board_config < 0) {
2407 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2408 "using BIOS defaults\n");
2409 err = stac92xx_save_bios_config_regs(codec);
2411 stac92xx_free(codec);
2414 spec->pin_configs = spec->bios_pin_configs;
2415 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2416 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2417 stac92xx_set_config_regs(codec);
2420 spec->multiout.max_channels = 2;
2421 spec->multiout.num_dacs = 1;
2422 spec->multiout.dac_nids = stac925x_dac_nids;
2423 spec->adc_nids = stac925x_adc_nids;
2424 spec->mux_nids = stac925x_mux_nids;
2425 spec->num_muxes = 1;
2426 switch (codec->vendor_id) {
2427 case 0x83847632: /* STAC9202 */
2428 case 0x83847633: /* STAC9202D */
2429 case 0x83847636: /* STAC9251 */
2430 case 0x83847637: /* STAC9251D */
2431 spec->num_dmics = 1;
2432 spec->dmic_nids = stac925x_dmic_nids;
2435 spec->num_dmics = 0;
2439 spec->init = stac925x_core_init;
2440 spec->mixer = stac925x_mixer;
2442 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
2444 if (spec->board_config < 0) {
2445 printk(KERN_WARNING "hda_codec: No auto-config is "
2446 "available, default to model=ref\n");
2447 spec->board_config = STAC_925x_REF;
2453 stac92xx_free(codec);
2457 codec->patch_ops = stac92xx_patch_ops;
2462 static int patch_stac922x(struct hda_codec *codec)
2464 struct sigmatel_spec *spec;
2467 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2472 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
2473 spec->pin_nids = stac922x_pin_nids;
2474 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2477 if (spec->board_config == STAC_INTEL_MAC_V3) {
2478 spec->gpio_mute = 1;
2479 /* Intel Macs have all same PCI SSID, so we need to check
2480 * codec SSID to distinguish the exact models
2482 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
2483 switch (codec->subsystem_id) {
2486 spec->board_config = STAC_INTEL_MAC_V1;
2490 spec->board_config = STAC_INTEL_MAC_V2;
2498 spec->board_config = STAC_INTEL_MAC_V3;
2502 spec->board_config = STAC_INTEL_MAC_V4;
2506 spec->board_config = STAC_INTEL_MAC_V5;
2512 if (spec->board_config < 0) {
2513 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2514 "using BIOS defaults\n");
2515 err = stac92xx_save_bios_config_regs(codec);
2517 stac92xx_free(codec);
2520 spec->pin_configs = spec->bios_pin_configs;
2521 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2522 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2523 stac92xx_set_config_regs(codec);
2526 spec->adc_nids = stac922x_adc_nids;
2527 spec->mux_nids = stac922x_mux_nids;
2528 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2529 spec->num_dmics = 0;
2531 spec->init = stac922x_core_init;
2532 spec->mixer = stac922x_mixer;
2534 spec->multiout.dac_nids = spec->dac_nids;
2536 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2538 if (spec->board_config < 0) {
2539 printk(KERN_WARNING "hda_codec: No auto-config is "
2540 "available, default to model=ref\n");
2541 spec->board_config = STAC_D945_REF;
2547 stac92xx_free(codec);
2551 codec->patch_ops = stac92xx_patch_ops;
2553 /* Fix Mux capture level; max to 2 */
2554 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2555 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2556 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2557 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2558 (0 << AC_AMPCAP_MUTE_SHIFT));
2563 static int patch_stac927x(struct hda_codec *codec)
2565 struct sigmatel_spec *spec;
2568 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2573 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
2574 spec->pin_nids = stac927x_pin_nids;
2575 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2579 if (spec->board_config < 0) {
2580 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2581 err = stac92xx_save_bios_config_regs(codec);
2583 stac92xx_free(codec);
2586 spec->pin_configs = spec->bios_pin_configs;
2587 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2588 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2589 stac92xx_set_config_regs(codec);
2592 switch (spec->board_config) {
2594 spec->adc_nids = stac927x_adc_nids;
2595 spec->mux_nids = stac927x_mux_nids;
2596 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2597 spec->num_dmics = 0;
2598 spec->init = d965_core_init;
2599 spec->mixer = stac9227_mixer;
2602 spec->adc_nids = stac927x_adc_nids;
2603 spec->mux_nids = stac927x_mux_nids;
2604 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2605 spec->num_dmics = 0;
2606 spec->init = d965_core_init;
2607 spec->mixer = stac9227_mixer;
2610 spec->adc_nids = stac927x_adc_nids;
2611 spec->mux_nids = stac927x_mux_nids;
2612 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2613 spec->num_dmics = 0;
2614 spec->init = stac927x_core_init;
2615 spec->mixer = stac927x_mixer;
2618 spec->multiout.dac_nids = spec->dac_nids;
2619 /* GPIO0 High = Enable EAPD */
2620 spec->gpio_mask = spec->gpio_data = 0x00000001;
2621 stac92xx_enable_gpio_mask(codec);
2623 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2625 if (spec->board_config < 0) {
2626 printk(KERN_WARNING "hda_codec: No auto-config is "
2627 "available, default to model=ref\n");
2628 spec->board_config = STAC_D965_REF;
2634 stac92xx_free(codec);
2638 codec->patch_ops = stac92xx_patch_ops;
2643 static int patch_stac9205(struct hda_codec *codec)
2645 struct sigmatel_spec *spec;
2648 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2653 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
2654 spec->pin_nids = stac9205_pin_nids;
2655 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2659 if (spec->board_config < 0) {
2660 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2661 err = stac92xx_save_bios_config_regs(codec);
2663 stac92xx_free(codec);
2666 spec->pin_configs = spec->bios_pin_configs;
2668 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2669 stac92xx_set_config_regs(codec);
2672 spec->adc_nids = stac9205_adc_nids;
2673 spec->mux_nids = stac9205_mux_nids;
2674 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2675 spec->dmic_nids = stac9205_dmic_nids;
2676 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2677 spec->dmux_nid = 0x1d;
2679 spec->init = stac9205_core_init;
2680 spec->mixer = stac9205_mixer;
2682 spec->multiout.dac_nids = spec->dac_nids;
2684 switch (spec->board_config){
2685 case STAC_9205_M43xx:
2686 case STAC_9205_DELL_M43:
2687 /* Enable SPDIF in/out */
2688 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
2689 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
2691 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
2692 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
2693 * GPIO2 High = Headphone Mute
2695 spec->gpio_data = 0x00000005;
2698 /* GPIO0 High = EAPD */
2699 spec->gpio_mask = spec->gpio_data = 0x00000001;
2703 stac92xx_enable_gpio_mask(codec);
2704 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2706 if (spec->board_config < 0) {
2707 printk(KERN_WARNING "hda_codec: No auto-config is "
2708 "available, default to model=ref\n");
2709 spec->board_config = STAC_9205_REF;
2715 stac92xx_free(codec);
2719 codec->patch_ops = stac92xx_patch_ops;
2728 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2729 static hda_nid_t vaio_dacs[] = { 0x2 };
2730 #define VAIO_HP_DAC 0x5
2731 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2732 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2734 static struct hda_input_mux vaio_mux = {
2737 /* { "HP", 0x0 }, */
2738 { "Mic Jack", 0x1 },
2739 { "Internal Mic", 0x2 },
2744 static struct hda_verb vaio_init[] = {
2745 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2746 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
2747 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2748 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2749 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2750 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2751 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
2752 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2753 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2754 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2755 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2756 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2760 static struct hda_verb vaio_ar_init[] = {
2761 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2762 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2763 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2764 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2765 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2766 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2767 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
2768 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2769 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2770 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2771 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2772 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2773 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2777 /* bind volumes of both NID 0x02 and 0x05 */
2778 static struct hda_bind_ctls vaio_bind_master_vol = {
2779 .ops = &snd_hda_bind_vol,
2781 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2782 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2787 /* bind volumes of both NID 0x02 and 0x05 */
2788 static struct hda_bind_ctls vaio_bind_master_sw = {
2789 .ops = &snd_hda_bind_sw,
2791 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2792 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
2797 static struct snd_kcontrol_new vaio_mixer[] = {
2798 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2799 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
2800 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2801 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2802 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2804 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2805 .name = "Capture Source",
2807 .info = stac92xx_mux_enum_info,
2808 .get = stac92xx_mux_enum_get,
2809 .put = stac92xx_mux_enum_put,
2814 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2815 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
2816 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
2817 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2818 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2819 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2820 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2821 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2824 .name = "Capture Source",
2826 .info = stac92xx_mux_enum_info,
2827 .get = stac92xx_mux_enum_get,
2828 .put = stac92xx_mux_enum_put,
2833 static struct hda_codec_ops stac9872_patch_ops = {
2834 .build_controls = stac92xx_build_controls,
2835 .build_pcms = stac92xx_build_pcms,
2836 .init = stac92xx_init,
2837 .free = stac92xx_free,
2838 #ifdef SND_HDA_NEEDS_RESUME
2839 .resume = stac92xx_resume,
2843 static int stac9872_vaio_init(struct hda_codec *codec)
2847 err = stac92xx_init(codec);
2850 if (codec->patch_ops.unsol_event)
2851 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2855 static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
2857 if (get_pin_presence(codec, 0x0a)) {
2858 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2859 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2861 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
2862 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
2866 static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
2868 switch (res >> 26) {
2870 stac9872_vaio_hp_detect(codec, res);
2875 static struct hda_codec_ops stac9872_vaio_patch_ops = {
2876 .build_controls = stac92xx_build_controls,
2877 .build_pcms = stac92xx_build_pcms,
2878 .init = stac9872_vaio_init,
2879 .free = stac92xx_free,
2880 .unsol_event = stac9872_vaio_unsol_event,
2882 .resume = stac92xx_resume,
2886 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2888 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2890 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2892 /* AR Series. id=0x83847664 and subsys=104D1300 */
2897 static const char *stac9872_models[STAC_9872_MODELS] = {
2898 [CXD9872RD_VAIO] = "vaio",
2899 [CXD9872AKD_VAIO] = "vaio-ar",
2902 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2903 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2904 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2905 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2906 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2910 static int patch_stac9872(struct hda_codec *codec)
2912 struct sigmatel_spec *spec;
2915 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2918 if (board_config < 0)
2919 /* unknown config, let generic-parser do its job... */
2920 return snd_hda_parse_generic_codec(codec);
2922 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2927 switch (board_config) {
2928 case CXD9872RD_VAIO:
2929 case STAC9872AK_VAIO:
2930 case STAC9872K_VAIO:
2931 spec->mixer = vaio_mixer;
2932 spec->init = vaio_init;
2933 spec->multiout.max_channels = 2;
2934 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2935 spec->multiout.dac_nids = vaio_dacs;
2936 spec->multiout.hp_nid = VAIO_HP_DAC;
2937 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2938 spec->adc_nids = vaio_adcs;
2939 spec->input_mux = &vaio_mux;
2940 spec->mux_nids = vaio_mux_nids;
2941 codec->patch_ops = stac9872_vaio_patch_ops;
2944 case CXD9872AKD_VAIO:
2945 spec->mixer = vaio_ar_mixer;
2946 spec->init = vaio_ar_init;
2947 spec->multiout.max_channels = 2;
2948 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2949 spec->multiout.dac_nids = vaio_dacs;
2950 spec->multiout.hp_nid = VAIO_HP_DAC;
2951 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2952 spec->adc_nids = vaio_adcs;
2953 spec->input_mux = &vaio_mux;
2954 spec->mux_nids = vaio_mux_nids;
2955 codec->patch_ops = stac9872_patch_ops;
2966 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2967 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2968 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2969 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2970 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2971 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2972 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2973 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2974 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2975 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2976 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2977 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2978 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2979 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2980 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2981 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2982 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2983 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2984 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2985 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2986 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2987 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2988 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2989 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2990 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2991 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2992 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2993 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2994 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2995 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2996 /* The following does not take into account .id=0x83847661 when subsys =
2997 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2998 * currently not fully supported.
3000 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3001 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3002 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
3003 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3004 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3005 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3006 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3007 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3008 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3009 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3010 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },