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
76 struct sigmatel_spec {
77 struct snd_kcontrol_new *mixers[4];
78 unsigned int num_mixers;
81 unsigned int surr_switch: 1;
82 unsigned int line_switch: 1;
83 unsigned int mic_switch: 1;
84 unsigned int alt_switch: 1;
85 unsigned int hp_detect: 1;
86 unsigned int gpio_mute: 1;
89 struct hda_multi_out multiout;
90 hda_nid_t dac_nids[5];
94 unsigned int num_adcs;
96 unsigned int num_muxes;
98 unsigned int num_dmics;
100 hda_nid_t dig_in_nid;
104 unsigned int num_pins;
105 unsigned int *pin_configs;
106 unsigned int *bios_pin_configs;
108 /* codec specific stuff */
109 struct hda_verb *init;
110 struct snd_kcontrol_new *mixer;
113 struct hda_input_mux *dinput_mux;
114 unsigned int cur_dmux;
115 struct hda_input_mux *input_mux;
116 unsigned int cur_mux[3];
119 unsigned int io_switch[2];
121 struct hda_pcm pcm_rec[2]; /* PCM information */
123 /* dynamic controls and input_mux */
124 struct auto_pin_cfg autocfg;
125 unsigned int num_kctl_alloc, num_kctl_used;
126 struct snd_kcontrol_new *kctl_alloc;
127 struct hda_input_mux private_dimux;
128 struct hda_input_mux private_imux;
131 static hda_nid_t stac9200_adc_nids[1] = {
135 static hda_nid_t stac9200_mux_nids[1] = {
139 static hda_nid_t stac9200_dac_nids[1] = {
143 static hda_nid_t stac925x_adc_nids[1] = {
147 static hda_nid_t stac925x_mux_nids[1] = {
151 static hda_nid_t stac925x_dac_nids[1] = {
155 static hda_nid_t stac922x_adc_nids[2] = {
159 static hda_nid_t stac922x_mux_nids[2] = {
163 static hda_nid_t stac927x_adc_nids[3] = {
167 static hda_nid_t stac927x_mux_nids[3] = {
171 static hda_nid_t stac9205_adc_nids[2] = {
175 static hda_nid_t stac9205_mux_nids[2] = {
179 static hda_nid_t stac9205_dmic_nids[2] = {
183 static hda_nid_t stac9200_pin_nids[8] = {
184 0x08, 0x09, 0x0d, 0x0e,
185 0x0f, 0x10, 0x11, 0x12,
188 static hda_nid_t stac925x_pin_nids[8] = {
189 0x07, 0x08, 0x0a, 0x0b,
190 0x0c, 0x0d, 0x10, 0x11,
193 static hda_nid_t stac922x_pin_nids[10] = {
194 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
195 0x0f, 0x10, 0x11, 0x15, 0x1b,
198 static hda_nid_t stac927x_pin_nids[14] = {
199 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
200 0x0f, 0x10, 0x11, 0x12, 0x13,
201 0x14, 0x21, 0x22, 0x23,
204 static hda_nid_t stac9205_pin_nids[12] = {
205 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
206 0x0f, 0x14, 0x16, 0x17, 0x18,
211 static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_info *uinfo)
214 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
215 struct sigmatel_spec *spec = codec->spec;
216 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
219 static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
220 struct snd_ctl_elem_value *ucontrol)
222 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
223 struct sigmatel_spec *spec = codec->spec;
225 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
229 static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol)
232 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
233 struct sigmatel_spec *spec = codec->spec;
235 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
236 spec->dmux_nid, &spec->cur_dmux);
239 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
241 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
242 struct sigmatel_spec *spec = codec->spec;
243 return snd_hda_input_mux_info(spec->input_mux, uinfo);
246 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct sigmatel_spec *spec = codec->spec;
250 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
252 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
256 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct sigmatel_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
262 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
263 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
266 static struct hda_verb stac9200_core_init[] = {
267 /* set dac0mux for dac converter */
268 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
272 static struct hda_verb stac925x_core_init[] = {
273 /* set dac0mux for dac converter */
274 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
278 static struct hda_verb stac922x_core_init[] = {
279 /* set master volume and direct control */
280 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
284 static struct hda_verb d965_core_init[] = {
285 /* set master volume and direct control */
286 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
287 /* unmute node 0x1b */
288 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
289 /* select node 0x03 as DAC */
290 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
294 static struct hda_verb stac927x_core_init[] = {
295 /* set master volume and direct control */
296 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
300 static struct hda_verb stac9205_core_init[] = {
301 /* set master volume and direct control */
302 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
306 static struct snd_kcontrol_new stac9200_mixer[] = {
307 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
308 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
311 .name = "Input Source",
313 .info = stac92xx_mux_enum_info,
314 .get = stac92xx_mux_enum_get,
315 .put = stac92xx_mux_enum_put,
317 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
318 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
319 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
323 static struct snd_kcontrol_new stac925x_mixer[] = {
324 HDA_CODEC_VOLUME("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
325 HDA_CODEC_MUTE("Master Playback Switch", 0xe, 0, HDA_OUTPUT),
327 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
328 .name = "Input Source",
330 .info = stac92xx_mux_enum_info,
331 .get = stac92xx_mux_enum_get,
332 .put = stac92xx_mux_enum_put,
334 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
335 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
336 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
340 /* This needs to be generated dynamically based on sequence */
341 static struct snd_kcontrol_new stac922x_mixer[] = {
343 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
344 .name = "Input Source",
346 .info = stac92xx_mux_enum_info,
347 .get = stac92xx_mux_enum_get,
348 .put = stac92xx_mux_enum_put,
350 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
351 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
352 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
356 /* This needs to be generated dynamically based on sequence */
357 static struct snd_kcontrol_new stac9227_mixer[] = {
359 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
360 .name = "Input Source",
362 .info = stac92xx_mux_enum_info,
363 .get = stac92xx_mux_enum_get,
364 .put = stac92xx_mux_enum_put,
366 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
367 HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
371 static struct snd_kcontrol_new stac927x_mixer[] = {
373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
374 .name = "Input Source",
376 .info = stac92xx_mux_enum_info,
377 .get = stac92xx_mux_enum_get,
378 .put = stac92xx_mux_enum_put,
380 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
381 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
382 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
386 static struct snd_kcontrol_new stac9205_mixer[] = {
388 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
389 .name = "Digital Input Source",
391 .info = stac92xx_dmux_enum_info,
392 .get = stac92xx_dmux_enum_get,
393 .put = stac92xx_dmux_enum_put,
396 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
397 .name = "Input Source",
399 .info = stac92xx_mux_enum_info,
400 .get = stac92xx_mux_enum_get,
401 .put = stac92xx_mux_enum_put,
403 HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
404 HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
405 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
409 static int stac92xx_build_controls(struct hda_codec *codec)
411 struct sigmatel_spec *spec = codec->spec;
415 err = snd_hda_add_new_ctls(codec, spec->mixer);
419 for (i = 0; i < spec->num_mixers; i++) {
420 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
425 if (spec->multiout.dig_out_nid) {
426 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
430 if (spec->dig_in_nid) {
431 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
438 static unsigned int ref9200_pin_configs[8] = {
439 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
440 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
443 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
444 [STAC_REF] = ref9200_pin_configs,
447 static const char *stac9200_models[STAC_9200_MODELS] = {
451 static struct snd_pci_quirk stac9200_cfg_tbl[] = {
452 /* SigmaTel reference board */
453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
454 "DFI LanParty", STAC_REF),
455 /* Dell laptops have BIOS problem */
456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
457 "Dell Inspiron 630m", STAC_REF),
458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
459 "Dell Latitude D620", STAC_REF),
460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
461 "Dell Latitude 120L", STAC_REF),
462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
463 "Dell Latitude D820", STAC_REF),
464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
465 "Dell Inspiron E1705/9400", STAC_REF),
466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
467 "Dell XPS M1710", STAC_REF),
468 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
469 "Dell Precision M90", STAC_REF),
473 static unsigned int ref925x_pin_configs[8] = {
474 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
475 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
478 static unsigned int stac925x_MA6_pin_configs[8] = {
479 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
480 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
483 static unsigned int stac925xM2_2_pin_configs[8] = {
484 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
485 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
488 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
489 [STAC_REF] = ref925x_pin_configs,
490 [STAC_M2_2] = stac925xM2_2_pin_configs,
491 [STAC_MA6] = stac925x_MA6_pin_configs,
494 static const char *stac925x_models[STAC_925x_MODELS] = {
496 [STAC_M2_2] = "m2-2",
500 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
501 /* SigmaTel reference board */
502 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
503 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
504 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
505 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
506 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
510 static unsigned int ref922x_pin_configs[10] = {
511 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
512 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
513 0x40000100, 0x40000100,
516 static unsigned int d945gtp3_pin_configs[10] = {
517 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
518 0x40000100, 0x40000100, 0x40000100, 0x40000100,
519 0x02a19120, 0x40000100,
522 static unsigned int d945gtp5_pin_configs[10] = {
523 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
524 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
525 0x02a19320, 0x40000100,
528 static unsigned int macbook_pro_v1_pin_configs[10] = {
529 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
530 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
531 0x02a19320, 0x400000fb
534 static unsigned int macbook_pro_v2_pin_configs[10] = {
535 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
536 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
537 0x400000fc, 0x400000fb,
540 static unsigned int imac_intel_pin_configs[10] = {
541 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
542 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
543 0x400000fc, 0x400000fb,
546 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
547 [STAC_D945_REF] = ref922x_pin_configs,
548 [STAC_D945GTP3] = d945gtp3_pin_configs,
549 [STAC_D945GTP5] = d945gtp5_pin_configs,
550 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
551 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
552 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
553 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
554 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
557 static const char *stac922x_models[STAC_922X_MODELS] = {
558 [STAC_D945_REF] = "ref",
559 [STAC_D945GTP5] = "5stack",
560 [STAC_D945GTP3] = "3stack",
561 [STAC_MACMINI] = "macmini",
562 [STAC_MACBOOK] = "macbook",
563 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
564 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
565 [STAC_IMAC_INTEL] = "imac-intel",
568 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
569 /* SigmaTel reference board */
570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
571 "DFI LanParty", STAC_D945_REF),
572 /* Intel 945G based systems */
573 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
574 "Intel D945G", STAC_D945GTP3),
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
576 "Intel D945G", STAC_D945GTP3),
577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
578 "Intel D945G", STAC_D945GTP3),
579 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
580 "Intel D945G", STAC_D945GTP3),
581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
582 "Intel D945G", STAC_D945GTP3),
583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
584 "Intel D945G", STAC_D945GTP3),
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
586 "Intel D945G", STAC_D945GTP3),
587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
588 "Intel D945G", STAC_D945GTP3),
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
590 "Intel D945G", STAC_D945GTP3),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
592 "Intel D945G", STAC_D945GTP3),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
594 "Intel D945G", STAC_D945GTP3),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
596 "Intel D945G", STAC_D945GTP3),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
602 "Intel D945G", STAC_D945GTP3),
603 /* Intel D945G 5-stack systems */
604 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
605 "Intel D945G", STAC_D945GTP5),
606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
607 "Intel D945G", STAC_D945GTP5),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
609 "Intel D945G", STAC_D945GTP5),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
611 "Intel D945G", STAC_D945GTP5),
612 /* Intel 945P based systems */
613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
614 "Intel D945P", STAC_D945GTP3),
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
616 "Intel D945P", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
618 "Intel D945P", STAC_D945GTP3),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
620 "Intel D945P", STAC_D945GTP3),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
622 "Intel D945P", STAC_D945GTP3),
623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
624 "Intel D945P", STAC_D945GTP5),
626 /* Apple Mac Mini (early 2006) */
627 SND_PCI_QUIRK(0x8384, 0x7680,
628 "Mac Mini", STAC_MACMINI),
632 static unsigned int ref927x_pin_configs[14] = {
633 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
634 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
635 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
636 0x01c42190, 0x40000100,
639 static unsigned int d965_3st_pin_configs[14] = {
640 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
641 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
642 0x40000100, 0x40000100, 0x40000100, 0x40000100,
643 0x40000100, 0x40000100
646 static unsigned int d965_5st_pin_configs[14] = {
647 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
648 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
649 0x40000100, 0x40000100, 0x40000100, 0x01442070,
650 0x40000100, 0x40000100
653 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
654 [STAC_D965_REF] = ref927x_pin_configs,
655 [STAC_D965_3ST] = d965_3st_pin_configs,
656 [STAC_D965_5ST] = d965_5st_pin_configs,
659 static const char *stac927x_models[STAC_927X_MODELS] = {
660 [STAC_D965_REF] = "ref",
661 [STAC_D965_3ST] = "3stack",
662 [STAC_D965_5ST] = "5stack",
665 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
666 /* SigmaTel reference board */
667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
668 "DFI LanParty", STAC_D965_REF),
669 /* Intel 946 based systems */
670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
672 /* 965 based 3 stack systems */
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
674 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
689 /* 965 based 5 stack systems */
690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
692 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
702 static unsigned int ref9205_pin_configs[12] = {
703 0x40000100, 0x40000100, 0x01016011, 0x01014010,
704 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
705 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
708 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
712 static const char *stac9205_models[STAC_9205_MODELS] = {
713 [STAC_9205_REF] = "ref",
716 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
717 /* SigmaTel reference board */
718 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
719 "DFI LanParty", STAC_9205_REF),
723 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
726 struct sigmatel_spec *spec = codec->spec;
728 if (! spec->bios_pin_configs) {
729 spec->bios_pin_configs = kcalloc(spec->num_pins,
730 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
731 if (! spec->bios_pin_configs)
735 for (i = 0; i < spec->num_pins; i++) {
736 hda_nid_t nid = spec->pin_nids[i];
737 unsigned int pin_cfg;
739 pin_cfg = snd_hda_codec_read(codec, nid, 0,
740 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
741 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
743 spec->bios_pin_configs[i] = pin_cfg;
749 static void stac92xx_set_config_regs(struct hda_codec *codec)
752 struct sigmatel_spec *spec = codec->spec;
753 unsigned int pin_cfg;
755 if (! spec->pin_nids || ! spec->pin_configs)
758 for (i = 0; i < spec->num_pins; i++) {
759 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
760 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
761 spec->pin_configs[i] & 0x000000ff);
762 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
763 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
764 (spec->pin_configs[i] & 0x0000ff00) >> 8);
765 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
766 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
767 (spec->pin_configs[i] & 0x00ff0000) >> 16);
768 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
769 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
770 spec->pin_configs[i] >> 24);
771 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
772 AC_VERB_GET_CONFIG_DEFAULT,
774 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
779 * Analog playback callbacks
781 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
782 struct hda_codec *codec,
783 struct snd_pcm_substream *substream)
785 struct sigmatel_spec *spec = codec->spec;
786 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
789 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
790 struct hda_codec *codec,
791 unsigned int stream_tag,
793 struct snd_pcm_substream *substream)
795 struct sigmatel_spec *spec = codec->spec;
796 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
799 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
800 struct hda_codec *codec,
801 struct snd_pcm_substream *substream)
803 struct sigmatel_spec *spec = codec->spec;
804 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
808 * Digital playback callbacks
810 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
811 struct hda_codec *codec,
812 struct snd_pcm_substream *substream)
814 struct sigmatel_spec *spec = codec->spec;
815 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
818 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
819 struct hda_codec *codec,
820 struct snd_pcm_substream *substream)
822 struct sigmatel_spec *spec = codec->spec;
823 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
826 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
827 struct hda_codec *codec,
828 unsigned int stream_tag,
830 struct snd_pcm_substream *substream)
832 struct sigmatel_spec *spec = codec->spec;
833 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
834 stream_tag, format, substream);
839 * Analog capture callbacks
841 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
842 struct hda_codec *codec,
843 unsigned int stream_tag,
845 struct snd_pcm_substream *substream)
847 struct sigmatel_spec *spec = codec->spec;
849 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
850 stream_tag, 0, format);
854 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
855 struct hda_codec *codec,
856 struct snd_pcm_substream *substream)
858 struct sigmatel_spec *spec = codec->spec;
860 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
864 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
868 /* NID is set in stac92xx_build_pcms */
870 .open = stac92xx_dig_playback_pcm_open,
871 .close = stac92xx_dig_playback_pcm_close,
872 .prepare = stac92xx_dig_playback_pcm_prepare
876 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
880 /* NID is set in stac92xx_build_pcms */
883 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
887 .nid = 0x02, /* NID to query formats and rates */
889 .open = stac92xx_playback_pcm_open,
890 .prepare = stac92xx_playback_pcm_prepare,
891 .cleanup = stac92xx_playback_pcm_cleanup
895 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
899 .nid = 0x06, /* NID to query formats and rates */
901 .open = stac92xx_playback_pcm_open,
902 .prepare = stac92xx_playback_pcm_prepare,
903 .cleanup = stac92xx_playback_pcm_cleanup
907 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
911 /* NID is set in stac92xx_build_pcms */
913 .prepare = stac92xx_capture_pcm_prepare,
914 .cleanup = stac92xx_capture_pcm_cleanup
918 static int stac92xx_build_pcms(struct hda_codec *codec)
920 struct sigmatel_spec *spec = codec->spec;
921 struct hda_pcm *info = spec->pcm_rec;
924 codec->pcm_info = info;
926 info->name = "STAC92xx Analog";
927 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
928 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
929 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
931 if (spec->alt_switch) {
934 info->name = "STAC92xx Analog Alt";
935 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
938 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
941 info->name = "STAC92xx Digital";
942 if (spec->multiout.dig_out_nid) {
943 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
944 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
946 if (spec->dig_in_nid) {
947 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
948 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
955 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
957 unsigned int pincap = snd_hda_param_read(codec, nid,
959 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
960 if (pincap & AC_PINCAP_VREF_100)
961 return AC_PINCTL_VREF_100;
962 if (pincap & AC_PINCAP_VREF_80)
963 return AC_PINCTL_VREF_80;
964 if (pincap & AC_PINCAP_VREF_50)
965 return AC_PINCTL_VREF_50;
966 if (pincap & AC_PINCAP_VREF_GRD)
967 return AC_PINCTL_VREF_GRD;
971 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
974 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
977 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
979 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
981 uinfo->value.integer.min = 0;
982 uinfo->value.integer.max = 1;
986 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
988 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
989 struct sigmatel_spec *spec = codec->spec;
990 int io_idx = kcontrol-> private_value & 0xff;
992 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
996 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
998 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
999 struct sigmatel_spec *spec = codec->spec;
1000 hda_nid_t nid = kcontrol->private_value >> 8;
1001 int io_idx = kcontrol-> private_value & 0xff;
1002 unsigned short val = ucontrol->value.integer.value[0];
1004 spec->io_switch[io_idx] = val;
1007 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1009 unsigned int pinctl = AC_PINCTL_IN_EN;
1010 if (io_idx) /* set VREF for mic */
1011 pinctl |= stac92xx_get_vref(codec, nid);
1012 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1017 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1018 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1021 .info = stac92xx_io_switch_info, \
1022 .get = stac92xx_io_switch_get, \
1023 .put = stac92xx_io_switch_put, \
1024 .private_value = xpval, \
1029 STAC_CTL_WIDGET_VOL,
1030 STAC_CTL_WIDGET_MUTE,
1031 STAC_CTL_WIDGET_IO_SWITCH,
1034 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1035 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1036 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1037 STAC_CODEC_IO_SWITCH(NULL, 0),
1040 /* add dynamic controls */
1041 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1043 struct snd_kcontrol_new *knew;
1045 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1046 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1048 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1051 if (spec->kctl_alloc) {
1052 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1053 kfree(spec->kctl_alloc);
1055 spec->kctl_alloc = knew;
1056 spec->num_kctl_alloc = num;
1059 knew = &spec->kctl_alloc[spec->num_kctl_used];
1060 *knew = stac92xx_control_templates[type];
1061 knew->name = kstrdup(name, GFP_KERNEL);
1064 knew->private_value = val;
1065 spec->num_kctl_used++;
1069 /* flag inputs as additional dynamic lineouts */
1070 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1072 struct sigmatel_spec *spec = codec->spec;
1073 unsigned int wcaps, wtype;
1074 int i, num_dacs = 0;
1076 /* use the wcaps cache to count all DACs available for line-outs */
1077 for (i = 0; i < codec->num_nodes; i++) {
1078 wcaps = codec->wcaps[i];
1079 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1080 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1084 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1086 switch (cfg->line_outs) {
1088 /* add line-in as side */
1089 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1090 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1091 spec->line_switch = 1;
1096 /* add line-in as clfe and mic as side */
1097 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1098 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1099 spec->line_switch = 1;
1102 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1103 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1104 spec->mic_switch = 1;
1109 /* add line-in as surr and mic as clfe */
1110 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1111 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1112 spec->line_switch = 1;
1115 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1116 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1117 spec->mic_switch = 1;
1127 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1131 for (i = 0; i < spec->multiout.num_dacs; i++) {
1132 if (spec->multiout.dac_nids[i] == nid)
1140 * Fill in the dac_nids table from the parsed pin configuration
1141 * This function only works when every pin in line_out_pins[]
1142 * contains atleast one DAC in its connection list. Some 92xx
1143 * codecs are not connected directly to a DAC, such as the 9200
1144 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1146 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1147 const struct auto_pin_cfg *cfg)
1149 struct sigmatel_spec *spec = codec->spec;
1150 int i, j, conn_len = 0;
1151 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1152 unsigned int wcaps, wtype;
1154 for (i = 0; i < cfg->line_outs; i++) {
1155 nid = cfg->line_out_pins[i];
1156 conn_len = snd_hda_get_connections(codec, nid, conn,
1157 HDA_MAX_CONNECTIONS);
1158 for (j = 0; j < conn_len; j++) {
1159 wcaps = snd_hda_param_read(codec, conn[j],
1160 AC_PAR_AUDIO_WIDGET_CAP);
1161 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1163 if (wtype != AC_WID_AUD_OUT ||
1164 (wcaps & AC_WCAP_DIGITAL))
1166 /* conn[j] is a DAC routed to this line-out */
1167 if (!is_in_dac_nids(spec, conn[j]))
1171 if (j == conn_len) {
1172 /* error out, no available DAC found */
1174 "%s: No available DAC for pin 0x%x\n",
1179 spec->multiout.dac_nids[i] = conn[j];
1180 spec->multiout.num_dacs++;
1182 /* select this DAC in the pin's input mux */
1183 snd_hda_codec_write(codec, nid, 0,
1184 AC_VERB_SET_CONNECT_SEL, j);
1189 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1190 spec->multiout.num_dacs,
1191 spec->multiout.dac_nids[0],
1192 spec->multiout.dac_nids[1],
1193 spec->multiout.dac_nids[2],
1194 spec->multiout.dac_nids[3],
1195 spec->multiout.dac_nids[4]);
1199 /* create volume control/switch for the given prefx type */
1200 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1205 sprintf(name, "%s Playback Volume", pfx);
1206 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1207 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1210 sprintf(name, "%s Playback Switch", pfx);
1211 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1212 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1218 /* add playback controls from the parsed DAC table */
1219 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1220 const struct auto_pin_cfg *cfg)
1222 static const char *chname[4] = {
1223 "Front", "Surround", NULL /*CLFE*/, "Side"
1228 for (i = 0; i < cfg->line_outs; i++) {
1229 if (!spec->multiout.dac_nids[i])
1232 nid = spec->multiout.dac_nids[i];
1236 err = create_controls(spec, "Center", nid, 1);
1239 err = create_controls(spec, "LFE", nid, 2);
1243 err = create_controls(spec, chname[i], nid, 3);
1249 if (spec->line_switch)
1250 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1253 if (spec->mic_switch)
1254 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1260 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1262 if (is_in_dac_nids(spec, nid))
1264 if (spec->multiout.hp_nid == nid)
1269 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1271 if (!spec->multiout.hp_nid)
1272 spec->multiout.hp_nid = nid;
1273 else if (spec->multiout.num_dacs > 4) {
1274 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1277 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1278 spec->multiout.num_dacs++;
1283 /* add playback controls for Speaker and HP outputs */
1284 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1285 struct auto_pin_cfg *cfg)
1287 struct sigmatel_spec *spec = codec->spec;
1289 int i, old_num_dacs, err;
1291 old_num_dacs = spec->multiout.num_dacs;
1292 for (i = 0; i < cfg->hp_outs; i++) {
1293 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1294 if (wid_caps & AC_WCAP_UNSOL_CAP)
1295 spec->hp_detect = 1;
1296 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1297 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1298 if (check_in_dac_nids(spec, nid))
1302 add_spec_dacs(spec, nid);
1304 for (i = 0; i < cfg->speaker_outs; i++) {
1305 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1306 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1307 if (check_in_dac_nids(spec, nid))
1311 add_spec_dacs(spec, nid);
1314 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1315 static const char *pfxs[] = {
1316 "Speaker", "External Speaker", "Speaker2",
1318 err = create_controls(spec, pfxs[i - old_num_dacs],
1319 spec->multiout.dac_nids[i], 3);
1323 if (spec->multiout.hp_nid) {
1325 if (old_num_dacs == spec->multiout.num_dacs)
1329 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1337 /* labels for dmic mux inputs */
1338 static const char *stac92xx_dmic_labels[5] = {
1339 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1340 "Digital Mic 3", "Digital Mic 4"
1343 /* create playback/capture controls for input pins on dmic capable codecs */
1344 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1345 const struct auto_pin_cfg *cfg)
1347 struct sigmatel_spec *spec = codec->spec;
1348 struct hda_input_mux *dimux = &spec->private_dimux;
1349 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1352 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1353 dimux->items[dimux->num_items].index = 0;
1356 for (i = 0; i < spec->num_dmics; i++) {
1359 unsigned int def_conf;
1361 def_conf = snd_hda_codec_read(codec,
1364 AC_VERB_GET_CONFIG_DEFAULT,
1366 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1369 num_cons = snd_hda_get_connections(codec,
1372 HDA_MAX_NUM_INPUTS);
1373 for (j = 0; j < num_cons; j++)
1374 if (con_lst[j] == spec->dmic_nids[i]) {
1380 dimux->items[dimux->num_items].label =
1381 stac92xx_dmic_labels[dimux->num_items];
1382 dimux->items[dimux->num_items].index = index;
1389 /* create playback/capture controls for input pins */
1390 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1392 struct sigmatel_spec *spec = codec->spec;
1393 struct hda_input_mux *imux = &spec->private_imux;
1394 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1397 for (i = 0; i < AUTO_PIN_LAST; i++) {
1400 if (!cfg->input_pins[i])
1403 for (j = 0; j < spec->num_muxes; j++) {
1405 num_cons = snd_hda_get_connections(codec,
1408 HDA_MAX_NUM_INPUTS);
1409 for (k = 0; k < num_cons; k++)
1410 if (con_lst[k] == cfg->input_pins[i]) {
1417 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1418 imux->items[imux->num_items].index = index;
1422 if (imux->num_items) {
1424 * Set the current input for the muxes.
1425 * The STAC9221 has two input muxes with identical source
1426 * NID lists. Hopefully this won't get confused.
1428 for (i = 0; i < spec->num_muxes; i++) {
1429 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1430 AC_VERB_SET_CONNECT_SEL,
1431 imux->items[0].index);
1438 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1440 struct sigmatel_spec *spec = codec->spec;
1443 for (i = 0; i < spec->autocfg.line_outs; i++) {
1444 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1445 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1449 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1451 struct sigmatel_spec *spec = codec->spec;
1454 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1456 pin = spec->autocfg.hp_pins[i];
1457 if (pin) /* connect to front */
1458 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1460 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1462 pin = spec->autocfg.speaker_pins[i];
1463 if (pin) /* connect to front */
1464 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1468 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1470 struct sigmatel_spec *spec = codec->spec;
1473 if ((err = snd_hda_parse_pin_def_config(codec,
1475 spec->dmic_nids)) < 0)
1477 if (! spec->autocfg.line_outs)
1478 return 0; /* can't find valid pin config */
1480 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1482 if (spec->multiout.num_dacs == 0)
1483 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1486 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1487 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1488 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1491 if (spec->num_dmics > 0)
1492 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1493 &spec->autocfg)) < 0)
1496 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1497 if (spec->multiout.max_channels > 2)
1498 spec->surr_switch = 1;
1500 if (spec->autocfg.dig_out_pin)
1501 spec->multiout.dig_out_nid = dig_out;
1502 if (spec->autocfg.dig_in_pin)
1503 spec->dig_in_nid = dig_in;
1505 if (spec->kctl_alloc)
1506 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1508 spec->input_mux = &spec->private_imux;
1509 spec->dinput_mux = &spec->private_dimux;
1514 /* add playback controls for HP output */
1515 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1516 struct auto_pin_cfg *cfg)
1518 struct sigmatel_spec *spec = codec->spec;
1519 hda_nid_t pin = cfg->hp_pins[0];
1520 unsigned int wid_caps;
1525 wid_caps = get_wcaps(codec, pin);
1526 if (wid_caps & AC_WCAP_UNSOL_CAP)
1527 spec->hp_detect = 1;
1532 /* add playback controls for LFE output */
1533 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1534 struct auto_pin_cfg *cfg)
1536 struct sigmatel_spec *spec = codec->spec;
1538 hda_nid_t lfe_pin = 0x0;
1542 * search speaker outs and line outs for a mono speaker pin
1543 * with an amp. If one is found, add LFE controls
1546 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1547 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1548 unsigned long wcaps = get_wcaps(codec, pin);
1549 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1550 if (wcaps == AC_WCAP_OUT_AMP)
1551 /* found a mono speaker with an amp, must be lfe */
1555 /* if speaker_outs is 0, then speakers may be in line_outs */
1556 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1557 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1558 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1560 cfg = snd_hda_codec_read(codec, pin, 0,
1561 AC_VERB_GET_CONFIG_DEFAULT,
1563 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
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,
1575 err = create_controls(spec, "LFE", lfe_pin, 1);
1583 static int stac9200_parse_auto_config(struct hda_codec *codec)
1585 struct sigmatel_spec *spec = codec->spec;
1588 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1591 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1594 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1597 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1600 if (spec->autocfg.dig_out_pin)
1601 spec->multiout.dig_out_nid = 0x05;
1602 if (spec->autocfg.dig_in_pin)
1603 spec->dig_in_nid = 0x04;
1605 if (spec->kctl_alloc)
1606 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1608 spec->input_mux = &spec->private_imux;
1609 spec->dinput_mux = &spec->private_dimux;
1615 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1616 * funky external mute control using GPIO pins.
1619 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1621 unsigned int gpiostate, gpiomask, gpiodir;
1623 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1624 AC_VERB_GET_GPIO_DATA, 0);
1627 gpiostate |= (1 << pin);
1629 gpiostate &= ~(1 << pin);
1631 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1632 AC_VERB_GET_GPIO_MASK, 0);
1633 gpiomask |= (1 << pin);
1635 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1636 AC_VERB_GET_GPIO_DIRECTION, 0);
1637 gpiodir |= (1 << pin);
1639 /* AppleHDA seems to do this -- WTF is this verb?? */
1640 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1642 snd_hda_codec_write(codec, codec->afg, 0,
1643 AC_VERB_SET_GPIO_MASK, gpiomask);
1644 snd_hda_codec_write(codec, codec->afg, 0,
1645 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1649 snd_hda_codec_write(codec, codec->afg, 0,
1650 AC_VERB_SET_GPIO_DATA, gpiostate);
1653 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1656 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1657 snd_hda_codec_write(codec, nid, 0,
1658 AC_VERB_SET_UNSOLICITED_ENABLE,
1659 (AC_USRSP_EN | event));
1662 static int stac92xx_init(struct hda_codec *codec)
1664 struct sigmatel_spec *spec = codec->spec;
1665 struct auto_pin_cfg *cfg = &spec->autocfg;
1668 snd_hda_sequence_write(codec, spec->init);
1671 if (spec->hp_detect) {
1672 /* Enable unsolicited responses on the HP widget */
1673 for (i = 0; i < cfg->hp_outs; i++)
1674 enable_pin_detect(codec, cfg->hp_pins[i],
1676 /* force to enable the first line-out; the others are set up
1679 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1681 stac92xx_auto_init_hp_out(codec);
1682 /* fake event to set up pins */
1683 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1685 stac92xx_auto_init_multi_out(codec);
1686 stac92xx_auto_init_hp_out(codec);
1688 for (i = 0; i < AUTO_PIN_LAST; i++) {
1689 hda_nid_t nid = cfg->input_pins[i];
1691 unsigned int pinctl = AC_PINCTL_IN_EN;
1692 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1693 pinctl |= stac92xx_get_vref(codec, nid);
1694 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1697 if (spec->num_dmics > 0)
1698 for (i = 0; i < spec->num_dmics; i++)
1699 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1702 if (cfg->dig_out_pin)
1703 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1705 if (cfg->dig_in_pin)
1706 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1709 if (spec->gpio_mute) {
1710 stac922x_gpio_mute(codec, 0, 0);
1711 stac922x_gpio_mute(codec, 1, 0);
1717 static void stac92xx_free(struct hda_codec *codec)
1719 struct sigmatel_spec *spec = codec->spec;
1725 if (spec->kctl_alloc) {
1726 for (i = 0; i < spec->num_kctl_used; i++)
1727 kfree(spec->kctl_alloc[i].name);
1728 kfree(spec->kctl_alloc);
1731 if (spec->bios_pin_configs)
1732 kfree(spec->bios_pin_configs);
1737 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1740 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1741 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1743 /* if setting pin direction bits, clear the current
1744 direction bits first */
1745 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1746 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1748 snd_hda_codec_write(codec, nid, 0,
1749 AC_VERB_SET_PIN_WIDGET_CONTROL,
1753 static void stac92xx_reset_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);
1758 snd_hda_codec_write(codec, nid, 0,
1759 AC_VERB_SET_PIN_WIDGET_CONTROL,
1763 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1767 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1773 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1775 struct sigmatel_spec *spec = codec->spec;
1776 struct auto_pin_cfg *cfg = &spec->autocfg;
1780 for (i = 0; i < cfg->hp_outs; i++) {
1781 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1787 /* disable lineouts, enable hp */
1788 for (i = 0; i < cfg->line_outs; i++)
1789 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1791 for (i = 0; i < cfg->speaker_outs; i++)
1792 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1795 /* enable lineouts, disable hp */
1796 for (i = 0; i < cfg->line_outs; i++)
1797 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1799 for (i = 0; i < cfg->speaker_outs; i++)
1800 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1805 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1807 switch (res >> 26) {
1809 stac92xx_hp_detect(codec, res);
1815 static int stac92xx_resume(struct hda_codec *codec)
1817 struct sigmatel_spec *spec = codec->spec;
1820 stac92xx_init(codec);
1821 stac92xx_set_config_regs(codec);
1822 snd_hda_resume_ctls(codec, spec->mixer);
1823 for (i = 0; i < spec->num_mixers; i++)
1824 snd_hda_resume_ctls(codec, spec->mixers[i]);
1825 if (spec->multiout.dig_out_nid)
1826 snd_hda_resume_spdif_out(codec);
1827 if (spec->dig_in_nid)
1828 snd_hda_resume_spdif_in(codec);
1834 static struct hda_codec_ops stac92xx_patch_ops = {
1835 .build_controls = stac92xx_build_controls,
1836 .build_pcms = stac92xx_build_pcms,
1837 .init = stac92xx_init,
1838 .free = stac92xx_free,
1839 .unsol_event = stac92xx_unsol_event,
1841 .resume = stac92xx_resume,
1845 static int patch_stac9200(struct hda_codec *codec)
1847 struct sigmatel_spec *spec;
1850 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1856 spec->pin_nids = stac9200_pin_nids;
1857 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1860 if (spec->board_config < 0) {
1861 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1862 err = stac92xx_save_bios_config_regs(codec);
1864 stac92xx_free(codec);
1867 spec->pin_configs = spec->bios_pin_configs;
1869 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1870 stac92xx_set_config_regs(codec);
1873 spec->multiout.max_channels = 2;
1874 spec->multiout.num_dacs = 1;
1875 spec->multiout.dac_nids = stac9200_dac_nids;
1876 spec->adc_nids = stac9200_adc_nids;
1877 spec->mux_nids = stac9200_mux_nids;
1878 spec->num_muxes = 1;
1879 spec->num_dmics = 0;
1881 spec->init = stac9200_core_init;
1882 spec->mixer = stac9200_mixer;
1884 err = stac9200_parse_auto_config(codec);
1886 stac92xx_free(codec);
1890 codec->patch_ops = stac92xx_patch_ops;
1895 static int patch_stac925x(struct hda_codec *codec)
1897 struct sigmatel_spec *spec;
1900 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1906 spec->pin_nids = stac925x_pin_nids;
1907 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1911 if (spec->board_config < 0) {
1912 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1913 err = stac92xx_save_bios_config_regs(codec);
1915 stac92xx_free(codec);
1918 spec->pin_configs = spec->bios_pin_configs;
1919 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1920 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1921 stac92xx_set_config_regs(codec);
1924 spec->multiout.max_channels = 2;
1925 spec->multiout.num_dacs = 1;
1926 spec->multiout.dac_nids = stac925x_dac_nids;
1927 spec->adc_nids = stac925x_adc_nids;
1928 spec->mux_nids = stac925x_mux_nids;
1929 spec->num_muxes = 1;
1930 spec->num_dmics = 0;
1932 spec->init = stac925x_core_init;
1933 spec->mixer = stac925x_mixer;
1935 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1937 if (spec->board_config < 0) {
1938 printk(KERN_WARNING "hda_codec: No auto-config is "
1939 "available, default to model=ref\n");
1940 spec->board_config = STAC_925x_REF;
1946 stac92xx_free(codec);
1950 codec->patch_ops = stac92xx_patch_ops;
1955 static int patch_stac922x(struct hda_codec *codec)
1957 struct sigmatel_spec *spec;
1960 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1965 spec->num_pins = 10;
1966 spec->pin_nids = stac922x_pin_nids;
1967 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1970 if (spec->board_config == STAC_MACMINI) {
1971 spec->gpio_mute = 1;
1972 /* Intel Macs have all same PCI SSID, so we need to check
1973 * codec SSID to distinguish the exact models
1975 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
1976 switch (codec->subsystem_id) {
1977 case 0x106b0a00: /* MacBook First generatoin */
1978 spec->board_config = STAC_MACBOOK;
1980 case 0x106b0200: /* MacBook Pro first generation */
1981 spec->board_config = STAC_MACBOOK_PRO_V1;
1983 case 0x106b1e00: /* MacBook Pro second generation */
1984 spec->board_config = STAC_MACBOOK_PRO_V2;
1986 case 0x106b0700: /* Intel-based iMac */
1987 spec->board_config = STAC_IMAC_INTEL;
1993 if (spec->board_config < 0) {
1994 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1995 "using BIOS defaults\n");
1996 err = stac92xx_save_bios_config_regs(codec);
1998 stac92xx_free(codec);
2001 spec->pin_configs = spec->bios_pin_configs;
2002 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2003 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2004 stac92xx_set_config_regs(codec);
2007 spec->adc_nids = stac922x_adc_nids;
2008 spec->mux_nids = stac922x_mux_nids;
2009 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2010 spec->num_dmics = 0;
2012 spec->init = stac922x_core_init;
2013 spec->mixer = stac922x_mixer;
2015 spec->multiout.dac_nids = spec->dac_nids;
2017 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2019 if (spec->board_config < 0) {
2020 printk(KERN_WARNING "hda_codec: No auto-config is "
2021 "available, default to model=ref\n");
2022 spec->board_config = STAC_D945_REF;
2028 stac92xx_free(codec);
2032 codec->patch_ops = stac92xx_patch_ops;
2037 static int patch_stac927x(struct hda_codec *codec)
2039 struct sigmatel_spec *spec;
2042 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2047 spec->num_pins = 14;
2048 spec->pin_nids = stac927x_pin_nids;
2049 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2053 if (spec->board_config < 0) {
2054 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2055 err = stac92xx_save_bios_config_regs(codec);
2057 stac92xx_free(codec);
2060 spec->pin_configs = spec->bios_pin_configs;
2061 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2062 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2063 stac92xx_set_config_regs(codec);
2066 switch (spec->board_config) {
2068 spec->adc_nids = stac927x_adc_nids;
2069 spec->mux_nids = stac927x_mux_nids;
2070 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2071 spec->num_dmics = 0;
2072 spec->init = d965_core_init;
2073 spec->mixer = stac9227_mixer;
2076 spec->adc_nids = stac927x_adc_nids;
2077 spec->mux_nids = stac927x_mux_nids;
2078 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2079 spec->num_dmics = 0;
2080 spec->init = d965_core_init;
2081 spec->mixer = stac9227_mixer;
2084 spec->adc_nids = stac927x_adc_nids;
2085 spec->mux_nids = stac927x_mux_nids;
2086 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2087 spec->num_dmics = 0;
2088 spec->init = stac927x_core_init;
2089 spec->mixer = stac927x_mixer;
2092 spec->multiout.dac_nids = spec->dac_nids;
2094 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2096 if (spec->board_config < 0) {
2097 printk(KERN_WARNING "hda_codec: No auto-config is "
2098 "available, default to model=ref\n");
2099 spec->board_config = STAC_D965_REF;
2105 stac92xx_free(codec);
2109 codec->patch_ops = stac92xx_patch_ops;
2114 static int patch_stac9205(struct hda_codec *codec)
2116 struct sigmatel_spec *spec;
2119 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2124 spec->num_pins = 14;
2125 spec->pin_nids = stac9205_pin_nids;
2126 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2130 if (spec->board_config < 0) {
2131 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2132 err = stac92xx_save_bios_config_regs(codec);
2134 stac92xx_free(codec);
2137 spec->pin_configs = spec->bios_pin_configs;
2139 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2140 stac92xx_set_config_regs(codec);
2143 spec->adc_nids = stac9205_adc_nids;
2144 spec->mux_nids = stac9205_mux_nids;
2145 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2146 spec->dmic_nids = stac9205_dmic_nids;
2147 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2148 spec->dmux_nid = 0x1d;
2150 spec->init = stac9205_core_init;
2151 spec->mixer = stac9205_mixer;
2153 spec->multiout.dac_nids = spec->dac_nids;
2155 /* Configure GPIO0 as EAPD output */
2156 snd_hda_codec_write(codec, codec->afg, 0,
2157 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2158 /* Configure GPIO0 as CMOS */
2159 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2160 /* Assert GPIO0 high */
2161 snd_hda_codec_write(codec, codec->afg, 0,
2162 AC_VERB_SET_GPIO_DATA, 0x00000001);
2164 snd_hda_codec_write(codec, codec->afg, 0,
2165 AC_VERB_SET_GPIO_MASK, 0x00000001);
2167 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2169 if (spec->board_config < 0) {
2170 printk(KERN_WARNING "hda_codec: No auto-config is "
2171 "available, default to model=ref\n");
2172 spec->board_config = STAC_9205_REF;
2178 stac92xx_free(codec);
2182 codec->patch_ops = stac92xx_patch_ops;
2191 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2192 static hda_nid_t vaio_dacs[] = { 0x2 };
2193 #define VAIO_HP_DAC 0x5
2194 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2195 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2197 static struct hda_input_mux vaio_mux = {
2200 /* { "HP", 0x0 }, */
2207 static struct hda_verb vaio_init[] = {
2208 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2209 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2210 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2211 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2212 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2213 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2214 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2215 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2216 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2217 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2218 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2222 static struct hda_verb vaio_ar_init[] = {
2223 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2224 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2225 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2226 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2227 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2228 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2229 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2230 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2231 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2232 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2233 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2234 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2235 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2239 /* bind volumes of both NID 0x02 and 0x05 */
2240 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2241 struct snd_ctl_elem_value *ucontrol)
2243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2244 long *valp = ucontrol->value.integer.value;
2247 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2248 0x7f, valp[0] & 0x7f);
2249 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2250 0x7f, valp[1] & 0x7f);
2251 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2252 0x7f, valp[0] & 0x7f);
2253 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2254 0x7f, valp[1] & 0x7f);
2258 /* bind volumes of both NID 0x02 and 0x05 */
2259 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2260 struct snd_ctl_elem_value *ucontrol)
2262 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2263 long *valp = ucontrol->value.integer.value;
2266 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2267 0x80, (valp[0] ? 0 : 0x80));
2268 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2269 0x80, (valp[1] ? 0 : 0x80));
2270 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2271 0x80, (valp[0] ? 0 : 0x80));
2272 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2273 0x80, (valp[1] ? 0 : 0x80));
2277 static struct snd_kcontrol_new vaio_mixer[] = {
2279 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2280 .name = "Master Playback Volume",
2281 .info = snd_hda_mixer_amp_volume_info,
2282 .get = snd_hda_mixer_amp_volume_get,
2283 .put = vaio_master_vol_put,
2284 .tlv = { .c = snd_hda_mixer_amp_tlv },
2285 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2289 .name = "Master Playback Switch",
2290 .info = snd_hda_mixer_amp_switch_info,
2291 .get = snd_hda_mixer_amp_switch_get,
2292 .put = vaio_master_sw_put,
2293 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2295 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2296 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2297 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2300 .name = "Capture Source",
2302 .info = stac92xx_mux_enum_info,
2303 .get = stac92xx_mux_enum_get,
2304 .put = stac92xx_mux_enum_put,
2309 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2312 .name = "Master Playback Volume",
2313 .info = snd_hda_mixer_amp_volume_info,
2314 .get = snd_hda_mixer_amp_volume_get,
2315 .put = vaio_master_vol_put,
2316 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2319 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2320 .name = "Master Playback Switch",
2321 .info = snd_hda_mixer_amp_switch_info,
2322 .get = snd_hda_mixer_amp_switch_get,
2323 .put = vaio_master_sw_put,
2324 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2326 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2327 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2328 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2329 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2330 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2332 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2333 .name = "Capture Source",
2335 .info = stac92xx_mux_enum_info,
2336 .get = stac92xx_mux_enum_get,
2337 .put = stac92xx_mux_enum_put,
2342 static struct hda_codec_ops stac9872_patch_ops = {
2343 .build_controls = stac92xx_build_controls,
2344 .build_pcms = stac92xx_build_pcms,
2345 .init = stac92xx_init,
2346 .free = stac92xx_free,
2348 .resume = stac92xx_resume,
2352 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2354 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2356 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2358 /* AR Series. id=0x83847664 and subsys=104D1300 */
2363 static const char *stac9872_models[STAC_9872_MODELS] = {
2364 [CXD9872RD_VAIO] = "vaio",
2365 [CXD9872AKD_VAIO] = "vaio-ar",
2368 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2369 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2370 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2371 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2372 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2376 static int patch_stac9872(struct hda_codec *codec)
2378 struct sigmatel_spec *spec;
2381 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2384 if (board_config < 0)
2385 /* unknown config, let generic-parser do its job... */
2386 return snd_hda_parse_generic_codec(codec);
2388 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2393 switch (board_config) {
2394 case CXD9872RD_VAIO:
2395 case STAC9872AK_VAIO:
2396 case STAC9872K_VAIO:
2397 spec->mixer = vaio_mixer;
2398 spec->init = vaio_init;
2399 spec->multiout.max_channels = 2;
2400 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2401 spec->multiout.dac_nids = vaio_dacs;
2402 spec->multiout.hp_nid = VAIO_HP_DAC;
2403 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2404 spec->adc_nids = vaio_adcs;
2405 spec->input_mux = &vaio_mux;
2406 spec->mux_nids = vaio_mux_nids;
2409 case CXD9872AKD_VAIO:
2410 spec->mixer = vaio_ar_mixer;
2411 spec->init = vaio_ar_init;
2412 spec->multiout.max_channels = 2;
2413 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2414 spec->multiout.dac_nids = vaio_dacs;
2415 spec->multiout.hp_nid = VAIO_HP_DAC;
2416 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2417 spec->adc_nids = vaio_adcs;
2418 spec->input_mux = &vaio_mux;
2419 spec->mux_nids = vaio_mux_nids;
2423 codec->patch_ops = stac9872_patch_ops;
2431 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2432 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2433 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2434 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2435 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2436 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2437 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2438 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2439 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2440 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2441 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2442 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2443 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2444 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2445 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2446 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2447 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2448 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2449 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2450 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2451 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2452 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2453 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2454 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2455 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2456 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2457 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2458 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2459 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2460 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2461 /* The following does not take into account .id=0x83847661 when subsys =
2462 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2463 * currently not fully supported.
2465 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2466 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2467 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2468 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2469 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2470 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2471 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2472 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2473 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2474 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2475 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },