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
77 struct sigmatel_spec {
78 struct snd_kcontrol_new *mixers[4];
79 unsigned int num_mixers;
82 unsigned int surr_switch: 1;
83 unsigned int line_switch: 1;
84 unsigned int mic_switch: 1;
85 unsigned int alt_switch: 1;
86 unsigned int hp_detect: 1;
87 unsigned int gpio_mute: 1;
90 struct hda_multi_out multiout;
91 hda_nid_t dac_nids[5];
95 unsigned int num_adcs;
97 unsigned int num_muxes;
99 unsigned int num_dmics;
101 hda_nid_t dig_in_nid;
105 unsigned int num_pins;
106 unsigned int *pin_configs;
107 unsigned int *bios_pin_configs;
109 /* codec specific stuff */
110 struct hda_verb *init;
111 struct snd_kcontrol_new *mixer;
114 struct hda_input_mux *dinput_mux;
115 unsigned int cur_dmux;
116 struct hda_input_mux *input_mux;
117 unsigned int cur_mux[3];
120 unsigned int io_switch[2];
122 struct hda_pcm pcm_rec[2]; /* PCM information */
124 /* dynamic controls and input_mux */
125 struct auto_pin_cfg autocfg;
126 unsigned int num_kctl_alloc, num_kctl_used;
127 struct snd_kcontrol_new *kctl_alloc;
128 struct hda_input_mux private_dimux;
129 struct hda_input_mux private_imux;
132 static hda_nid_t stac9200_adc_nids[1] = {
136 static hda_nid_t stac9200_mux_nids[1] = {
140 static hda_nid_t stac9200_dac_nids[1] = {
144 static hda_nid_t stac925x_adc_nids[1] = {
148 static hda_nid_t stac925x_mux_nids[1] = {
152 static hda_nid_t stac925x_dac_nids[1] = {
156 static hda_nid_t stac925x_dmic_nids[1] = {
160 static hda_nid_t stac922x_adc_nids[2] = {
164 static hda_nid_t stac922x_mux_nids[2] = {
168 static hda_nid_t stac927x_adc_nids[3] = {
172 static hda_nid_t stac927x_mux_nids[3] = {
176 static hda_nid_t stac9205_adc_nids[2] = {
180 static hda_nid_t stac9205_mux_nids[2] = {
184 static hda_nid_t stac9205_dmic_nids[2] = {
188 static hda_nid_t stac9200_pin_nids[8] = {
189 0x08, 0x09, 0x0d, 0x0e,
190 0x0f, 0x10, 0x11, 0x12,
193 static hda_nid_t stac925x_pin_nids[8] = {
194 0x07, 0x08, 0x0a, 0x0b,
195 0x0c, 0x0d, 0x10, 0x11,
198 static hda_nid_t stac922x_pin_nids[10] = {
199 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
200 0x0f, 0x10, 0x11, 0x15, 0x1b,
203 static hda_nid_t stac927x_pin_nids[14] = {
204 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
205 0x0f, 0x10, 0x11, 0x12, 0x13,
206 0x14, 0x21, 0x22, 0x23,
209 static hda_nid_t stac9205_pin_nids[12] = {
210 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
211 0x0f, 0x14, 0x16, 0x17, 0x18,
216 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
217 struct snd_ctl_elem_info *uinfo)
219 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
220 struct sigmatel_spec *spec = codec->spec;
221 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
224 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
225 struct snd_ctl_elem_value *ucontrol)
227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
228 struct sigmatel_spec *spec = codec->spec;
230 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
234 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol)
237 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
238 struct sigmatel_spec *spec = codec->spec;
240 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
241 spec->dmux_nid, &spec->cur_dmux);
244 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct sigmatel_spec *spec = codec->spec;
248 return snd_hda_input_mux_info(spec->input_mux, uinfo);
251 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
253 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
254 struct sigmatel_spec *spec = codec->spec;
255 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
257 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
261 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
263 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
264 struct sigmatel_spec *spec = codec->spec;
265 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
267 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
268 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
271 static struct hda_verb stac9200_core_init[] = {
272 /* set dac0mux for dac converter */
273 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
277 static struct hda_verb stac925x_core_init[] = {
278 /* set dac0mux for dac converter */
279 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
283 static struct hda_verb stac922x_core_init[] = {
284 /* set master volume and direct control */
285 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
289 static struct hda_verb d965_core_init[] = {
290 /* set master volume and direct control */
291 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
292 /* unmute node 0x1b */
293 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
294 /* select node 0x03 as DAC */
295 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
299 static struct hda_verb stac927x_core_init[] = {
300 /* set master volume and direct control */
301 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
305 static struct hda_verb stac9205_core_init[] = {
306 /* set master volume and direct control */
307 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
311 static struct snd_kcontrol_new stac9200_mixer[] = {
312 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
313 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
315 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
316 .name = "Input Source",
318 .info = stac92xx_mux_enum_info,
319 .get = stac92xx_mux_enum_get,
320 .put = stac92xx_mux_enum_put,
322 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
323 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
324 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
328 static struct snd_kcontrol_new stac925x_mixer[] = {
329 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
330 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
332 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
333 .name = "Input Source",
335 .info = stac92xx_mux_enum_info,
336 .get = stac92xx_mux_enum_get,
337 .put = stac92xx_mux_enum_put,
339 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
340 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
341 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
345 /* This needs to be generated dynamically based on sequence */
346 static struct snd_kcontrol_new stac922x_mixer[] = {
348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
349 .name = "Input Source",
351 .info = stac92xx_mux_enum_info,
352 .get = stac92xx_mux_enum_get,
353 .put = stac92xx_mux_enum_put,
355 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
356 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
357 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
361 /* This needs to be generated dynamically based on sequence */
362 static struct snd_kcontrol_new stac9227_mixer[] = {
364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
365 .name = "Input Source",
367 .info = stac92xx_mux_enum_info,
368 .get = stac92xx_mux_enum_get,
369 .put = stac92xx_mux_enum_put,
371 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
372 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
376 static struct snd_kcontrol_new stac927x_mixer[] = {
378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
379 .name = "Input Source",
381 .info = stac92xx_mux_enum_info,
382 .get = stac92xx_mux_enum_get,
383 .put = stac92xx_mux_enum_put,
385 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
386 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
387 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
391 static struct snd_kcontrol_new stac9205_mixer[] = {
393 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
394 .name = "Digital Input Source",
396 .info = stac92xx_dmux_enum_info,
397 .get = stac92xx_dmux_enum_get,
398 .put = stac92xx_dmux_enum_put,
401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
402 .name = "Input Source",
404 .info = stac92xx_mux_enum_info,
405 .get = stac92xx_mux_enum_get,
406 .put = stac92xx_mux_enum_put,
408 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
409 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
410 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
414 static int stac92xx_build_controls(struct hda_codec *codec)
416 struct sigmatel_spec *spec = codec->spec;
420 err = snd_hda_add_new_ctls(codec, spec->mixer);
424 for (i = 0; i < spec->num_mixers; i++) {
425 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
430 if (spec->multiout.dig_out_nid) {
431 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
435 if (spec->dig_in_nid) {
436 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
443 static unsigned int ref9200_pin_configs[8] = {
444 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
445 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
448 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
449 [STAC_REF] = ref9200_pin_configs,
452 static const char *stac9200_models[STAC_9200_MODELS] = {
456 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
457 /* SigmaTel reference board */
458 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
459 "DFI LanParty", STAC_REF),
460 /* Dell laptops have BIOS problem */
461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
462 "Dell Inspiron 630m", STAC_REF),
463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
464 "Dell Latitude D620", STAC_REF),
465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
466 "Dell Latitude 120L", STAC_REF),
467 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
468 "Dell Latitude D820", STAC_REF),
469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
470 "Dell Inspiron E1705/9400", STAC_REF),
471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
472 "Dell XPS M1710", STAC_REF),
473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
474 "Dell Precision M90", STAC_REF),
475 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
476 "unknown Dell", STAC_REF),
480 static unsigned int ref925x_pin_configs[8] = {
481 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
482 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
485 static unsigned int stac925x_MA6_pin_configs[8] = {
486 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
487 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
490 static unsigned int stac925x_PA6_pin_configs[8] = {
491 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
492 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
495 static unsigned int stac925xM2_2_pin_configs[8] = {
496 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
497 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
500 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
501 [STAC_REF] = ref925x_pin_configs,
502 [STAC_M2_2] = stac925xM2_2_pin_configs,
503 [STAC_MA6] = stac925x_MA6_pin_configs,
504 [STAC_PA6] = stac925x_PA6_pin_configs,
507 static const char *stac925x_models[STAC_925x_MODELS] = {
509 [STAC_M2_2] = "m2-2",
514 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
515 /* SigmaTel reference board */
516 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
517 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
518 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
519 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
520 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
521 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
522 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
526 static unsigned int ref922x_pin_configs[10] = {
527 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
528 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
529 0x40000100, 0x40000100,
532 static unsigned int d945gtp3_pin_configs[10] = {
533 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
534 0x40000100, 0x40000100, 0x40000100, 0x40000100,
535 0x02a19120, 0x40000100,
538 static unsigned int d945gtp5_pin_configs[10] = {
539 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
540 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
541 0x02a19320, 0x40000100,
544 static unsigned int macbook_pro_v1_pin_configs[10] = {
545 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
546 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
547 0x02a19320, 0x400000fb
550 static unsigned int macbook_pro_v2_pin_configs[10] = {
551 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
552 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
553 0x400000fc, 0x400000fb,
556 static unsigned int imac_intel_pin_configs[10] = {
557 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
558 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
559 0x400000fc, 0x400000fb,
562 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
563 [STAC_D945_REF] = ref922x_pin_configs,
564 [STAC_D945GTP3] = d945gtp3_pin_configs,
565 [STAC_D945GTP5] = d945gtp5_pin_configs,
566 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
567 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
568 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
569 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
570 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
573 static const char *stac922x_models[STAC_922X_MODELS] = {
574 [STAC_D945_REF] = "ref",
575 [STAC_D945GTP5] = "5stack",
576 [STAC_D945GTP3] = "3stack",
577 [STAC_MACMINI] = "macmini",
578 [STAC_MACBOOK] = "macbook",
579 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
580 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
581 [STAC_IMAC_INTEL] = "imac-intel",
584 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
585 /* SigmaTel reference board */
586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
587 "DFI LanParty", STAC_D945_REF),
588 /* Intel 945G based systems */
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
590 "Intel D945G", STAC_D945GTP3),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
592 "Intel D945G", STAC_D945GTP3),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
594 "Intel D945G", STAC_D945GTP3),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
596 "Intel D945G", STAC_D945GTP3),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
602 "Intel D945G", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
604 "Intel D945G", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
606 "Intel D945G", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
608 "Intel D945G", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
610 "Intel D945G", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
612 "Intel D945G", STAC_D945GTP3),
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
614 "Intel D945G", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
616 "Intel D945G", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
618 "Intel D945G", STAC_D945GTP3),
619 /* Intel D945G 5-stack systems */
620 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
621 "Intel D945G", STAC_D945GTP5),
622 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
623 "Intel D945G", STAC_D945GTP5),
624 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
625 "Intel D945G", STAC_D945GTP5),
626 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
627 "Intel D945G", STAC_D945GTP5),
628 /* Intel 945P based systems */
629 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
630 "Intel D945P", STAC_D945GTP3),
631 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
632 "Intel D945P", STAC_D945GTP3),
633 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
634 "Intel D945P", STAC_D945GTP3),
635 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
636 "Intel D945P", STAC_D945GTP3),
637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
638 "Intel D945P", STAC_D945GTP3),
639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
640 "Intel D945P", STAC_D945GTP5),
642 /* Apple Mac Mini (early 2006) */
643 SND_PCI_QUIRK(0x8384, 0x7680,
644 "Mac Mini", STAC_MACMINI),
648 static unsigned int ref927x_pin_configs[14] = {
649 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
650 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
651 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
652 0x01c42190, 0x40000100,
655 static unsigned int d965_3st_pin_configs[14] = {
656 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
657 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
658 0x40000100, 0x40000100, 0x40000100, 0x40000100,
659 0x40000100, 0x40000100
662 static unsigned int d965_5st_pin_configs[14] = {
663 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
664 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
665 0x40000100, 0x40000100, 0x40000100, 0x01442070,
666 0x40000100, 0x40000100
669 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
670 [STAC_D965_REF] = ref927x_pin_configs,
671 [STAC_D965_3ST] = d965_3st_pin_configs,
672 [STAC_D965_5ST] = d965_5st_pin_configs,
675 static const char *stac927x_models[STAC_927X_MODELS] = {
676 [STAC_D965_REF] = "ref",
677 [STAC_D965_3ST] = "3stack",
678 [STAC_D965_5ST] = "5stack",
681 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
682 /* SigmaTel reference board */
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
684 "DFI LanParty", STAC_D965_REF),
685 /* Intel 946 based systems */
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
688 /* 965 based 3 stack systems */
689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
692 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
701 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
702 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
703 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
705 /* 965 based 5 stack systems */
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
707 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
708 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
710 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
711 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
712 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
718 static unsigned int ref9205_pin_configs[12] = {
719 0x40000100, 0x40000100, 0x01016011, 0x01014010,
720 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
721 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
724 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
728 static const char *stac9205_models[STAC_9205_MODELS] = {
729 [STAC_9205_REF] = "ref",
732 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
733 /* SigmaTel reference board */
734 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
735 "DFI LanParty", STAC_9205_REF),
739 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
742 struct sigmatel_spec *spec = codec->spec;
744 if (! spec->bios_pin_configs) {
745 spec->bios_pin_configs = kcalloc(spec->num_pins,
746 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
747 if (! spec->bios_pin_configs)
751 for (i = 0; i < spec->num_pins; i++) {
752 hda_nid_t nid = spec->pin_nids[i];
753 unsigned int pin_cfg;
755 pin_cfg = snd_hda_codec_read(codec, nid, 0,
756 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
757 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
759 spec->bios_pin_configs[i] = pin_cfg;
765 static void stac92xx_set_config_regs(struct hda_codec *codec)
768 struct sigmatel_spec *spec = codec->spec;
769 unsigned int pin_cfg;
771 if (! spec->pin_nids || ! spec->pin_configs)
774 for (i = 0; i < spec->num_pins; i++) {
775 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
776 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
777 spec->pin_configs[i] & 0x000000ff);
778 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
779 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
780 (spec->pin_configs[i] & 0x0000ff00) >> 8);
781 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
782 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
783 (spec->pin_configs[i] & 0x00ff0000) >> 16);
784 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
785 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
786 spec->pin_configs[i] >> 24);
787 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
788 AC_VERB_GET_CONFIG_DEFAULT,
790 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
795 * Analog playback callbacks
797 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
798 struct hda_codec *codec,
799 struct snd_pcm_substream *substream)
801 struct sigmatel_spec *spec = codec->spec;
802 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
805 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
806 struct hda_codec *codec,
807 unsigned int stream_tag,
809 struct snd_pcm_substream *substream)
811 struct sigmatel_spec *spec = codec->spec;
812 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
815 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
816 struct hda_codec *codec,
817 struct snd_pcm_substream *substream)
819 struct sigmatel_spec *spec = codec->spec;
820 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
824 * Digital playback callbacks
826 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
827 struct hda_codec *codec,
828 struct snd_pcm_substream *substream)
830 struct sigmatel_spec *spec = codec->spec;
831 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
834 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
835 struct hda_codec *codec,
836 struct snd_pcm_substream *substream)
838 struct sigmatel_spec *spec = codec->spec;
839 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
842 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
843 struct hda_codec *codec,
844 unsigned int stream_tag,
846 struct snd_pcm_substream *substream)
848 struct sigmatel_spec *spec = codec->spec;
849 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
850 stream_tag, format, substream);
855 * Analog capture callbacks
857 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
858 struct hda_codec *codec,
859 unsigned int stream_tag,
861 struct snd_pcm_substream *substream)
863 struct sigmatel_spec *spec = codec->spec;
865 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
866 stream_tag, 0, format);
870 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
871 struct hda_codec *codec,
872 struct snd_pcm_substream *substream)
874 struct sigmatel_spec *spec = codec->spec;
876 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
880 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
884 /* NID is set in stac92xx_build_pcms */
886 .open = stac92xx_dig_playback_pcm_open,
887 .close = stac92xx_dig_playback_pcm_close,
888 .prepare = stac92xx_dig_playback_pcm_prepare
892 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
896 /* NID is set in stac92xx_build_pcms */
899 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
903 .nid = 0x02, /* NID to query formats and rates */
905 .open = stac92xx_playback_pcm_open,
906 .prepare = stac92xx_playback_pcm_prepare,
907 .cleanup = stac92xx_playback_pcm_cleanup
911 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
915 .nid = 0x06, /* NID to query formats and rates */
917 .open = stac92xx_playback_pcm_open,
918 .prepare = stac92xx_playback_pcm_prepare,
919 .cleanup = stac92xx_playback_pcm_cleanup
923 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
927 /* NID is set in stac92xx_build_pcms */
929 .prepare = stac92xx_capture_pcm_prepare,
930 .cleanup = stac92xx_capture_pcm_cleanup
934 static int stac92xx_build_pcms(struct hda_codec *codec)
936 struct sigmatel_spec *spec = codec->spec;
937 struct hda_pcm *info = spec->pcm_rec;
940 codec->pcm_info = info;
942 info->name = "STAC92xx Analog";
943 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
944 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
945 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
947 if (spec->alt_switch) {
950 info->name = "STAC92xx Analog Alt";
951 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
954 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
957 info->name = "STAC92xx Digital";
958 if (spec->multiout.dig_out_nid) {
959 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
960 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
962 if (spec->dig_in_nid) {
963 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
964 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
971 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
973 unsigned int pincap = snd_hda_param_read(codec, nid,
975 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
976 if (pincap & AC_PINCAP_VREF_100)
977 return AC_PINCTL_VREF_100;
978 if (pincap & AC_PINCAP_VREF_80)
979 return AC_PINCTL_VREF_80;
980 if (pincap & AC_PINCAP_VREF_50)
981 return AC_PINCTL_VREF_50;
982 if (pincap & AC_PINCAP_VREF_GRD)
983 return AC_PINCTL_VREF_GRD;
987 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
990 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
993 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
995 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
997 uinfo->value.integer.min = 0;
998 uinfo->value.integer.max = 1;
1002 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1004 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1005 struct sigmatel_spec *spec = codec->spec;
1006 int io_idx = kcontrol-> private_value & 0xff;
1008 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1012 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1015 struct sigmatel_spec *spec = codec->spec;
1016 hda_nid_t nid = kcontrol->private_value >> 8;
1017 int io_idx = kcontrol-> private_value & 0xff;
1018 unsigned short val = ucontrol->value.integer.value[0];
1020 spec->io_switch[io_idx] = val;
1023 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1025 unsigned int pinctl = AC_PINCTL_IN_EN;
1026 if (io_idx) /* set VREF for mic */
1027 pinctl |= stac92xx_get_vref(codec, nid);
1028 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1033 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1034 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1037 .info = stac92xx_io_switch_info, \
1038 .get = stac92xx_io_switch_get, \
1039 .put = stac92xx_io_switch_put, \
1040 .private_value = xpval, \
1045 STAC_CTL_WIDGET_VOL,
1046 STAC_CTL_WIDGET_MUTE,
1047 STAC_CTL_WIDGET_IO_SWITCH,
1050 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1051 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1052 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1053 STAC_CODEC_IO_SWITCH(NULL, 0),
1056 /* add dynamic controls */
1057 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1059 struct snd_kcontrol_new *knew;
1061 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1062 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1064 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1067 if (spec->kctl_alloc) {
1068 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1069 kfree(spec->kctl_alloc);
1071 spec->kctl_alloc = knew;
1072 spec->num_kctl_alloc = num;
1075 knew = &spec->kctl_alloc[spec->num_kctl_used];
1076 *knew = stac92xx_control_templates[type];
1077 knew->name = kstrdup(name, GFP_KERNEL);
1080 knew->private_value = val;
1081 spec->num_kctl_used++;
1085 /* flag inputs as additional dynamic lineouts */
1086 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1088 struct sigmatel_spec *spec = codec->spec;
1089 unsigned int wcaps, wtype;
1090 int i, num_dacs = 0;
1092 /* use the wcaps cache to count all DACs available for line-outs */
1093 for (i = 0; i < codec->num_nodes; i++) {
1094 wcaps = codec->wcaps[i];
1095 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1096 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1100 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1102 switch (cfg->line_outs) {
1104 /* add line-in as side */
1105 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1106 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1107 spec->line_switch = 1;
1112 /* add line-in as clfe and mic as side */
1113 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1114 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1115 spec->line_switch = 1;
1118 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1119 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1120 spec->mic_switch = 1;
1125 /* add line-in as surr and mic as clfe */
1126 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1127 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1128 spec->line_switch = 1;
1131 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1132 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1133 spec->mic_switch = 1;
1143 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1147 for (i = 0; i < spec->multiout.num_dacs; i++) {
1148 if (spec->multiout.dac_nids[i] == nid)
1156 * Fill in the dac_nids table from the parsed pin configuration
1157 * This function only works when every pin in line_out_pins[]
1158 * contains atleast one DAC in its connection list. Some 92xx
1159 * codecs are not connected directly to a DAC, such as the 9200
1160 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1162 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1163 const struct auto_pin_cfg *cfg)
1165 struct sigmatel_spec *spec = codec->spec;
1166 int i, j, conn_len = 0;
1167 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1168 unsigned int wcaps, wtype;
1170 for (i = 0; i < cfg->line_outs; i++) {
1171 nid = cfg->line_out_pins[i];
1172 conn_len = snd_hda_get_connections(codec, nid, conn,
1173 HDA_MAX_CONNECTIONS);
1174 for (j = 0; j < conn_len; j++) {
1175 wcaps = snd_hda_param_read(codec, conn[j],
1176 AC_PAR_AUDIO_WIDGET_CAP);
1177 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1179 if (wtype != AC_WID_AUD_OUT ||
1180 (wcaps & AC_WCAP_DIGITAL))
1182 /* conn[j] is a DAC routed to this line-out */
1183 if (!is_in_dac_nids(spec, conn[j]))
1187 if (j == conn_len) {
1188 /* error out, no available DAC found */
1190 "%s: No available DAC for pin 0x%x\n",
1195 spec->multiout.dac_nids[i] = conn[j];
1196 spec->multiout.num_dacs++;
1198 /* select this DAC in the pin's input mux */
1199 snd_hda_codec_write(codec, nid, 0,
1200 AC_VERB_SET_CONNECT_SEL, j);
1205 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1206 spec->multiout.num_dacs,
1207 spec->multiout.dac_nids[0],
1208 spec->multiout.dac_nids[1],
1209 spec->multiout.dac_nids[2],
1210 spec->multiout.dac_nids[3],
1211 spec->multiout.dac_nids[4]);
1215 /* create volume control/switch for the given prefx type */
1216 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1221 sprintf(name, "%s Playback Volume", pfx);
1222 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1223 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1226 sprintf(name, "%s Playback Switch", pfx);
1227 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1228 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1234 /* add playback controls from the parsed DAC table */
1235 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1236 const struct auto_pin_cfg *cfg)
1238 static const char *chname[4] = {
1239 "Front", "Surround", NULL /*CLFE*/, "Side"
1244 for (i = 0; i < cfg->line_outs; i++) {
1245 if (!spec->multiout.dac_nids[i])
1248 nid = spec->multiout.dac_nids[i];
1252 err = create_controls(spec, "Center", nid, 1);
1255 err = create_controls(spec, "LFE", nid, 2);
1259 err = create_controls(spec, chname[i], nid, 3);
1265 if (spec->line_switch)
1266 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1269 if (spec->mic_switch)
1270 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1276 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1278 if (is_in_dac_nids(spec, nid))
1280 if (spec->multiout.hp_nid == nid)
1285 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1287 if (!spec->multiout.hp_nid)
1288 spec->multiout.hp_nid = nid;
1289 else if (spec->multiout.num_dacs > 4) {
1290 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1293 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1294 spec->multiout.num_dacs++;
1299 /* add playback controls for Speaker and HP outputs */
1300 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1301 struct auto_pin_cfg *cfg)
1303 struct sigmatel_spec *spec = codec->spec;
1305 int i, old_num_dacs, err;
1307 old_num_dacs = spec->multiout.num_dacs;
1308 for (i = 0; i < cfg->hp_outs; i++) {
1309 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1310 if (wid_caps & AC_WCAP_UNSOL_CAP)
1311 spec->hp_detect = 1;
1312 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1313 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1314 if (check_in_dac_nids(spec, nid))
1318 add_spec_dacs(spec, nid);
1320 for (i = 0; i < cfg->speaker_outs; i++) {
1321 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1322 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1323 if (check_in_dac_nids(spec, nid))
1327 add_spec_dacs(spec, nid);
1330 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1331 static const char *pfxs[] = {
1332 "Speaker", "External Speaker", "Speaker2",
1334 err = create_controls(spec, pfxs[i - old_num_dacs],
1335 spec->multiout.dac_nids[i], 3);
1339 if (spec->multiout.hp_nid) {
1341 if (old_num_dacs == spec->multiout.num_dacs)
1345 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1353 /* labels for dmic mux inputs */
1354 static const char *stac92xx_dmic_labels[5] = {
1355 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1356 "Digital Mic 3", "Digital Mic 4"
1359 /* create playback/capture controls for input pins on dmic capable codecs */
1360 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1361 const struct auto_pin_cfg *cfg)
1363 struct sigmatel_spec *spec = codec->spec;
1364 struct hda_input_mux *dimux = &spec->private_dimux;
1365 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1368 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1369 dimux->items[dimux->num_items].index = 0;
1372 for (i = 0; i < spec->num_dmics; i++) {
1375 unsigned int def_conf;
1377 def_conf = snd_hda_codec_read(codec,
1380 AC_VERB_GET_CONFIG_DEFAULT,
1382 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1385 num_cons = snd_hda_get_connections(codec,
1388 HDA_MAX_NUM_INPUTS);
1389 for (j = 0; j < num_cons; j++)
1390 if (con_lst[j] == spec->dmic_nids[i]) {
1396 dimux->items[dimux->num_items].label =
1397 stac92xx_dmic_labels[dimux->num_items];
1398 dimux->items[dimux->num_items].index = index;
1405 /* create playback/capture controls for input pins */
1406 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1408 struct sigmatel_spec *spec = codec->spec;
1409 struct hda_input_mux *imux = &spec->private_imux;
1410 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1413 for (i = 0; i < AUTO_PIN_LAST; i++) {
1416 if (!cfg->input_pins[i])
1419 for (j = 0; j < spec->num_muxes; j++) {
1421 num_cons = snd_hda_get_connections(codec,
1424 HDA_MAX_NUM_INPUTS);
1425 for (k = 0; k < num_cons; k++)
1426 if (con_lst[k] == cfg->input_pins[i]) {
1433 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1434 imux->items[imux->num_items].index = index;
1438 if (imux->num_items) {
1440 * Set the current input for the muxes.
1441 * The STAC9221 has two input muxes with identical source
1442 * NID lists. Hopefully this won't get confused.
1444 for (i = 0; i < spec->num_muxes; i++) {
1445 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1446 AC_VERB_SET_CONNECT_SEL,
1447 imux->items[0].index);
1454 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1456 struct sigmatel_spec *spec = codec->spec;
1459 for (i = 0; i < spec->autocfg.line_outs; i++) {
1460 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1461 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1465 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1467 struct sigmatel_spec *spec = codec->spec;
1470 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1472 pin = spec->autocfg.hp_pins[i];
1473 if (pin) /* connect to front */
1474 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1476 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1478 pin = spec->autocfg.speaker_pins[i];
1479 if (pin) /* connect to front */
1480 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1484 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1486 struct sigmatel_spec *spec = codec->spec;
1489 if ((err = snd_hda_parse_pin_def_config(codec,
1491 spec->dmic_nids)) < 0)
1493 if (! spec->autocfg.line_outs)
1494 return 0; /* can't find valid pin config */
1496 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1498 if (spec->multiout.num_dacs == 0)
1499 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1502 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1503 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1504 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1507 if (spec->num_dmics > 0)
1508 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1509 &spec->autocfg)) < 0)
1512 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1513 if (spec->multiout.max_channels > 2)
1514 spec->surr_switch = 1;
1516 if (spec->autocfg.dig_out_pin)
1517 spec->multiout.dig_out_nid = dig_out;
1518 if (spec->autocfg.dig_in_pin)
1519 spec->dig_in_nid = dig_in;
1521 if (spec->kctl_alloc)
1522 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1524 spec->input_mux = &spec->private_imux;
1525 spec->dinput_mux = &spec->private_dimux;
1530 /* add playback controls for HP output */
1531 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1532 struct auto_pin_cfg *cfg)
1534 struct sigmatel_spec *spec = codec->spec;
1535 hda_nid_t pin = cfg->hp_pins[0];
1536 unsigned int wid_caps;
1541 wid_caps = get_wcaps(codec, pin);
1542 if (wid_caps & AC_WCAP_UNSOL_CAP)
1543 spec->hp_detect = 1;
1548 /* add playback controls for LFE output */
1549 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1550 struct auto_pin_cfg *cfg)
1552 struct sigmatel_spec *spec = codec->spec;
1554 hda_nid_t lfe_pin = 0x0;
1558 * search speaker outs and line outs for a mono speaker pin
1559 * with an amp. If one is found, add LFE controls
1562 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1563 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1564 unsigned long wcaps = get_wcaps(codec, pin);
1565 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1566 if (wcaps == AC_WCAP_OUT_AMP)
1567 /* found a mono speaker with an amp, must be lfe */
1571 /* if speaker_outs is 0, then speakers may be in line_outs */
1572 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1573 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1574 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1576 cfg = snd_hda_codec_read(codec, pin, 0,
1577 AC_VERB_GET_CONFIG_DEFAULT,
1579 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1580 unsigned long wcaps = get_wcaps(codec, pin);
1581 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1582 if (wcaps == AC_WCAP_OUT_AMP)
1583 /* found a mono speaker with an amp,
1591 err = create_controls(spec, "LFE", lfe_pin, 1);
1599 static int stac9200_parse_auto_config(struct hda_codec *codec)
1601 struct sigmatel_spec *spec = codec->spec;
1604 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1607 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1610 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1613 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1616 if (spec->autocfg.dig_out_pin)
1617 spec->multiout.dig_out_nid = 0x05;
1618 if (spec->autocfg.dig_in_pin)
1619 spec->dig_in_nid = 0x04;
1621 if (spec->kctl_alloc)
1622 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1624 spec->input_mux = &spec->private_imux;
1625 spec->dinput_mux = &spec->private_dimux;
1631 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1632 * funky external mute control using GPIO pins.
1635 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1637 unsigned int gpiostate, gpiomask, gpiodir;
1639 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1640 AC_VERB_GET_GPIO_DATA, 0);
1643 gpiostate |= (1 << pin);
1645 gpiostate &= ~(1 << pin);
1647 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1648 AC_VERB_GET_GPIO_MASK, 0);
1649 gpiomask |= (1 << pin);
1651 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1652 AC_VERB_GET_GPIO_DIRECTION, 0);
1653 gpiodir |= (1 << pin);
1655 /* AppleHDA seems to do this -- WTF is this verb?? */
1656 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1658 snd_hda_codec_write(codec, codec->afg, 0,
1659 AC_VERB_SET_GPIO_MASK, gpiomask);
1660 snd_hda_codec_write(codec, codec->afg, 0,
1661 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1665 snd_hda_codec_write(codec, codec->afg, 0,
1666 AC_VERB_SET_GPIO_DATA, gpiostate);
1669 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1672 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1673 snd_hda_codec_write(codec, nid, 0,
1674 AC_VERB_SET_UNSOLICITED_ENABLE,
1675 (AC_USRSP_EN | event));
1678 static int stac92xx_init(struct hda_codec *codec)
1680 struct sigmatel_spec *spec = codec->spec;
1681 struct auto_pin_cfg *cfg = &spec->autocfg;
1684 snd_hda_sequence_write(codec, spec->init);
1687 if (spec->hp_detect) {
1688 /* Enable unsolicited responses on the HP widget */
1689 for (i = 0; i < cfg->hp_outs; i++)
1690 enable_pin_detect(codec, cfg->hp_pins[i],
1692 /* force to enable the first line-out; the others are set up
1695 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1697 stac92xx_auto_init_hp_out(codec);
1698 /* fake event to set up pins */
1699 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1701 stac92xx_auto_init_multi_out(codec);
1702 stac92xx_auto_init_hp_out(codec);
1704 for (i = 0; i < AUTO_PIN_LAST; i++) {
1705 hda_nid_t nid = cfg->input_pins[i];
1707 unsigned int pinctl = AC_PINCTL_IN_EN;
1708 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1709 pinctl |= stac92xx_get_vref(codec, nid);
1710 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1713 if (spec->num_dmics > 0)
1714 for (i = 0; i < spec->num_dmics; i++)
1715 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1718 if (cfg->dig_out_pin)
1719 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1721 if (cfg->dig_in_pin)
1722 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1725 if (spec->gpio_mute) {
1726 stac922x_gpio_mute(codec, 0, 0);
1727 stac922x_gpio_mute(codec, 1, 0);
1733 static void stac92xx_free(struct hda_codec *codec)
1735 struct sigmatel_spec *spec = codec->spec;
1741 if (spec->kctl_alloc) {
1742 for (i = 0; i < spec->num_kctl_used; i++)
1743 kfree(spec->kctl_alloc[i].name);
1744 kfree(spec->kctl_alloc);
1747 if (spec->bios_pin_configs)
1748 kfree(spec->bios_pin_configs);
1753 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1756 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1757 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1759 /* if setting pin direction bits, clear the current
1760 direction bits first */
1761 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1762 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1764 snd_hda_codec_write(codec, nid, 0,
1765 AC_VERB_SET_PIN_WIDGET_CONTROL,
1769 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1772 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1773 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1774 snd_hda_codec_write(codec, nid, 0,
1775 AC_VERB_SET_PIN_WIDGET_CONTROL,
1779 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1783 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1789 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1791 struct sigmatel_spec *spec = codec->spec;
1792 struct auto_pin_cfg *cfg = &spec->autocfg;
1796 for (i = 0; i < cfg->hp_outs; i++) {
1797 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1803 /* disable lineouts, enable hp */
1804 for (i = 0; i < cfg->line_outs; i++)
1805 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1807 for (i = 0; i < cfg->speaker_outs; i++)
1808 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1811 /* enable lineouts, disable hp */
1812 for (i = 0; i < cfg->line_outs; i++)
1813 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1815 for (i = 0; i < cfg->speaker_outs; i++)
1816 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1821 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1823 switch (res >> 26) {
1825 stac92xx_hp_detect(codec, res);
1831 static int stac92xx_resume(struct hda_codec *codec)
1833 struct sigmatel_spec *spec = codec->spec;
1836 stac92xx_init(codec);
1837 stac92xx_set_config_regs(codec);
1838 snd_hda_resume_ctls(codec, spec->mixer);
1839 for (i = 0; i < spec->num_mixers; i++)
1840 snd_hda_resume_ctls(codec, spec->mixers[i]);
1841 if (spec->multiout.dig_out_nid)
1842 snd_hda_resume_spdif_out(codec);
1843 if (spec->dig_in_nid)
1844 snd_hda_resume_spdif_in(codec);
1850 static struct hda_codec_ops stac92xx_patch_ops = {
1851 .build_controls = stac92xx_build_controls,
1852 .build_pcms = stac92xx_build_pcms,
1853 .init = stac92xx_init,
1854 .free = stac92xx_free,
1855 .unsol_event = stac92xx_unsol_event,
1857 .resume = stac92xx_resume,
1861 static int patch_stac9200(struct hda_codec *codec)
1863 struct sigmatel_spec *spec;
1866 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1872 spec->pin_nids = stac9200_pin_nids;
1873 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1876 if (spec->board_config < 0) {
1877 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1878 err = stac92xx_save_bios_config_regs(codec);
1880 stac92xx_free(codec);
1883 spec->pin_configs = spec->bios_pin_configs;
1885 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1886 stac92xx_set_config_regs(codec);
1889 spec->multiout.max_channels = 2;
1890 spec->multiout.num_dacs = 1;
1891 spec->multiout.dac_nids = stac9200_dac_nids;
1892 spec->adc_nids = stac9200_adc_nids;
1893 spec->mux_nids = stac9200_mux_nids;
1894 spec->num_muxes = 1;
1895 spec->num_dmics = 0;
1897 spec->init = stac9200_core_init;
1898 spec->mixer = stac9200_mixer;
1900 err = stac9200_parse_auto_config(codec);
1902 stac92xx_free(codec);
1906 codec->patch_ops = stac92xx_patch_ops;
1911 static int patch_stac925x(struct hda_codec *codec)
1913 struct sigmatel_spec *spec;
1916 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1922 spec->pin_nids = stac925x_pin_nids;
1923 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1927 if (spec->board_config < 0) {
1928 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
1929 "using BIOS defaults\n");
1930 err = stac92xx_save_bios_config_regs(codec);
1932 stac92xx_free(codec);
1935 spec->pin_configs = spec->bios_pin_configs;
1936 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1937 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1938 stac92xx_set_config_regs(codec);
1941 spec->multiout.max_channels = 2;
1942 spec->multiout.num_dacs = 1;
1943 spec->multiout.dac_nids = stac925x_dac_nids;
1944 spec->adc_nids = stac925x_adc_nids;
1945 spec->mux_nids = stac925x_mux_nids;
1946 spec->num_muxes = 1;
1947 switch (codec->vendor_id) {
1948 case 0x83847632: /* STAC9202 */
1949 case 0x83847633: /* STAC9202D */
1950 case 0x83847636: /* STAC9251 */
1951 case 0x83847637: /* STAC9251D */
1952 spec->num_dmics = 1;
1953 spec->dmic_nids = stac925x_dmic_nids;
1956 spec->num_dmics = 0;
1960 spec->init = stac925x_core_init;
1961 spec->mixer = stac925x_mixer;
1963 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1965 if (spec->board_config < 0) {
1966 printk(KERN_WARNING "hda_codec: No auto-config is "
1967 "available, default to model=ref\n");
1968 spec->board_config = STAC_925x_REF;
1974 stac92xx_free(codec);
1978 codec->patch_ops = stac92xx_patch_ops;
1983 static int patch_stac922x(struct hda_codec *codec)
1985 struct sigmatel_spec *spec;
1988 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1993 spec->num_pins = 10;
1994 spec->pin_nids = stac922x_pin_nids;
1995 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1998 if (spec->board_config == STAC_MACMINI) {
1999 spec->gpio_mute = 1;
2000 /* Intel Macs have all same PCI SSID, so we need to check
2001 * codec SSID to distinguish the exact models
2003 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
2004 switch (codec->subsystem_id) {
2005 case 0x106b0a00: /* MacBook First generatoin */
2006 spec->board_config = STAC_MACBOOK;
2008 case 0x106b0200: /* MacBook Pro first generation */
2009 spec->board_config = STAC_MACBOOK_PRO_V1;
2011 case 0x106b1e00: /* MacBook Pro second generation */
2012 spec->board_config = STAC_MACBOOK_PRO_V2;
2014 case 0x106b0700: /* Intel-based iMac */
2015 spec->board_config = STAC_IMAC_INTEL;
2021 if (spec->board_config < 0) {
2022 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2023 "using BIOS defaults\n");
2024 err = stac92xx_save_bios_config_regs(codec);
2026 stac92xx_free(codec);
2029 spec->pin_configs = spec->bios_pin_configs;
2030 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2031 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2032 stac92xx_set_config_regs(codec);
2035 spec->adc_nids = stac922x_adc_nids;
2036 spec->mux_nids = stac922x_mux_nids;
2037 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2038 spec->num_dmics = 0;
2040 spec->init = stac922x_core_init;
2041 spec->mixer = stac922x_mixer;
2043 spec->multiout.dac_nids = spec->dac_nids;
2045 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2047 if (spec->board_config < 0) {
2048 printk(KERN_WARNING "hda_codec: No auto-config is "
2049 "available, default to model=ref\n");
2050 spec->board_config = STAC_D945_REF;
2056 stac92xx_free(codec);
2060 codec->patch_ops = stac92xx_patch_ops;
2065 static int patch_stac927x(struct hda_codec *codec)
2067 struct sigmatel_spec *spec;
2070 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2075 spec->num_pins = 14;
2076 spec->pin_nids = stac927x_pin_nids;
2077 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2081 if (spec->board_config < 0) {
2082 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2083 err = stac92xx_save_bios_config_regs(codec);
2085 stac92xx_free(codec);
2088 spec->pin_configs = spec->bios_pin_configs;
2089 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2090 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2091 stac92xx_set_config_regs(codec);
2094 switch (spec->board_config) {
2096 spec->adc_nids = stac927x_adc_nids;
2097 spec->mux_nids = stac927x_mux_nids;
2098 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2099 spec->num_dmics = 0;
2100 spec->init = d965_core_init;
2101 spec->mixer = stac9227_mixer;
2104 spec->adc_nids = stac927x_adc_nids;
2105 spec->mux_nids = stac927x_mux_nids;
2106 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2107 spec->num_dmics = 0;
2108 spec->init = d965_core_init;
2109 spec->mixer = stac9227_mixer;
2112 spec->adc_nids = stac927x_adc_nids;
2113 spec->mux_nids = stac927x_mux_nids;
2114 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2115 spec->num_dmics = 0;
2116 spec->init = stac927x_core_init;
2117 spec->mixer = stac927x_mixer;
2120 spec->multiout.dac_nids = spec->dac_nids;
2122 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2124 if (spec->board_config < 0) {
2125 printk(KERN_WARNING "hda_codec: No auto-config is "
2126 "available, default to model=ref\n");
2127 spec->board_config = STAC_D965_REF;
2133 stac92xx_free(codec);
2137 codec->patch_ops = stac92xx_patch_ops;
2142 static int patch_stac9205(struct hda_codec *codec)
2144 struct sigmatel_spec *spec;
2147 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2152 spec->num_pins = 14;
2153 spec->pin_nids = stac9205_pin_nids;
2154 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2158 if (spec->board_config < 0) {
2159 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2160 err = stac92xx_save_bios_config_regs(codec);
2162 stac92xx_free(codec);
2165 spec->pin_configs = spec->bios_pin_configs;
2167 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2168 stac92xx_set_config_regs(codec);
2171 spec->adc_nids = stac9205_adc_nids;
2172 spec->mux_nids = stac9205_mux_nids;
2173 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2174 spec->dmic_nids = stac9205_dmic_nids;
2175 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2176 spec->dmux_nid = 0x1d;
2178 spec->init = stac9205_core_init;
2179 spec->mixer = stac9205_mixer;
2181 spec->multiout.dac_nids = spec->dac_nids;
2183 /* Configure GPIO0 as EAPD output */
2184 snd_hda_codec_write(codec, codec->afg, 0,
2185 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2186 /* Configure GPIO0 as CMOS */
2187 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2188 /* Assert GPIO0 high */
2189 snd_hda_codec_write(codec, codec->afg, 0,
2190 AC_VERB_SET_GPIO_DATA, 0x00000001);
2192 snd_hda_codec_write(codec, codec->afg, 0,
2193 AC_VERB_SET_GPIO_MASK, 0x00000001);
2195 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2197 if (spec->board_config < 0) {
2198 printk(KERN_WARNING "hda_codec: No auto-config is "
2199 "available, default to model=ref\n");
2200 spec->board_config = STAC_9205_REF;
2206 stac92xx_free(codec);
2210 codec->patch_ops = stac92xx_patch_ops;
2219 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2220 static hda_nid_t vaio_dacs[] = { 0x2 };
2221 #define VAIO_HP_DAC 0x5
2222 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2223 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2225 static struct hda_input_mux vaio_mux = {
2228 /* { "HP", 0x0 }, */
2235 static struct hda_verb vaio_init[] = {
2236 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2237 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2238 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2239 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2240 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2241 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2242 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2243 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2244 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2245 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2246 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2250 static struct hda_verb vaio_ar_init[] = {
2251 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2252 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2253 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2254 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2255 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2256 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2257 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2258 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2259 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2260 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2261 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2262 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2263 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2267 /* bind volumes of both NID 0x02 and 0x05 */
2268 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2269 struct snd_ctl_elem_value *ucontrol)
2271 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2272 long *valp = ucontrol->value.integer.value;
2275 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2276 0x7f, valp[0] & 0x7f);
2277 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2278 0x7f, valp[1] & 0x7f);
2279 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2280 0x7f, valp[0] & 0x7f);
2281 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2282 0x7f, valp[1] & 0x7f);
2286 /* bind volumes of both NID 0x02 and 0x05 */
2287 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2288 struct snd_ctl_elem_value *ucontrol)
2290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2291 long *valp = ucontrol->value.integer.value;
2294 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2295 0x80, (valp[0] ? 0 : 0x80));
2296 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2297 0x80, (valp[1] ? 0 : 0x80));
2298 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2299 0x80, (valp[0] ? 0 : 0x80));
2300 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2301 0x80, (valp[1] ? 0 : 0x80));
2305 static struct snd_kcontrol_new vaio_mixer[] = {
2307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2308 .name = "Master Playback Volume",
2309 .info = snd_hda_mixer_amp_volume_info,
2310 .get = snd_hda_mixer_amp_volume_get,
2311 .put = vaio_master_vol_put,
2312 .tlv = { .c = snd_hda_mixer_amp_tlv },
2313 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2316 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2317 .name = "Master Playback Switch",
2318 .info = snd_hda_mixer_amp_switch_info,
2319 .get = snd_hda_mixer_amp_switch_get,
2320 .put = vaio_master_sw_put,
2321 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2323 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2324 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2325 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2327 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2328 .name = "Capture Source",
2330 .info = stac92xx_mux_enum_info,
2331 .get = stac92xx_mux_enum_get,
2332 .put = stac92xx_mux_enum_put,
2337 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2340 .name = "Master Playback Volume",
2341 .info = snd_hda_mixer_amp_volume_info,
2342 .get = snd_hda_mixer_amp_volume_get,
2343 .put = vaio_master_vol_put,
2344 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2348 .name = "Master Playback Switch",
2349 .info = snd_hda_mixer_amp_switch_info,
2350 .get = snd_hda_mixer_amp_switch_get,
2351 .put = vaio_master_sw_put,
2352 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2354 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2355 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2356 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2357 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2358 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2360 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2361 .name = "Capture Source",
2363 .info = stac92xx_mux_enum_info,
2364 .get = stac92xx_mux_enum_get,
2365 .put = stac92xx_mux_enum_put,
2370 static struct hda_codec_ops stac9872_patch_ops = {
2371 .build_controls = stac92xx_build_controls,
2372 .build_pcms = stac92xx_build_pcms,
2373 .init = stac92xx_init,
2374 .free = stac92xx_free,
2376 .resume = stac92xx_resume,
2380 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2382 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2384 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2386 /* AR Series. id=0x83847664 and subsys=104D1300 */
2391 static const char *stac9872_models[STAC_9872_MODELS] = {
2392 [CXD9872RD_VAIO] = "vaio",
2393 [CXD9872AKD_VAIO] = "vaio-ar",
2396 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2397 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2398 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2399 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2400 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2404 static int patch_stac9872(struct hda_codec *codec)
2406 struct sigmatel_spec *spec;
2409 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2412 if (board_config < 0)
2413 /* unknown config, let generic-parser do its job... */
2414 return snd_hda_parse_generic_codec(codec);
2416 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2421 switch (board_config) {
2422 case CXD9872RD_VAIO:
2423 case STAC9872AK_VAIO:
2424 case STAC9872K_VAIO:
2425 spec->mixer = vaio_mixer;
2426 spec->init = vaio_init;
2427 spec->multiout.max_channels = 2;
2428 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2429 spec->multiout.dac_nids = vaio_dacs;
2430 spec->multiout.hp_nid = VAIO_HP_DAC;
2431 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2432 spec->adc_nids = vaio_adcs;
2433 spec->input_mux = &vaio_mux;
2434 spec->mux_nids = vaio_mux_nids;
2437 case CXD9872AKD_VAIO:
2438 spec->mixer = vaio_ar_mixer;
2439 spec->init = vaio_ar_init;
2440 spec->multiout.max_channels = 2;
2441 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2442 spec->multiout.dac_nids = vaio_dacs;
2443 spec->multiout.hp_nid = VAIO_HP_DAC;
2444 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2445 spec->adc_nids = vaio_adcs;
2446 spec->input_mux = &vaio_mux;
2447 spec->mux_nids = vaio_mux_nids;
2451 codec->patch_ops = stac9872_patch_ops;
2459 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2460 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2461 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2462 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2463 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2464 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2465 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2466 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2467 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2468 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2469 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2470 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2471 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2472 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2473 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2474 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2475 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2476 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2477 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2478 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2479 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2480 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2481 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2482 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2483 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2484 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2485 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2486 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2487 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2488 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2489 /* The following does not take into account .id=0x83847661 when subsys =
2490 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2491 * currently not fully supported.
2493 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2494 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2495 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2496 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2497 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2498 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2499 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2500 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2501 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2502 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2503 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },