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;
1074 switch (cfg->line_outs) {
1076 /* add line-in as side */
1077 if (cfg->input_pins[AUTO_PIN_LINE]) {
1078 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1079 spec->line_switch = 1;
1084 /* add line-in as clfe and mic as side */
1085 if (cfg->input_pins[AUTO_PIN_LINE]) {
1086 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1087 spec->line_switch = 1;
1090 if (cfg->input_pins[AUTO_PIN_MIC]) {
1091 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1092 spec->mic_switch = 1;
1097 /* add line-in as surr and mic as clfe */
1098 if (cfg->input_pins[AUTO_PIN_LINE]) {
1099 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1100 spec->line_switch = 1;
1103 if (cfg->input_pins[AUTO_PIN_MIC]) {
1104 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1105 spec->mic_switch = 1;
1115 * XXX The line_out pin widget connection list may not be set to the
1116 * desired DAC nid. This is the case on 927x where ports A and B can
1117 * be routed to several DACs.
1119 * This requires an analysis of the line-out/hp pin configuration
1120 * to provide a best fit for pin/DAC configurations that are routable.
1121 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
1122 * A and B is not supported.
1124 /* fill in the dac_nids table from the parsed pin configuration */
1125 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1126 const struct auto_pin_cfg *cfg)
1128 struct sigmatel_spec *spec = codec->spec;
1132 /* check the pins hardwired to audio widget */
1133 for (i = 0; i < cfg->line_outs; i++) {
1134 nid = cfg->line_out_pins[i];
1135 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
1136 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1139 spec->multiout.num_dacs = cfg->line_outs;
1144 /* create volume control/switch for the given prefx type */
1145 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1150 sprintf(name, "%s Playback Volume", pfx);
1151 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1152 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1155 sprintf(name, "%s Playback Switch", pfx);
1156 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1157 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1163 /* add playback controls from the parsed DAC table */
1164 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1165 const struct auto_pin_cfg *cfg)
1167 static const char *chname[4] = {
1168 "Front", "Surround", NULL /*CLFE*/, "Side"
1173 for (i = 0; i < cfg->line_outs; i++) {
1174 if (!spec->multiout.dac_nids[i])
1177 nid = spec->multiout.dac_nids[i];
1181 err = create_controls(spec, "Center", nid, 1);
1184 err = create_controls(spec, "LFE", nid, 2);
1188 err = create_controls(spec, chname[i], nid, 3);
1194 if (spec->line_switch)
1195 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1198 if (spec->mic_switch)
1199 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1205 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1209 for (i = 0; i < spec->multiout.num_dacs; i++) {
1210 if (spec->multiout.dac_nids[i] == nid)
1213 if (spec->multiout.hp_nid == nid)
1218 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1220 if (!spec->multiout.hp_nid)
1221 spec->multiout.hp_nid = nid;
1222 else if (spec->multiout.num_dacs > 4) {
1223 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1226 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1227 spec->multiout.num_dacs++;
1232 /* add playback controls for Speaker and HP outputs */
1233 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1234 struct auto_pin_cfg *cfg)
1236 struct sigmatel_spec *spec = codec->spec;
1238 int i, old_num_dacs, err;
1240 old_num_dacs = spec->multiout.num_dacs;
1241 for (i = 0; i < cfg->hp_outs; i++) {
1242 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1243 if (wid_caps & AC_WCAP_UNSOL_CAP)
1244 spec->hp_detect = 1;
1245 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1246 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1247 if (check_in_dac_nids(spec, nid))
1251 add_spec_dacs(spec, nid);
1253 for (i = 0; i < cfg->speaker_outs; i++) {
1254 nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
1255 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1256 if (check_in_dac_nids(spec, nid))
1258 if (check_in_dac_nids(spec, nid))
1262 add_spec_dacs(spec, nid);
1265 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1266 static const char *pfxs[] = {
1267 "Speaker", "External Speaker", "Speaker2",
1269 err = create_controls(spec, pfxs[i - old_num_dacs],
1270 spec->multiout.dac_nids[i], 3);
1274 if (spec->multiout.hp_nid) {
1276 if (old_num_dacs == spec->multiout.num_dacs)
1280 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1288 /* labels for dmic mux inputs */
1289 static const char *stac92xx_dmic_labels[5] = {
1290 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1291 "Digital Mic 3", "Digital Mic 4"
1294 /* create playback/capture controls for input pins on dmic capable codecs */
1295 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1296 const struct auto_pin_cfg *cfg)
1298 struct sigmatel_spec *spec = codec->spec;
1299 struct hda_input_mux *dimux = &spec->private_dimux;
1300 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1303 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1304 dimux->items[dimux->num_items].index = 0;
1307 for (i = 0; i < spec->num_dmics; i++) {
1310 unsigned int def_conf;
1312 def_conf = snd_hda_codec_read(codec,
1315 AC_VERB_GET_CONFIG_DEFAULT,
1317 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1320 num_cons = snd_hda_get_connections(codec,
1323 HDA_MAX_NUM_INPUTS);
1324 for (j = 0; j < num_cons; j++)
1325 if (con_lst[j] == spec->dmic_nids[i]) {
1331 dimux->items[dimux->num_items].label =
1332 stac92xx_dmic_labels[dimux->num_items];
1333 dimux->items[dimux->num_items].index = index;
1340 /* create playback/capture controls for input pins */
1341 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1343 struct sigmatel_spec *spec = codec->spec;
1344 struct hda_input_mux *imux = &spec->private_imux;
1345 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1348 for (i = 0; i < AUTO_PIN_LAST; i++) {
1351 if (!cfg->input_pins[i])
1354 for (j = 0; j < spec->num_muxes; j++) {
1356 num_cons = snd_hda_get_connections(codec,
1359 HDA_MAX_NUM_INPUTS);
1360 for (k = 0; k < num_cons; k++)
1361 if (con_lst[k] == cfg->input_pins[i]) {
1368 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1369 imux->items[imux->num_items].index = index;
1373 if (imux->num_items == 1) {
1375 * Set the current input for the muxes.
1376 * The STAC9221 has two input muxes with identical source
1377 * NID lists. Hopefully this won't get confused.
1379 for (i = 0; i < spec->num_muxes; i++) {
1380 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1381 AC_VERB_SET_CONNECT_SEL,
1382 imux->items[0].index);
1389 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1391 struct sigmatel_spec *spec = codec->spec;
1394 for (i = 0; i < spec->autocfg.line_outs; i++) {
1395 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1396 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1400 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1402 struct sigmatel_spec *spec = codec->spec;
1405 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1407 pin = spec->autocfg.hp_pins[i];
1408 if (pin) /* connect to front */
1409 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1411 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1413 pin = spec->autocfg.speaker_pins[i];
1414 if (pin) /* connect to front */
1415 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1419 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1421 struct sigmatel_spec *spec = codec->spec;
1424 if ((err = snd_hda_parse_pin_def_config(codec,
1426 spec->dmic_nids)) < 0)
1428 if (! spec->autocfg.line_outs)
1429 return 0; /* can't find valid pin config */
1431 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1433 if (spec->multiout.num_dacs == 0)
1434 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1437 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1438 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1439 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1442 if (spec->num_dmics > 0)
1443 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1444 &spec->autocfg)) < 0)
1447 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1448 if (spec->multiout.max_channels > 2)
1449 spec->surr_switch = 1;
1451 if (spec->autocfg.dig_out_pin)
1452 spec->multiout.dig_out_nid = dig_out;
1453 if (spec->autocfg.dig_in_pin)
1454 spec->dig_in_nid = dig_in;
1456 if (spec->kctl_alloc)
1457 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1459 spec->input_mux = &spec->private_imux;
1460 spec->dinput_mux = &spec->private_dimux;
1465 /* add playback controls for HP output */
1466 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1467 struct auto_pin_cfg *cfg)
1469 struct sigmatel_spec *spec = codec->spec;
1470 hda_nid_t pin = cfg->hp_pins[0];
1471 unsigned int wid_caps;
1476 wid_caps = get_wcaps(codec, pin);
1477 if (wid_caps & AC_WCAP_UNSOL_CAP)
1478 spec->hp_detect = 1;
1483 /* add playback controls for LFE output */
1484 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1485 struct auto_pin_cfg *cfg)
1487 struct sigmatel_spec *spec = codec->spec;
1489 hda_nid_t lfe_pin = 0x0;
1493 * search speaker outs and line outs for a mono speaker pin
1494 * with an amp. If one is found, add LFE controls
1497 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1498 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1499 unsigned long wcaps = get_wcaps(codec, pin);
1500 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1501 if (wcaps == AC_WCAP_OUT_AMP)
1502 /* found a mono speaker with an amp, must be lfe */
1506 /* if speaker_outs is 0, then speakers may be in line_outs */
1507 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1508 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1509 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1511 cfg = snd_hda_codec_read(codec, pin, 0,
1512 AC_VERB_GET_CONFIG_DEFAULT,
1514 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1515 unsigned long wcaps = get_wcaps(codec, pin);
1516 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1517 if (wcaps == AC_WCAP_OUT_AMP)
1518 /* found a mono speaker with an amp,
1526 err = create_controls(spec, "LFE", lfe_pin, 1);
1534 static int stac9200_parse_auto_config(struct hda_codec *codec)
1536 struct sigmatel_spec *spec = codec->spec;
1539 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1542 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1545 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1548 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1551 if (spec->autocfg.dig_out_pin)
1552 spec->multiout.dig_out_nid = 0x05;
1553 if (spec->autocfg.dig_in_pin)
1554 spec->dig_in_nid = 0x04;
1556 if (spec->kctl_alloc)
1557 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1559 spec->input_mux = &spec->private_imux;
1560 spec->dinput_mux = &spec->private_dimux;
1566 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1567 * funky external mute control using GPIO pins.
1570 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1572 unsigned int gpiostate, gpiomask, gpiodir;
1574 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1575 AC_VERB_GET_GPIO_DATA, 0);
1578 gpiostate |= (1 << pin);
1580 gpiostate &= ~(1 << pin);
1582 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1583 AC_VERB_GET_GPIO_MASK, 0);
1584 gpiomask |= (1 << pin);
1586 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1587 AC_VERB_GET_GPIO_DIRECTION, 0);
1588 gpiodir |= (1 << pin);
1590 /* AppleHDA seems to do this -- WTF is this verb?? */
1591 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1593 snd_hda_codec_write(codec, codec->afg, 0,
1594 AC_VERB_SET_GPIO_MASK, gpiomask);
1595 snd_hda_codec_write(codec, codec->afg, 0,
1596 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1600 snd_hda_codec_write(codec, codec->afg, 0,
1601 AC_VERB_SET_GPIO_DATA, gpiostate);
1604 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1607 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1608 snd_hda_codec_write(codec, nid, 0,
1609 AC_VERB_SET_UNSOLICITED_ENABLE,
1610 (AC_USRSP_EN | event));
1613 static int stac92xx_init(struct hda_codec *codec)
1615 struct sigmatel_spec *spec = codec->spec;
1616 struct auto_pin_cfg *cfg = &spec->autocfg;
1619 snd_hda_sequence_write(codec, spec->init);
1622 if (spec->hp_detect) {
1623 /* Enable unsolicited responses on the HP widget */
1624 for (i = 0; i < cfg->hp_outs; i++)
1625 enable_pin_detect(codec, cfg->hp_pins[i],
1627 /* force to enable the first line-out; the others are set up
1630 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1632 stac92xx_auto_init_hp_out(codec);
1633 /* fake event to set up pins */
1634 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1636 stac92xx_auto_init_multi_out(codec);
1637 stac92xx_auto_init_hp_out(codec);
1639 for (i = 0; i < AUTO_PIN_LAST; i++) {
1640 hda_nid_t nid = cfg->input_pins[i];
1642 unsigned int pinctl = AC_PINCTL_IN_EN;
1643 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1644 pinctl |= stac92xx_get_vref(codec, nid);
1645 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1648 if (spec->num_dmics > 0)
1649 for (i = 0; i < spec->num_dmics; i++)
1650 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1653 if (cfg->dig_out_pin)
1654 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1656 if (cfg->dig_in_pin)
1657 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1660 if (spec->gpio_mute) {
1661 stac922x_gpio_mute(codec, 0, 0);
1662 stac922x_gpio_mute(codec, 1, 0);
1668 static void stac92xx_free(struct hda_codec *codec)
1670 struct sigmatel_spec *spec = codec->spec;
1676 if (spec->kctl_alloc) {
1677 for (i = 0; i < spec->num_kctl_used; i++)
1678 kfree(spec->kctl_alloc[i].name);
1679 kfree(spec->kctl_alloc);
1682 if (spec->bios_pin_configs)
1683 kfree(spec->bios_pin_configs);
1688 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1691 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1692 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1693 if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
1695 snd_hda_codec_write(codec, nid, 0,
1696 AC_VERB_SET_PIN_WIDGET_CONTROL,
1700 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1703 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1704 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1705 snd_hda_codec_write(codec, nid, 0,
1706 AC_VERB_SET_PIN_WIDGET_CONTROL,
1710 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1714 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1720 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1722 struct sigmatel_spec *spec = codec->spec;
1723 struct auto_pin_cfg *cfg = &spec->autocfg;
1727 for (i = 0; i < cfg->hp_outs; i++) {
1728 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1734 /* disable lineouts, enable hp */
1735 for (i = 0; i < cfg->line_outs; i++)
1736 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1738 for (i = 0; i < cfg->speaker_outs; i++)
1739 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1742 /* enable lineouts, disable hp */
1743 for (i = 0; i < cfg->line_outs; i++)
1744 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1746 for (i = 0; i < cfg->speaker_outs; i++)
1747 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1752 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1754 switch (res >> 26) {
1756 stac92xx_hp_detect(codec, res);
1762 static int stac92xx_resume(struct hda_codec *codec)
1764 struct sigmatel_spec *spec = codec->spec;
1767 stac92xx_init(codec);
1768 stac92xx_set_config_regs(codec);
1769 for (i = 0; i < spec->num_mixers; i++)
1770 snd_hda_resume_ctls(codec, spec->mixers[i]);
1771 if (spec->multiout.dig_out_nid)
1772 snd_hda_resume_spdif_out(codec);
1773 if (spec->dig_in_nid)
1774 snd_hda_resume_spdif_in(codec);
1780 static struct hda_codec_ops stac92xx_patch_ops = {
1781 .build_controls = stac92xx_build_controls,
1782 .build_pcms = stac92xx_build_pcms,
1783 .init = stac92xx_init,
1784 .free = stac92xx_free,
1785 .unsol_event = stac92xx_unsol_event,
1787 .resume = stac92xx_resume,
1791 static int patch_stac9200(struct hda_codec *codec)
1793 struct sigmatel_spec *spec;
1796 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1802 spec->pin_nids = stac9200_pin_nids;
1803 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1806 if (spec->board_config < 0) {
1807 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1808 err = stac92xx_save_bios_config_regs(codec);
1810 stac92xx_free(codec);
1813 spec->pin_configs = spec->bios_pin_configs;
1815 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1816 stac92xx_set_config_regs(codec);
1819 spec->multiout.max_channels = 2;
1820 spec->multiout.num_dacs = 1;
1821 spec->multiout.dac_nids = stac9200_dac_nids;
1822 spec->adc_nids = stac9200_adc_nids;
1823 spec->mux_nids = stac9200_mux_nids;
1824 spec->num_muxes = 1;
1825 spec->num_dmics = 0;
1827 spec->init = stac9200_core_init;
1828 spec->mixer = stac9200_mixer;
1830 err = stac9200_parse_auto_config(codec);
1832 stac92xx_free(codec);
1836 codec->patch_ops = stac92xx_patch_ops;
1841 static int patch_stac925x(struct hda_codec *codec)
1843 struct sigmatel_spec *spec;
1846 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1852 spec->pin_nids = stac925x_pin_nids;
1853 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1857 if (spec->board_config < 0) {
1858 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1859 err = stac92xx_save_bios_config_regs(codec);
1861 stac92xx_free(codec);
1864 spec->pin_configs = spec->bios_pin_configs;
1865 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1866 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1867 stac92xx_set_config_regs(codec);
1870 spec->multiout.max_channels = 2;
1871 spec->multiout.num_dacs = 1;
1872 spec->multiout.dac_nids = stac925x_dac_nids;
1873 spec->adc_nids = stac925x_adc_nids;
1874 spec->mux_nids = stac925x_mux_nids;
1875 spec->num_muxes = 1;
1876 spec->num_dmics = 0;
1878 spec->init = stac925x_core_init;
1879 spec->mixer = stac925x_mixer;
1881 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1883 if (spec->board_config < 0) {
1884 printk(KERN_WARNING "hda_codec: No auto-config is "
1885 "available, default to model=ref\n");
1886 spec->board_config = STAC_925x_REF;
1892 stac92xx_free(codec);
1896 codec->patch_ops = stac92xx_patch_ops;
1901 static int patch_stac922x(struct hda_codec *codec)
1903 struct sigmatel_spec *spec;
1906 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1911 spec->num_pins = 10;
1912 spec->pin_nids = stac922x_pin_nids;
1913 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1916 if (spec->board_config == STAC_MACMINI) {
1917 spec->gpio_mute = 1;
1918 /* Intel Macs have all same PCI SSID, so we need to check
1919 * codec SSID to distinguish the exact models
1921 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
1922 switch (codec->subsystem_id) {
1923 case 0x106b0a00: /* MacBook First generatoin */
1924 spec->board_config = STAC_MACBOOK;
1926 case 0x106b0200: /* MacBook Pro first generation */
1927 spec->board_config = STAC_MACBOOK_PRO_V1;
1929 case 0x106b1e00: /* MacBook Pro second generation */
1930 spec->board_config = STAC_MACBOOK_PRO_V2;
1932 case 0x106b0700: /* Intel-based iMac */
1933 spec->board_config = STAC_IMAC_INTEL;
1939 if (spec->board_config < 0) {
1940 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1941 "using BIOS defaults\n");
1942 err = stac92xx_save_bios_config_regs(codec);
1944 stac92xx_free(codec);
1947 spec->pin_configs = spec->bios_pin_configs;
1948 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
1949 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1950 stac92xx_set_config_regs(codec);
1953 spec->adc_nids = stac922x_adc_nids;
1954 spec->mux_nids = stac922x_mux_nids;
1955 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
1956 spec->num_dmics = 0;
1958 spec->init = stac922x_core_init;
1959 spec->mixer = stac922x_mixer;
1961 spec->multiout.dac_nids = spec->dac_nids;
1963 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1965 if (spec->board_config < 0) {
1966 printk(KERN_WARNING "hda_codec: No auto-config is "
1967 "available, default to model=ref\n");
1968 spec->board_config = STAC_D945_REF;
1974 stac92xx_free(codec);
1978 codec->patch_ops = stac92xx_patch_ops;
1983 static int patch_stac927x(struct hda_codec *codec)
1985 struct sigmatel_spec *spec;
1988 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1993 spec->num_pins = 14;
1994 spec->pin_nids = stac927x_pin_nids;
1995 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
1999 if (spec->board_config < 0) {
2000 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2001 err = stac92xx_save_bios_config_regs(codec);
2003 stac92xx_free(codec);
2006 spec->pin_configs = spec->bios_pin_configs;
2007 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2008 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2009 stac92xx_set_config_regs(codec);
2012 switch (spec->board_config) {
2014 spec->adc_nids = stac927x_adc_nids;
2015 spec->mux_nids = stac927x_mux_nids;
2016 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2017 spec->num_dmics = 0;
2018 spec->init = d965_core_init;
2019 spec->mixer = stac9227_mixer;
2022 spec->adc_nids = stac927x_adc_nids;
2023 spec->mux_nids = stac927x_mux_nids;
2024 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2025 spec->num_dmics = 0;
2026 spec->init = d965_core_init;
2027 spec->mixer = stac9227_mixer;
2030 spec->adc_nids = stac927x_adc_nids;
2031 spec->mux_nids = stac927x_mux_nids;
2032 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2033 spec->num_dmics = 0;
2034 spec->init = stac927x_core_init;
2035 spec->mixer = stac927x_mixer;
2038 spec->multiout.dac_nids = spec->dac_nids;
2040 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2042 if (spec->board_config < 0) {
2043 printk(KERN_WARNING "hda_codec: No auto-config is "
2044 "available, default to model=ref\n");
2045 spec->board_config = STAC_D965_REF;
2051 stac92xx_free(codec);
2055 codec->patch_ops = stac92xx_patch_ops;
2060 static int patch_stac9205(struct hda_codec *codec)
2062 struct sigmatel_spec *spec;
2065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2070 spec->num_pins = 14;
2071 spec->pin_nids = stac9205_pin_nids;
2072 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2076 if (spec->board_config < 0) {
2077 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2078 err = stac92xx_save_bios_config_regs(codec);
2080 stac92xx_free(codec);
2083 spec->pin_configs = spec->bios_pin_configs;
2085 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2086 stac92xx_set_config_regs(codec);
2089 spec->adc_nids = stac9205_adc_nids;
2090 spec->mux_nids = stac9205_mux_nids;
2091 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2092 spec->dmic_nids = stac9205_dmic_nids;
2093 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2094 spec->dmux_nid = 0x1d;
2096 spec->init = stac9205_core_init;
2097 spec->mixer = stac9205_mixer;
2099 spec->multiout.dac_nids = spec->dac_nids;
2101 /* Configure GPIO0 as EAPD output */
2102 snd_hda_codec_write(codec, codec->afg, 0,
2103 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2104 /* Configure GPIO0 as CMOS */
2105 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2106 /* Assert GPIO0 high */
2107 snd_hda_codec_write(codec, codec->afg, 0,
2108 AC_VERB_SET_GPIO_DATA, 0x00000001);
2110 snd_hda_codec_write(codec, codec->afg, 0,
2111 AC_VERB_SET_GPIO_MASK, 0x00000001);
2113 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2115 if (spec->board_config < 0) {
2116 printk(KERN_WARNING "hda_codec: No auto-config is "
2117 "available, default to model=ref\n");
2118 spec->board_config = STAC_9205_REF;
2124 stac92xx_free(codec);
2128 codec->patch_ops = stac92xx_patch_ops;
2137 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2138 static hda_nid_t vaio_dacs[] = { 0x2 };
2139 #define VAIO_HP_DAC 0x5
2140 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2141 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2143 static struct hda_input_mux vaio_mux = {
2146 /* { "HP", 0x0 }, */
2153 static struct hda_verb vaio_init[] = {
2154 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2155 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2156 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2157 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2158 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2159 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2160 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2161 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2162 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2163 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2164 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2168 static struct hda_verb vaio_ar_init[] = {
2169 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2170 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2171 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2172 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2173 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2174 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2175 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2176 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2177 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2178 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2179 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2180 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2181 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2185 /* bind volumes of both NID 0x02 and 0x05 */
2186 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2187 struct snd_ctl_elem_value *ucontrol)
2189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2190 long *valp = ucontrol->value.integer.value;
2193 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2194 0x7f, valp[0] & 0x7f);
2195 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2196 0x7f, valp[1] & 0x7f);
2197 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2198 0x7f, valp[0] & 0x7f);
2199 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2200 0x7f, valp[1] & 0x7f);
2204 /* bind volumes of both NID 0x02 and 0x05 */
2205 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_value *ucontrol)
2208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2209 long *valp = ucontrol->value.integer.value;
2212 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2213 0x80, (valp[0] ? 0 : 0x80));
2214 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2215 0x80, (valp[1] ? 0 : 0x80));
2216 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2217 0x80, (valp[0] ? 0 : 0x80));
2218 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2219 0x80, (valp[1] ? 0 : 0x80));
2223 static struct snd_kcontrol_new vaio_mixer[] = {
2225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2226 .name = "Master Playback Volume",
2227 .info = snd_hda_mixer_amp_volume_info,
2228 .get = snd_hda_mixer_amp_volume_get,
2229 .put = vaio_master_vol_put,
2230 .tlv = { .c = snd_hda_mixer_amp_tlv },
2231 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2235 .name = "Master Playback Switch",
2236 .info = snd_hda_mixer_amp_switch_info,
2237 .get = snd_hda_mixer_amp_switch_get,
2238 .put = vaio_master_sw_put,
2239 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2241 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2242 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2243 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2245 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2246 .name = "Capture Source",
2248 .info = stac92xx_mux_enum_info,
2249 .get = stac92xx_mux_enum_get,
2250 .put = stac92xx_mux_enum_put,
2255 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2257 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2258 .name = "Master Playback Volume",
2259 .info = snd_hda_mixer_amp_volume_info,
2260 .get = snd_hda_mixer_amp_volume_get,
2261 .put = vaio_master_vol_put,
2262 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2265 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2266 .name = "Master Playback Switch",
2267 .info = snd_hda_mixer_amp_switch_info,
2268 .get = snd_hda_mixer_amp_switch_get,
2269 .put = vaio_master_sw_put,
2270 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2272 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2273 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2274 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2275 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2276 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2279 .name = "Capture Source",
2281 .info = stac92xx_mux_enum_info,
2282 .get = stac92xx_mux_enum_get,
2283 .put = stac92xx_mux_enum_put,
2288 static struct hda_codec_ops stac9872_patch_ops = {
2289 .build_controls = stac92xx_build_controls,
2290 .build_pcms = stac92xx_build_pcms,
2291 .init = stac92xx_init,
2292 .free = stac92xx_free,
2294 .resume = stac92xx_resume,
2298 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2300 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2302 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2304 /* AR Series. id=0x83847664 and subsys=104D1300 */
2309 static const char *stac9872_models[STAC_9872_MODELS] = {
2310 [CXD9872RD_VAIO] = "vaio",
2311 [CXD9872AKD_VAIO] = "vaio-ar",
2314 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2315 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2316 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2317 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2318 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2322 static int patch_stac9872(struct hda_codec *codec)
2324 struct sigmatel_spec *spec;
2327 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2330 if (board_config < 0)
2331 /* unknown config, let generic-parser do its job... */
2332 return snd_hda_parse_generic_codec(codec);
2334 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2339 switch (board_config) {
2340 case CXD9872RD_VAIO:
2341 case STAC9872AK_VAIO:
2342 case STAC9872K_VAIO:
2343 spec->mixer = vaio_mixer;
2344 spec->init = vaio_init;
2345 spec->multiout.max_channels = 2;
2346 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2347 spec->multiout.dac_nids = vaio_dacs;
2348 spec->multiout.hp_nid = VAIO_HP_DAC;
2349 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2350 spec->adc_nids = vaio_adcs;
2351 spec->input_mux = &vaio_mux;
2352 spec->mux_nids = vaio_mux_nids;
2355 case CXD9872AKD_VAIO:
2356 spec->mixer = vaio_ar_mixer;
2357 spec->init = vaio_ar_init;
2358 spec->multiout.max_channels = 2;
2359 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2360 spec->multiout.dac_nids = vaio_dacs;
2361 spec->multiout.hp_nid = VAIO_HP_DAC;
2362 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2363 spec->adc_nids = vaio_adcs;
2364 spec->input_mux = &vaio_mux;
2365 spec->mux_nids = vaio_mux_nids;
2369 codec->patch_ops = stac9872_patch_ops;
2377 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2378 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2379 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2380 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2381 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2382 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2383 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2384 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2385 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2386 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2387 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2388 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2389 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2390 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2391 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2392 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2393 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2394 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2395 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2396 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2397 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2398 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2399 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2400 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2401 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2402 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2403 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2404 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2405 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2406 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2407 /* The following does not take into account .id=0x83847661 when subsys =
2408 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2409 * currently not fully supported.
2411 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2412 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2413 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2414 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2415 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2416 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2417 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2418 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2419 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2420 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2421 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },