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
74 struct sigmatel_spec {
75 struct snd_kcontrol_new *mixers[4];
76 unsigned int num_mixers;
79 unsigned int surr_switch: 1;
80 unsigned int line_switch: 1;
81 unsigned int mic_switch: 1;
82 unsigned int alt_switch: 1;
83 unsigned int hp_detect: 1;
84 unsigned int gpio_mute: 1;
87 struct hda_multi_out multiout;
88 hda_nid_t dac_nids[5];
92 unsigned int num_adcs;
94 unsigned int num_muxes;
96 unsigned int num_dmics;
102 unsigned int num_pins;
103 unsigned int *pin_configs;
104 unsigned int *bios_pin_configs;
106 /* codec specific stuff */
107 struct hda_verb *init;
108 struct snd_kcontrol_new *mixer;
111 struct hda_input_mux *dinput_mux;
112 unsigned int cur_dmux;
113 struct hda_input_mux *input_mux;
114 unsigned int cur_mux[3];
117 unsigned int io_switch[2];
119 struct hda_pcm pcm_rec[2]; /* PCM information */
121 /* dynamic controls and input_mux */
122 struct auto_pin_cfg autocfg;
123 unsigned int num_kctl_alloc, num_kctl_used;
124 struct snd_kcontrol_new *kctl_alloc;
125 struct hda_input_mux private_dimux;
126 struct hda_input_mux private_imux;
129 static hda_nid_t stac9200_adc_nids[1] = {
133 static hda_nid_t stac9200_mux_nids[1] = {
137 static hda_nid_t stac9200_dac_nids[1] = {
141 static hda_nid_t stac925x_adc_nids[1] = {
145 static hda_nid_t stac925x_mux_nids[1] = {
149 static hda_nid_t stac925x_dac_nids[1] = {
153 static hda_nid_t stac922x_adc_nids[2] = {
157 static hda_nid_t stac922x_mux_nids[2] = {
161 static hda_nid_t stac927x_adc_nids[3] = {
165 static hda_nid_t stac927x_mux_nids[3] = {
169 static hda_nid_t stac9205_adc_nids[2] = {
173 static hda_nid_t stac9205_mux_nids[2] = {
177 static hda_nid_t stac9205_dmic_nids[3] = {
181 static hda_nid_t stac9200_pin_nids[8] = {
182 0x08, 0x09, 0x0d, 0x0e,
183 0x0f, 0x10, 0x11, 0x12,
186 static hda_nid_t stac925x_pin_nids[8] = {
187 0x07, 0x08, 0x0a, 0x0b,
188 0x0c, 0x0d, 0x10, 0x11,
191 static hda_nid_t stac922x_pin_nids[10] = {
192 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
193 0x0f, 0x10, 0x11, 0x15, 0x1b,
196 static hda_nid_t stac927x_pin_nids[14] = {
197 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
198 0x0f, 0x10, 0x11, 0x12, 0x13,
199 0x14, 0x21, 0x22, 0x23,
202 static hda_nid_t stac9205_pin_nids[12] = {
203 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
204 0x0f, 0x14, 0x16, 0x17, 0x18,
209 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
210 struct snd_ctl_elem_info *uinfo)
212 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
213 struct sigmatel_spec *spec = codec->spec;
214 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
217 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol)
220 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
221 struct sigmatel_spec *spec = codec->spec;
223 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
227 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol)
230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
231 struct sigmatel_spec *spec = codec->spec;
233 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
234 spec->dmux_nid, &spec->cur_dmux);
237 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
240 struct sigmatel_spec *spec = codec->spec;
241 return snd_hda_input_mux_info(spec->input_mux, uinfo);
244 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct sigmatel_spec *spec = codec->spec;
248 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
250 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
254 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct sigmatel_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
261 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
264 static struct hda_verb stac9200_core_init[] = {
265 /* set dac0mux for dac converter */
266 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
270 static struct hda_verb stac925x_core_init[] = {
271 /* set dac0mux for dac converter */
272 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
276 static struct hda_verb stac922x_core_init[] = {
277 /* set master volume and direct control */
278 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
282 static struct hda_verb d965_core_init[] = {
283 /* set master volume and direct control */
284 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
285 /* unmute node 0x1b */
286 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
287 /* select node 0x03 as DAC */
288 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
292 static struct hda_verb stac927x_core_init[] = {
293 /* set master volume and direct control */
294 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
298 static struct hda_verb stac9205_core_init[] = {
299 /* set master volume and direct control */
300 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
304 static struct snd_kcontrol_new stac9200_mixer[] = {
305 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
306 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
309 .name = "Input Source",
311 .info = stac92xx_mux_enum_info,
312 .get = stac92xx_mux_enum_get,
313 .put = stac92xx_mux_enum_put,
315 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
316 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
317 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
321 static struct snd_kcontrol_new stac925x_mixer[] = {
322 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
323 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
325 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
326 .name = "Input Source",
328 .info = stac92xx_mux_enum_info,
329 .get = stac92xx_mux_enum_get,
330 .put = stac92xx_mux_enum_put,
332 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
333 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
334 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
338 /* This needs to be generated dynamically based on sequence */
339 static struct snd_kcontrol_new stac922x_mixer[] = {
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,
348 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
349 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
350 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
354 /* This needs to be generated dynamically based on sequence */
355 static struct snd_kcontrol_new stac9227_mixer[] = {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Input Source",
360 .info = stac92xx_mux_enum_info,
361 .get = stac92xx_mux_enum_get,
362 .put = stac92xx_mux_enum_put,
364 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
365 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
369 static struct snd_kcontrol_new stac927x_mixer[] = {
371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
372 .name = "Input Source",
374 .info = stac92xx_mux_enum_info,
375 .get = stac92xx_mux_enum_get,
376 .put = stac92xx_mux_enum_put,
378 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
379 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
380 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
384 static struct snd_kcontrol_new stac9205_mixer[] = {
386 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
387 .name = "Digital Input Source",
389 .info = stac92xx_dmux_enum_info,
390 .get = stac92xx_dmux_enum_get,
391 .put = stac92xx_dmux_enum_put,
394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
395 .name = "Input Source",
397 .info = stac92xx_mux_enum_info,
398 .get = stac92xx_mux_enum_get,
399 .put = stac92xx_mux_enum_put,
401 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
402 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
403 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
407 static int stac92xx_build_controls(struct hda_codec *codec)
409 struct sigmatel_spec *spec = codec->spec;
413 err = snd_hda_add_new_ctls(codec, spec->mixer);
417 for (i = 0; i < spec->num_mixers; i++) {
418 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
423 if (spec->multiout.dig_out_nid) {
424 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
428 if (spec->dig_in_nid) {
429 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
436 static unsigned int ref9200_pin_configs[8] = {
437 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
438 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
441 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
442 [STAC_REF] = ref9200_pin_configs,
445 static const char *stac9200_models[STAC_9200_MODELS] = {
449 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
450 /* SigmaTel reference board */
451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
452 "DFI LanParty", STAC_REF),
453 /* Dell laptops have BIOS problem */
454 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
455 "Dell Inspiron 630m", STAC_REF),
456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
457 "Dell Latitude D620", STAC_REF),
458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
459 "Dell Latitude 120L", STAC_REF),
460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
461 "Dell Latitude D820", STAC_REF),
462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
463 "Dell Inspiron E1705/9400", STAC_REF),
464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
465 "Dell XPS M1710", STAC_REF),
466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
467 "Dell Precision M90", STAC_REF),
471 static unsigned int ref925x_pin_configs[8] = {
472 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
473 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
476 static unsigned int stac925x_MA6_pin_configs[8] = {
477 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
478 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
481 static unsigned int stac925xM2_2_pin_configs[8] = {
482 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
483 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
486 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
487 [STAC_REF] = ref925x_pin_configs,
488 [STAC_M2_2] = stac925xM2_2_pin_configs,
489 [STAC_MA6] = stac925x_MA6_pin_configs,
492 static const char *stac925x_models[STAC_925x_MODELS] = {
494 [STAC_M2_2] = "m2-2",
498 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
499 /* SigmaTel reference board */
500 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
501 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
502 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
503 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
504 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
508 static unsigned int ref922x_pin_configs[10] = {
509 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
510 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
511 0x40000100, 0x40000100,
514 static unsigned int d945gtp3_pin_configs[10] = {
515 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
516 0x40000100, 0x40000100, 0x40000100, 0x40000100,
517 0x02a19120, 0x40000100,
520 static unsigned int d945gtp5_pin_configs[10] = {
521 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
522 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
523 0x02a19320, 0x40000100,
526 static unsigned int macbook_pin_configs[10] = {
527 0x0321e230, 0x03a1e020, 0x400000fd, 0x9017e110,
528 0x400000fe, 0x0381e021, 0x1345e240, 0x13c5e22e,
529 0x400000fc, 0x400000fb,
532 static unsigned int macbook_pro_pin_configs[10] = {
533 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
534 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
535 0x400000fc, 0x400000fb,
538 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
539 [STAC_D945_REF] = ref922x_pin_configs,
540 [STAC_D945GTP3] = d945gtp3_pin_configs,
541 [STAC_D945GTP5] = d945gtp5_pin_configs,
542 [STAC_MACMINI] = d945gtp5_pin_configs,
543 [STAC_MACBOOK] = macbook_pin_configs,
544 [STAC_MACBOOK_PRO] = macbook_pro_pin_configs,
547 static const char *stac922x_models[STAC_922X_MODELS] = {
548 [STAC_D945_REF] = "ref",
549 [STAC_D945GTP5] = "5stack",
550 [STAC_D945GTP3] = "3stack",
551 [STAC_MACMINI] = "macmini",
552 [STAC_MACBOOK] = "macbook",
553 [STAC_MACBOOK_PRO] = "macbook-pro",
556 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
557 /* SigmaTel reference board */
558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
559 "DFI LanParty", STAC_D945_REF),
560 /* Intel 945G based systems */
561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
562 "Intel D945G", STAC_D945GTP3),
563 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
564 "Intel D945G", STAC_D945GTP3),
565 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
566 "Intel D945G", STAC_D945GTP3),
567 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
568 "Intel D945G", STAC_D945GTP3),
569 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
570 "Intel D945G", STAC_D945GTP3),
571 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
572 "Intel D945G", STAC_D945GTP3),
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
574 "Intel D945G", STAC_D945GTP3),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
576 "Intel D945G", STAC_D945GTP3),
577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
578 "Intel D945G", STAC_D945GTP3),
579 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
580 "Intel D945G", STAC_D945GTP3),
581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
582 "Intel D945G", STAC_D945GTP3),
583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
584 "Intel D945G", STAC_D945GTP3),
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
586 "Intel D945G", STAC_D945GTP3),
587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
588 "Intel D945G", STAC_D945GTP3),
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
590 "Intel D945G", STAC_D945GTP3),
591 /* Intel D945G 5-stack systems */
592 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
593 "Intel D945G", STAC_D945GTP5),
594 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
595 "Intel D945G", STAC_D945GTP5),
596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
597 "Intel D945G", STAC_D945GTP5),
598 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
599 "Intel D945G", STAC_D945GTP5),
600 /* Intel 945P based systems */
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
602 "Intel D945P", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
604 "Intel D945P", STAC_D945GTP3),
605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
606 "Intel D945P", STAC_D945GTP3),
607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
608 "Intel D945P", STAC_D945GTP3),
609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
610 "Intel D945P", STAC_D945GTP3),
611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
612 "Intel D945P", STAC_D945GTP5),
614 /* Apple Mac Mini (early 2006) */
615 SND_PCI_QUIRK(0x8384, 0x7680,
616 "Mac Mini", STAC_MACMINI),
620 static unsigned int ref927x_pin_configs[14] = {
621 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
622 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
623 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
624 0x01c42190, 0x40000100,
627 static unsigned int d965_3st_pin_configs[14] = {
628 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
629 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
630 0x40000100, 0x40000100, 0x40000100, 0x40000100,
631 0x40000100, 0x40000100
634 static unsigned int d965_5st_pin_configs[14] = {
635 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
636 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
637 0x40000100, 0x40000100, 0x40000100, 0x01442070,
638 0x40000100, 0x40000100
641 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
642 [STAC_D965_REF] = ref927x_pin_configs,
643 [STAC_D965_3ST] = d965_3st_pin_configs,
644 [STAC_D965_5ST] = d965_5st_pin_configs,
647 static const char *stac927x_models[STAC_927X_MODELS] = {
648 [STAC_D965_REF] = "ref",
649 [STAC_D965_3ST] = "3stack",
650 [STAC_D965_5ST] = "5stack",
653 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
654 /* SigmaTel reference board */
655 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
656 "DFI LanParty", STAC_D965_REF),
657 /* Intel 946 based systems */
658 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
659 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
660 /* 965 based 3 stack systems */
661 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
662 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
664 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
665 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
666 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
668 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
669 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
677 /* 965 based 5 stack systems */
678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
690 static unsigned int ref9205_pin_configs[12] = {
691 0x40000100, 0x40000100, 0x01016011, 0x01014010,
692 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
693 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
696 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
700 static const char *stac9205_models[STAC_9205_MODELS] = {
701 [STAC_9205_REF] = "ref",
704 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
705 /* SigmaTel reference board */
706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
707 "DFI LanParty", STAC_9205_REF),
711 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
714 struct sigmatel_spec *spec = codec->spec;
716 if (! spec->bios_pin_configs) {
717 spec->bios_pin_configs = kcalloc(spec->num_pins,
718 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
719 if (! spec->bios_pin_configs)
723 for (i = 0; i < spec->num_pins; i++) {
724 hda_nid_t nid = spec->pin_nids[i];
725 unsigned int pin_cfg;
727 pin_cfg = snd_hda_codec_read(codec, nid, 0,
728 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
729 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
731 spec->bios_pin_configs[i] = pin_cfg;
737 static void stac92xx_set_config_regs(struct hda_codec *codec)
740 struct sigmatel_spec *spec = codec->spec;
741 unsigned int pin_cfg;
743 if (! spec->pin_nids || ! spec->pin_configs)
746 for (i = 0; i < spec->num_pins; i++) {
747 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
748 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
749 spec->pin_configs[i] & 0x000000ff);
750 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
751 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
752 (spec->pin_configs[i] & 0x0000ff00) >> 8);
753 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
754 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
755 (spec->pin_configs[i] & 0x00ff0000) >> 16);
756 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
757 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
758 spec->pin_configs[i] >> 24);
759 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
760 AC_VERB_GET_CONFIG_DEFAULT,
762 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
767 * Analog playback callbacks
769 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
770 struct hda_codec *codec,
771 struct snd_pcm_substream *substream)
773 struct sigmatel_spec *spec = codec->spec;
774 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
777 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
778 struct hda_codec *codec,
779 unsigned int stream_tag,
781 struct snd_pcm_substream *substream)
783 struct sigmatel_spec *spec = codec->spec;
784 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
787 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
788 struct hda_codec *codec,
789 struct snd_pcm_substream *substream)
791 struct sigmatel_spec *spec = codec->spec;
792 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
796 * Digital playback callbacks
798 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
799 struct hda_codec *codec,
800 struct snd_pcm_substream *substream)
802 struct sigmatel_spec *spec = codec->spec;
803 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
806 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
807 struct hda_codec *codec,
808 struct snd_pcm_substream *substream)
810 struct sigmatel_spec *spec = codec->spec;
811 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
816 * Analog capture callbacks
818 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
819 struct hda_codec *codec,
820 unsigned int stream_tag,
822 struct snd_pcm_substream *substream)
824 struct sigmatel_spec *spec = codec->spec;
826 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
827 stream_tag, 0, format);
831 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
832 struct hda_codec *codec,
833 struct snd_pcm_substream *substream)
835 struct sigmatel_spec *spec = codec->spec;
837 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
841 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
845 /* NID is set in stac92xx_build_pcms */
847 .open = stac92xx_dig_playback_pcm_open,
848 .close = stac92xx_dig_playback_pcm_close
852 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
856 /* NID is set in stac92xx_build_pcms */
859 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
863 .nid = 0x02, /* NID to query formats and rates */
865 .open = stac92xx_playback_pcm_open,
866 .prepare = stac92xx_playback_pcm_prepare,
867 .cleanup = stac92xx_playback_pcm_cleanup
871 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
875 .nid = 0x06, /* NID to query formats and rates */
877 .open = stac92xx_playback_pcm_open,
878 .prepare = stac92xx_playback_pcm_prepare,
879 .cleanup = stac92xx_playback_pcm_cleanup
883 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
887 /* NID is set in stac92xx_build_pcms */
889 .prepare = stac92xx_capture_pcm_prepare,
890 .cleanup = stac92xx_capture_pcm_cleanup
894 static int stac92xx_build_pcms(struct hda_codec *codec)
896 struct sigmatel_spec *spec = codec->spec;
897 struct hda_pcm *info = spec->pcm_rec;
900 codec->pcm_info = info;
902 info->name = "STAC92xx Analog";
903 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
904 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
905 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
907 if (spec->alt_switch) {
910 info->name = "STAC92xx Analog Alt";
911 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
914 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
917 info->name = "STAC92xx Digital";
918 if (spec->multiout.dig_out_nid) {
919 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
920 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
922 if (spec->dig_in_nid) {
923 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
924 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
931 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
933 unsigned int pincap = snd_hda_param_read(codec, nid,
935 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
936 if (pincap & AC_PINCAP_VREF_100)
937 return AC_PINCTL_VREF_100;
938 if (pincap & AC_PINCAP_VREF_80)
939 return AC_PINCTL_VREF_80;
940 if (pincap & AC_PINCAP_VREF_50)
941 return AC_PINCTL_VREF_50;
942 if (pincap & AC_PINCAP_VREF_GRD)
943 return AC_PINCTL_VREF_GRD;
947 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
950 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
953 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
955 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
957 uinfo->value.integer.min = 0;
958 uinfo->value.integer.max = 1;
962 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
964 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
965 struct sigmatel_spec *spec = codec->spec;
966 int io_idx = kcontrol-> private_value & 0xff;
968 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
972 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
975 struct sigmatel_spec *spec = codec->spec;
976 hda_nid_t nid = kcontrol->private_value >> 8;
977 int io_idx = kcontrol-> private_value & 0xff;
978 unsigned short val = ucontrol->value.integer.value[0];
980 spec->io_switch[io_idx] = val;
983 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
985 unsigned int pinctl = AC_PINCTL_IN_EN;
986 if (io_idx) /* set VREF for mic */
987 pinctl |= stac92xx_get_vref(codec, nid);
988 stac92xx_auto_set_pinctl(codec, nid, pinctl);
993 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
994 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
997 .info = stac92xx_io_switch_info, \
998 .get = stac92xx_io_switch_get, \
999 .put = stac92xx_io_switch_put, \
1000 .private_value = xpval, \
1005 STAC_CTL_WIDGET_VOL,
1006 STAC_CTL_WIDGET_MUTE,
1007 STAC_CTL_WIDGET_IO_SWITCH,
1010 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1011 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1012 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1013 STAC_CODEC_IO_SWITCH(NULL, 0),
1016 /* add dynamic controls */
1017 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1019 struct snd_kcontrol_new *knew;
1021 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1022 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1024 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1027 if (spec->kctl_alloc) {
1028 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1029 kfree(spec->kctl_alloc);
1031 spec->kctl_alloc = knew;
1032 spec->num_kctl_alloc = num;
1035 knew = &spec->kctl_alloc[spec->num_kctl_used];
1036 *knew = stac92xx_control_templates[type];
1037 knew->name = kstrdup(name, GFP_KERNEL);
1040 knew->private_value = val;
1041 spec->num_kctl_used++;
1045 /* flag inputs as additional dynamic lineouts */
1046 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1048 struct sigmatel_spec *spec = codec->spec;
1050 switch (cfg->line_outs) {
1052 /* add line-in as side */
1053 if (cfg->input_pins[AUTO_PIN_LINE]) {
1054 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1055 spec->line_switch = 1;
1060 /* add line-in as clfe and mic as side */
1061 if (cfg->input_pins[AUTO_PIN_LINE]) {
1062 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1063 spec->line_switch = 1;
1066 if (cfg->input_pins[AUTO_PIN_MIC]) {
1067 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1068 spec->mic_switch = 1;
1073 /* add line-in as surr and mic as clfe */
1074 if (cfg->input_pins[AUTO_PIN_LINE]) {
1075 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1076 spec->line_switch = 1;
1079 if (cfg->input_pins[AUTO_PIN_MIC]) {
1080 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1081 spec->mic_switch = 1;
1091 * XXX The line_out pin widget connection list may not be set to the
1092 * desired DAC nid. This is the case on 927x where ports A and B can
1093 * be routed to several DACs.
1095 * This requires an analysis of the line-out/hp pin configuration
1096 * to provide a best fit for pin/DAC configurations that are routable.
1097 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1098 * A and B is not supported.
1100 /* fill in the dac_nids table from the parsed pin configuration */
1101 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1102 const struct auto_pin_cfg *cfg)
1104 struct sigmatel_spec *spec = codec->spec;
1108 /* check the pins hardwired to audio widget */
1109 for (i = 0; i < cfg->line_outs; i++) {
1110 nid = cfg->line_out_pins[i];
1111 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1112 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1115 spec->multiout.num_dacs = cfg->line_outs;
1120 /* create volume control/switch for the given prefx type */
1121 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1126 sprintf(name, "%s Playback Volume", pfx);
1127 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1128 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1131 sprintf(name, "%s Playback Switch", pfx);
1132 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1133 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1139 /* add playback controls from the parsed DAC table */
1140 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1141 const struct auto_pin_cfg *cfg)
1143 static const char *chname[4] = {
1144 "Front", "Surround", NULL /*CLFE*/, "Side"
1149 for (i = 0; i < cfg->line_outs; i++) {
1150 if (!spec->multiout.dac_nids[i])
1153 nid = spec->multiout.dac_nids[i];
1157 err = create_controls(spec, "Center", nid, 1);
1160 err = create_controls(spec, "LFE", nid, 2);
1164 err = create_controls(spec, chname[i], nid, 3);
1170 if (spec->line_switch)
1171 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1174 if (spec->mic_switch)
1175 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1181 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1185 for (i = 0; i < spec->multiout.num_dacs; i++) {
1186 if (spec->multiout.dac_nids[i] == nid)
1189 if (spec->multiout.hp_nid == nid)
1194 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1196 if (!spec->multiout.hp_nid)
1197 spec->multiout.hp_nid = nid;
1198 else if (spec->multiout.num_dacs > 4) {
1199 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1202 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1203 spec->multiout.num_dacs++;
1208 /* add playback controls for Speaker and HP outputs */
1209 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1210 struct auto_pin_cfg *cfg)
1212 struct sigmatel_spec *spec = codec->spec;
1214 int i, old_num_dacs, err;
1216 old_num_dacs = spec->multiout.num_dacs;
1217 for (i = 0; i < cfg->hp_outs; i++) {
1218 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1219 if (wid_caps & AC_WCAP_UNSOL_CAP)
1220 spec->hp_detect = 1;
1221 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1222 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1223 if (check_in_dac_nids(spec, nid))
1227 add_spec_dacs(spec, nid);
1229 for (i = 0; i < cfg->speaker_outs; i++) {
1230 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1231 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1232 if (check_in_dac_nids(spec, nid))
1234 if (check_in_dac_nids(spec, nid))
1238 add_spec_dacs(spec, nid);
1241 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1242 static const char *pfxs[] = {
1243 "Speaker", "External Speaker", "Speaker2",
1245 err = create_controls(spec, pfxs[i - old_num_dacs],
1246 spec->multiout.dac_nids[i], 3);
1250 if (spec->multiout.hp_nid) {
1252 if (old_num_dacs == spec->multiout.num_dacs)
1256 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1264 /* labels for dmic mux inputs */
1265 static const char *stac92xx_dmic_labels[5] = {
1266 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1267 "Digital Mic 3", "Digital Mic 4"
1270 /* create playback/capture controls for input pins on dmic capable codecs */
1271 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1272 const struct auto_pin_cfg *cfg)
1274 struct sigmatel_spec *spec = codec->spec;
1275 struct hda_input_mux *dimux = &spec->private_dimux;
1276 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1279 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1280 dimux->items[dimux->num_items].index = 0;
1283 for (i = 0; i < spec->num_dmics; i++) {
1286 unsigned int def_conf;
1288 def_conf = snd_hda_codec_read(codec,
1291 AC_VERB_GET_CONFIG_DEFAULT,
1293 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1296 num_cons = snd_hda_get_connections(codec,
1299 HDA_MAX_NUM_INPUTS);
1300 for (j = 0; j < num_cons; j++)
1301 if (con_lst[j] == spec->dmic_nids[i]) {
1307 dimux->items[dimux->num_items].label =
1308 stac92xx_dmic_labels[dimux->num_items];
1309 dimux->items[dimux->num_items].index = index;
1316 /* create playback/capture controls for input pins */
1317 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1319 struct sigmatel_spec *spec = codec->spec;
1320 struct hda_input_mux *imux = &spec->private_imux;
1321 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1324 for (i = 0; i < AUTO_PIN_LAST; i++) {
1327 if (!cfg->input_pins[i])
1330 for (j = 0; j < spec->num_muxes; j++) {
1332 num_cons = snd_hda_get_connections(codec,
1335 HDA_MAX_NUM_INPUTS);
1336 for (k = 0; k < num_cons; k++)
1337 if (con_lst[k] == cfg->input_pins[i]) {
1344 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1345 imux->items[imux->num_items].index = index;
1349 if (imux->num_items == 1) {
1351 * Set the current input for the muxes.
1352 * The STAC9221 has two input muxes with identical source
1353 * NID lists. Hopefully this won't get confused.
1355 for (i = 0; i < spec->num_muxes; i++) {
1356 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1357 AC_VERB_SET_CONNECT_SEL,
1358 imux->items[0].index);
1365 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1367 struct sigmatel_spec *spec = codec->spec;
1370 for (i = 0; i < spec->autocfg.line_outs; i++) {
1371 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1372 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1376 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1378 struct sigmatel_spec *spec = codec->spec;
1381 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1383 pin = spec->autocfg.hp_pins[i];
1384 if (pin) /* connect to front */
1385 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1387 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1389 pin = spec->autocfg.speaker_pins[i];
1390 if (pin) /* connect to front */
1391 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1395 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1397 struct sigmatel_spec *spec = codec->spec;
1400 if ((err = snd_hda_parse_pin_def_config(codec,
1402 spec->dmic_nids)) < 0)
1404 if (! spec->autocfg.line_outs)
1405 return 0; /* can't find valid pin config */
1407 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1409 if (spec->multiout.num_dacs == 0)
1410 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1413 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1414 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1415 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1418 if (spec->num_dmics > 0)
1419 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1420 &spec->autocfg)) < 0)
1423 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1424 if (spec->multiout.max_channels > 2)
1425 spec->surr_switch = 1;
1427 if (spec->autocfg.dig_out_pin)
1428 spec->multiout.dig_out_nid = dig_out;
1429 if (spec->autocfg.dig_in_pin)
1430 spec->dig_in_nid = dig_in;
1432 if (spec->kctl_alloc)
1433 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1435 spec->input_mux = &spec->private_imux;
1436 spec->dinput_mux = &spec->private_dimux;
1441 /* add playback controls for HP output */
1442 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1443 struct auto_pin_cfg *cfg)
1445 struct sigmatel_spec *spec = codec->spec;
1446 hda_nid_t pin = cfg->hp_pins[0];
1447 unsigned int wid_caps;
1452 wid_caps = get_wcaps(codec, pin);
1453 if (wid_caps & AC_WCAP_UNSOL_CAP)
1454 spec->hp_detect = 1;
1459 /* add playback controls for LFE output */
1460 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1461 struct auto_pin_cfg *cfg)
1463 struct sigmatel_spec *spec = codec->spec;
1465 hda_nid_t lfe_pin = 0x0;
1469 * search speaker outs and line outs for a mono speaker pin
1470 * with an amp. If one is found, add LFE controls
1473 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1474 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1475 unsigned long wcaps = get_wcaps(codec, pin);
1476 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1477 if (wcaps == AC_WCAP_OUT_AMP)
1478 /* found a mono speaker with an amp, must be lfe */
1482 /* if speaker_outs is 0, then speakers may be in line_outs */
1483 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1484 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1485 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1487 cfg = snd_hda_codec_read(codec, pin, 0,
1488 AC_VERB_GET_CONFIG_DEFAULT,
1490 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1491 unsigned long wcaps = get_wcaps(codec, pin);
1492 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1493 if (wcaps == AC_WCAP_OUT_AMP)
1494 /* found a mono speaker with an amp,
1502 err = create_controls(spec, "LFE", lfe_pin, 1);
1510 static int stac9200_parse_auto_config(struct hda_codec *codec)
1512 struct sigmatel_spec *spec = codec->spec;
1515 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1518 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1521 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1524 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1527 if (spec->autocfg.dig_out_pin)
1528 spec->multiout.dig_out_nid = 0x05;
1529 if (spec->autocfg.dig_in_pin)
1530 spec->dig_in_nid = 0x04;
1532 if (spec->kctl_alloc)
1533 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1535 spec->input_mux = &spec->private_imux;
1536 spec->dinput_mux = &spec->private_dimux;
1542 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1543 * funky external mute control using GPIO pins.
1546 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1548 unsigned int gpiostate, gpiomask, gpiodir;
1550 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1551 AC_VERB_GET_GPIO_DATA, 0);
1554 gpiostate |= (1 << pin);
1556 gpiostate &= ~(1 << pin);
1558 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1559 AC_VERB_GET_GPIO_MASK, 0);
1560 gpiomask |= (1 << pin);
1562 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1563 AC_VERB_GET_GPIO_DIRECTION, 0);
1564 gpiodir |= (1 << pin);
1566 /* AppleHDA seems to do this -- WTF is this verb?? */
1567 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1569 snd_hda_codec_write(codec, codec->afg, 0,
1570 AC_VERB_SET_GPIO_MASK, gpiomask);
1571 snd_hda_codec_write(codec, codec->afg, 0,
1572 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1576 snd_hda_codec_write(codec, codec->afg, 0,
1577 AC_VERB_SET_GPIO_DATA, gpiostate);
1580 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1583 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1584 snd_hda_codec_write(codec, nid, 0,
1585 AC_VERB_SET_UNSOLICITED_ENABLE,
1586 (AC_USRSP_EN | event));
1589 static int stac92xx_init(struct hda_codec *codec)
1591 struct sigmatel_spec *spec = codec->spec;
1592 struct auto_pin_cfg *cfg = &spec->autocfg;
1595 snd_hda_sequence_write(codec, spec->init);
1598 if (spec->hp_detect) {
1599 /* Enable unsolicited responses on the HP widget */
1600 for (i = 0; i < cfg->hp_outs; i++)
1601 enable_pin_detect(codec, cfg->hp_pins[i],
1603 stac92xx_auto_init_hp_out(codec);
1604 /* fake event to set up pins */
1605 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1607 stac92xx_auto_init_multi_out(codec);
1608 stac92xx_auto_init_hp_out(codec);
1610 for (i = 0; i < AUTO_PIN_LAST; i++) {
1611 hda_nid_t nid = cfg->input_pins[i];
1613 unsigned int pinctl = AC_PINCTL_IN_EN;
1614 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1615 pinctl |= stac92xx_get_vref(codec, nid);
1616 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1619 if (spec->num_dmics > 0)
1620 for (i = 0; i < spec->num_dmics; i++)
1621 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1624 if (cfg->dig_out_pin)
1625 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1627 if (cfg->dig_in_pin)
1628 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1631 if (spec->gpio_mute) {
1632 stac922x_gpio_mute(codec, 0, 0);
1633 stac922x_gpio_mute(codec, 1, 0);
1639 static void stac92xx_free(struct hda_codec *codec)
1641 struct sigmatel_spec *spec = codec->spec;
1647 if (spec->kctl_alloc) {
1648 for (i = 0; i < spec->num_kctl_used; i++)
1649 kfree(spec->kctl_alloc[i].name);
1650 kfree(spec->kctl_alloc);
1653 if (spec->bios_pin_configs)
1654 kfree(spec->bios_pin_configs);
1659 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1662 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1663 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1664 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1666 snd_hda_codec_write(codec, nid, 0,
1667 AC_VERB_SET_PIN_WIDGET_CONTROL,
1671 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1674 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1675 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1676 snd_hda_codec_write(codec, nid, 0,
1677 AC_VERB_SET_PIN_WIDGET_CONTROL,
1681 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1685 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1691 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1693 struct sigmatel_spec *spec = codec->spec;
1694 struct auto_pin_cfg *cfg = &spec->autocfg;
1698 for (i = 0; i < cfg->hp_outs; i++) {
1699 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1705 /* disable lineouts, enable hp */
1706 for (i = 0; i < cfg->line_outs; i++)
1707 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1709 for (i = 0; i < cfg->speaker_outs; i++)
1710 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1713 /* enable lineouts, disable hp */
1714 for (i = 0; i < cfg->line_outs; i++)
1715 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1717 for (i = 0; i < cfg->speaker_outs; i++)
1718 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1723 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1725 switch (res >> 26) {
1727 stac92xx_hp_detect(codec, res);
1733 static int stac92xx_resume(struct hda_codec *codec)
1735 struct sigmatel_spec *spec = codec->spec;
1738 stac92xx_init(codec);
1739 stac92xx_set_config_regs(codec);
1740 for (i = 0; i < spec->num_mixers; i++)
1741 snd_hda_resume_ctls(codec, spec->mixers[i]);
1742 if (spec->multiout.dig_out_nid)
1743 snd_hda_resume_spdif_out(codec);
1744 if (spec->dig_in_nid)
1745 snd_hda_resume_spdif_in(codec);
1751 static struct hda_codec_ops stac92xx_patch_ops = {
1752 .build_controls = stac92xx_build_controls,
1753 .build_pcms = stac92xx_build_pcms,
1754 .init = stac92xx_init,
1755 .free = stac92xx_free,
1756 .unsol_event = stac92xx_unsol_event,
1758 .resume = stac92xx_resume,
1762 static int patch_stac9200(struct hda_codec *codec)
1764 struct sigmatel_spec *spec;
1767 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1773 spec->pin_nids = stac9200_pin_nids;
1774 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1777 if (spec->board_config < 0) {
1778 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1779 err = stac92xx_save_bios_config_regs(codec);
1781 stac92xx_free(codec);
1784 spec->pin_configs = spec->bios_pin_configs;
1786 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1787 stac92xx_set_config_regs(codec);
1790 spec->multiout.max_channels = 2;
1791 spec->multiout.num_dacs = 1;
1792 spec->multiout.dac_nids = stac9200_dac_nids;
1793 spec->adc_nids = stac9200_adc_nids;
1794 spec->mux_nids = stac9200_mux_nids;
1795 spec->num_muxes = 1;
1796 spec->num_dmics = 0;
1798 spec->init = stac9200_core_init;
1799 spec->mixer = stac9200_mixer;
1801 err = stac9200_parse_auto_config(codec);
1803 stac92xx_free(codec);
1807 codec->patch_ops = stac92xx_patch_ops;
1812 static int patch_stac925x(struct hda_codec *codec)
1814 struct sigmatel_spec *spec;
1817 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1823 spec->pin_nids = stac925x_pin_nids;
1824 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1828 if (spec->board_config < 0) {
1829 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1830 err = stac92xx_save_bios_config_regs(codec);
1832 stac92xx_free(codec);
1835 spec->pin_configs = spec->bios_pin_configs;
1836 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1837 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1838 stac92xx_set_config_regs(codec);
1841 spec->multiout.max_channels = 2;
1842 spec->multiout.num_dacs = 1;
1843 spec->multiout.dac_nids = stac925x_dac_nids;
1844 spec->adc_nids = stac925x_adc_nids;
1845 spec->mux_nids = stac925x_mux_nids;
1846 spec->num_muxes = 1;
1847 spec->num_dmics = 0;
1849 spec->init = stac925x_core_init;
1850 spec->mixer = stac925x_mixer;
1852 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1854 if (spec->board_config < 0) {
1855 printk(KERN_WARNING "hda_codec: No auto-config is "
1856 "available, default to model=ref\n");
1857 spec->board_config = STAC_925x_REF;
1863 stac92xx_free(codec);
1867 codec->patch_ops = stac92xx_patch_ops;
1872 static int patch_stac922x(struct hda_codec *codec)
1874 struct sigmatel_spec *spec;
1877 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1882 spec->num_pins = 10;
1883 spec->pin_nids = stac922x_pin_nids;
1884 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1887 if (spec->board_config == STAC_MACMINI) {
1888 spec->gpio_mute = 1;
1889 /* Intel Macs have all same PCI SSID, so we need to check
1890 * codec SSID to distinguish the exact models
1892 switch (codec->subsystem_id) {
1894 spec->board_config = STAC_MACBOOK_PRO;
1900 if (spec->board_config < 0) {
1901 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1902 "using BIOS defaults\n");
1903 err = stac92xx_save_bios_config_regs(codec);
1905 stac92xx_free(codec);
1908 spec->pin_configs = spec->bios_pin_configs;
1909 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
1910 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1911 stac92xx_set_config_regs(codec);
1914 spec->adc_nids = stac922x_adc_nids;
1915 spec->mux_nids = stac922x_mux_nids;
1916 spec->num_muxes = 2;
1917 spec->num_dmics = 0;
1919 spec->init = stac922x_core_init;
1920 spec->mixer = stac922x_mixer;
1922 spec->multiout.dac_nids = spec->dac_nids;
1924 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1926 if (spec->board_config < 0) {
1927 printk(KERN_WARNING "hda_codec: No auto-config is "
1928 "available, default to model=ref\n");
1929 spec->board_config = STAC_D945_REF;
1935 stac92xx_free(codec);
1939 codec->patch_ops = stac92xx_patch_ops;
1944 static int patch_stac927x(struct hda_codec *codec)
1946 struct sigmatel_spec *spec;
1949 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1954 spec->num_pins = 14;
1955 spec->pin_nids = stac927x_pin_nids;
1956 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1960 if (spec->board_config < 0) {
1961 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1962 err = stac92xx_save_bios_config_regs(codec);
1964 stac92xx_free(codec);
1967 spec->pin_configs = spec->bios_pin_configs;
1968 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
1969 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1970 stac92xx_set_config_regs(codec);
1973 switch (spec->board_config) {
1975 spec->adc_nids = stac927x_adc_nids;
1976 spec->mux_nids = stac927x_mux_nids;
1977 spec->num_muxes = 3;
1978 spec->num_dmics = 0;
1979 spec->init = d965_core_init;
1980 spec->mixer = stac9227_mixer;
1983 spec->adc_nids = stac927x_adc_nids;
1984 spec->mux_nids = stac927x_mux_nids;
1985 spec->num_muxes = 3;
1986 spec->num_dmics = 0;
1987 spec->init = d965_core_init;
1988 spec->mixer = stac9227_mixer;
1991 spec->adc_nids = stac927x_adc_nids;
1992 spec->mux_nids = stac927x_mux_nids;
1993 spec->num_muxes = 3;
1994 spec->num_dmics = 0;
1995 spec->init = stac927x_core_init;
1996 spec->mixer = stac927x_mixer;
1999 spec->multiout.dac_nids = spec->dac_nids;
2001 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2003 if (spec->board_config < 0) {
2004 printk(KERN_WARNING "hda_codec: No auto-config is "
2005 "available, default to model=ref\n");
2006 spec->board_config = STAC_D965_REF;
2012 stac92xx_free(codec);
2016 codec->patch_ops = stac92xx_patch_ops;
2021 static int patch_stac9205(struct hda_codec *codec)
2023 struct sigmatel_spec *spec;
2026 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2031 spec->num_pins = 14;
2032 spec->pin_nids = stac9205_pin_nids;
2033 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2037 if (spec->board_config < 0) {
2038 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2039 err = stac92xx_save_bios_config_regs(codec);
2041 stac92xx_free(codec);
2044 spec->pin_configs = spec->bios_pin_configs;
2046 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2047 stac92xx_set_config_regs(codec);
2050 spec->adc_nids = stac9205_adc_nids;
2051 spec->mux_nids = stac9205_mux_nids;
2052 spec->num_muxes = 2;
2053 spec->dmic_nids = stac9205_dmic_nids;
2054 spec->num_dmics = 2;
2055 spec->dmux_nid = 0x1d;
2057 spec->init = stac9205_core_init;
2058 spec->mixer = stac9205_mixer;
2060 spec->multiout.dac_nids = spec->dac_nids;
2062 /* Configure GPIO0 as EAPD output */
2063 snd_hda_codec_write(codec, codec->afg, 0,
2064 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2065 /* Configure GPIO0 as CMOS */
2066 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2067 /* Assert GPIO0 high */
2068 snd_hda_codec_write(codec, codec->afg, 0,
2069 AC_VERB_SET_GPIO_DATA, 0x00000001);
2071 snd_hda_codec_write(codec, codec->afg, 0,
2072 AC_VERB_SET_GPIO_MASK, 0x00000001);
2074 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2076 if (spec->board_config < 0) {
2077 printk(KERN_WARNING "hda_codec: No auto-config is "
2078 "available, default to model=ref\n");
2079 spec->board_config = STAC_9205_REF;
2085 stac92xx_free(codec);
2089 codec->patch_ops = stac92xx_patch_ops;
2098 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2099 static hda_nid_t vaio_dacs[] = { 0x2 };
2100 #define VAIO_HP_DAC 0x5
2101 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2102 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2104 static struct hda_input_mux vaio_mux = {
2107 /* { "HP", 0x0 }, */
2114 static struct hda_verb vaio_init[] = {
2115 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2116 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2117 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2118 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2119 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2120 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2121 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2122 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2123 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2124 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2125 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2129 static struct hda_verb vaio_ar_init[] = {
2130 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2131 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2132 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2133 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2134 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2135 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2136 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2137 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2138 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2139 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2140 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2141 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2142 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2146 /* bind volumes of both NID 0x02 and 0x05 */
2147 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2148 struct snd_ctl_elem_value *ucontrol)
2150 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2151 long *valp = ucontrol->value.integer.value;
2154 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2155 0x7f, valp[0] & 0x7f);
2156 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2157 0x7f, valp[1] & 0x7f);
2158 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2159 0x7f, valp[0] & 0x7f);
2160 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2161 0x7f, valp[1] & 0x7f);
2165 /* bind volumes of both NID 0x02 and 0x05 */
2166 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2167 struct snd_ctl_elem_value *ucontrol)
2169 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2170 long *valp = ucontrol->value.integer.value;
2173 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2174 0x80, (valp[0] ? 0 : 0x80));
2175 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2176 0x80, (valp[1] ? 0 : 0x80));
2177 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2178 0x80, (valp[0] ? 0 : 0x80));
2179 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2180 0x80, (valp[1] ? 0 : 0x80));
2184 static struct snd_kcontrol_new vaio_mixer[] = {
2186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2187 .name = "Master Playback Volume",
2188 .info = snd_hda_mixer_amp_volume_info,
2189 .get = snd_hda_mixer_amp_volume_get,
2190 .put = vaio_master_vol_put,
2191 .tlv = { .c = snd_hda_mixer_amp_tlv },
2192 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2196 .name = "Master Playback Switch",
2197 .info = snd_hda_mixer_amp_switch_info,
2198 .get = snd_hda_mixer_amp_switch_get,
2199 .put = vaio_master_sw_put,
2200 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2202 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2203 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2204 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2207 .name = "Capture Source",
2209 .info = stac92xx_mux_enum_info,
2210 .get = stac92xx_mux_enum_get,
2211 .put = stac92xx_mux_enum_put,
2216 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2219 .name = "Master Playback Volume",
2220 .info = snd_hda_mixer_amp_volume_info,
2221 .get = snd_hda_mixer_amp_volume_get,
2222 .put = vaio_master_vol_put,
2223 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2226 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2227 .name = "Master Playback Switch",
2228 .info = snd_hda_mixer_amp_switch_info,
2229 .get = snd_hda_mixer_amp_switch_get,
2230 .put = vaio_master_sw_put,
2231 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2233 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2234 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2235 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2236 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2237 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2240 .name = "Capture Source",
2242 .info = stac92xx_mux_enum_info,
2243 .get = stac92xx_mux_enum_get,
2244 .put = stac92xx_mux_enum_put,
2249 static struct hda_codec_ops stac9872_patch_ops = {
2250 .build_controls = stac92xx_build_controls,
2251 .build_pcms = stac92xx_build_pcms,
2252 .init = stac92xx_init,
2253 .free = stac92xx_free,
2255 .resume = stac92xx_resume,
2259 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2261 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2263 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2265 /* AR Series. id=0x83847664 and subsys=104D1300 */
2270 static const char *stac9872_models[STAC_9872_MODELS] = {
2271 [CXD9872RD_VAIO] = "vaio",
2272 [CXD9872AKD_VAIO] = "vaio-ar",
2275 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2276 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2277 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2278 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2282 static int patch_stac9872(struct hda_codec *codec)
2284 struct sigmatel_spec *spec;
2287 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2290 if (board_config < 0)
2291 /* unknown config, let generic-parser do its job... */
2292 return snd_hda_parse_generic_codec(codec);
2294 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2299 switch (board_config) {
2300 case CXD9872RD_VAIO:
2301 case STAC9872AK_VAIO:
2302 case STAC9872K_VAIO:
2303 spec->mixer = vaio_mixer;
2304 spec->init = vaio_init;
2305 spec->multiout.max_channels = 2;
2306 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2307 spec->multiout.dac_nids = vaio_dacs;
2308 spec->multiout.hp_nid = VAIO_HP_DAC;
2309 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2310 spec->adc_nids = vaio_adcs;
2311 spec->input_mux = &vaio_mux;
2312 spec->mux_nids = vaio_mux_nids;
2315 case CXD9872AKD_VAIO:
2316 spec->mixer = vaio_ar_mixer;
2317 spec->init = vaio_ar_init;
2318 spec->multiout.max_channels = 2;
2319 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2320 spec->multiout.dac_nids = vaio_dacs;
2321 spec->multiout.hp_nid = VAIO_HP_DAC;
2322 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2323 spec->adc_nids = vaio_adcs;
2324 spec->input_mux = &vaio_mux;
2325 spec->mux_nids = vaio_mux_nids;
2329 codec->patch_ops = stac9872_patch_ops;
2337 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2338 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2339 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2340 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2341 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2342 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2343 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2344 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2345 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2346 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2347 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2348 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2349 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2350 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2351 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2352 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2353 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2354 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2355 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2356 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2357 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2358 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2359 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2360 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2361 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2362 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2363 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2364 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2365 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2366 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2367 /* The following does not take into account .id=0x83847661 when subsys =
2368 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2369 * currently not fully supported.
2371 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2372 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2373 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2374 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2375 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2376 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2377 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2378 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2379 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2380 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2381 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },