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),
470 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
471 "unknown Dell", STAC_REF),
475 static unsigned int ref925x_pin_configs[8] = {
476 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
477 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
480 static unsigned int stac925x_MA6_pin_configs[8] = {
481 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
482 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
485 static unsigned int stac925xM2_2_pin_configs[8] = {
486 0x40c003f3, 0x424503f2, 0x041800f4, 0x02a19020,
487 0x50a103F0, 0x90100210, 0x400003f1, 0x9033032e,
490 static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
491 [STAC_REF] = ref925x_pin_configs,
492 [STAC_M2_2] = stac925xM2_2_pin_configs,
493 [STAC_MA6] = stac925x_MA6_pin_configs,
496 static const char *stac925x_models[STAC_925x_MODELS] = {
498 [STAC_M2_2] = "m2-2",
502 static struct snd_pci_quirk stac925x_cfg_tbl[] = {
503 /* SigmaTel reference board */
504 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
505 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
506 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
507 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
508 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
512 static unsigned int ref922x_pin_configs[10] = {
513 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
514 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
515 0x40000100, 0x40000100,
518 static unsigned int d945gtp3_pin_configs[10] = {
519 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
520 0x40000100, 0x40000100, 0x40000100, 0x40000100,
521 0x02a19120, 0x40000100,
524 static unsigned int d945gtp5_pin_configs[10] = {
525 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
526 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
527 0x02a19320, 0x40000100,
530 static unsigned int macbook_pro_v1_pin_configs[10] = {
531 0x0321e230, 0x03a1e020, 0x9017e110, 0x01014010,
532 0x01a19021, 0x0381e021, 0x1345e240, 0x13c5e22e,
533 0x02a19320, 0x400000fb
536 static unsigned int macbook_pro_v2_pin_configs[10] = {
537 0x0221401f, 0x90a70120, 0x01813024, 0x01014010,
538 0x400000fd, 0x01016011, 0x1345e240, 0x13c5e22e,
539 0x400000fc, 0x400000fb,
542 static unsigned int imac_intel_pin_configs[10] = {
543 0x0121e230, 0x90a70120, 0x9017e110, 0x400000fe,
544 0x400000fd, 0x0181e021, 0x1145e040, 0x400000fa,
545 0x400000fc, 0x400000fb,
548 static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
549 [STAC_D945_REF] = ref922x_pin_configs,
550 [STAC_D945GTP3] = d945gtp3_pin_configs,
551 [STAC_D945GTP5] = d945gtp5_pin_configs,
552 [STAC_MACMINI] = macbook_pro_v1_pin_configs,
553 [STAC_MACBOOK] = macbook_pro_v1_pin_configs,
554 [STAC_MACBOOK_PRO_V1] = macbook_pro_v1_pin_configs,
555 [STAC_MACBOOK_PRO_V2] = macbook_pro_v2_pin_configs,
556 [STAC_IMAC_INTEL] = imac_intel_pin_configs,
559 static const char *stac922x_models[STAC_922X_MODELS] = {
560 [STAC_D945_REF] = "ref",
561 [STAC_D945GTP5] = "5stack",
562 [STAC_D945GTP3] = "3stack",
563 [STAC_MACMINI] = "macmini",
564 [STAC_MACBOOK] = "macbook",
565 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
566 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
567 [STAC_IMAC_INTEL] = "imac-intel",
570 static struct snd_pci_quirk stac922x_cfg_tbl[] = {
571 /* SigmaTel reference board */
572 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
573 "DFI LanParty", STAC_D945_REF),
574 /* Intel 945G based systems */
575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
576 "Intel D945G", STAC_D945GTP3),
577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
578 "Intel D945G", STAC_D945GTP3),
579 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
580 "Intel D945G", STAC_D945GTP3),
581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
582 "Intel D945G", STAC_D945GTP3),
583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
584 "Intel D945G", STAC_D945GTP3),
585 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
586 "Intel D945G", STAC_D945GTP3),
587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
588 "Intel D945G", STAC_D945GTP3),
589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
590 "Intel D945G", STAC_D945GTP3),
591 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
592 "Intel D945G", STAC_D945GTP3),
593 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
594 "Intel D945G", STAC_D945GTP3),
595 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
596 "Intel D945G", STAC_D945GTP3),
597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
598 "Intel D945G", STAC_D945GTP3),
599 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
600 "Intel D945G", STAC_D945GTP3),
601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
602 "Intel D945G", STAC_D945GTP3),
603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
604 "Intel D945G", STAC_D945GTP3),
605 /* Intel D945G 5-stack systems */
606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
607 "Intel D945G", STAC_D945GTP5),
608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
609 "Intel D945G", STAC_D945GTP5),
610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
611 "Intel D945G", STAC_D945GTP5),
612 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
613 "Intel D945G", STAC_D945GTP5),
614 /* Intel 945P based systems */
615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
616 "Intel D945P", STAC_D945GTP3),
617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
618 "Intel D945P", STAC_D945GTP3),
619 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
620 "Intel D945P", STAC_D945GTP3),
621 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
622 "Intel D945P", STAC_D945GTP3),
623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
624 "Intel D945P", STAC_D945GTP3),
625 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
626 "Intel D945P", STAC_D945GTP5),
628 /* Apple Mac Mini (early 2006) */
629 SND_PCI_QUIRK(0x8384, 0x7680,
630 "Mac Mini", STAC_MACMINI),
634 static unsigned int ref927x_pin_configs[14] = {
635 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
636 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
637 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
638 0x01c42190, 0x40000100,
641 static unsigned int d965_3st_pin_configs[14] = {
642 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
643 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
644 0x40000100, 0x40000100, 0x40000100, 0x40000100,
645 0x40000100, 0x40000100
648 static unsigned int d965_5st_pin_configs[14] = {
649 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
650 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
651 0x40000100, 0x40000100, 0x40000100, 0x01442070,
652 0x40000100, 0x40000100
655 static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
656 [STAC_D965_REF] = ref927x_pin_configs,
657 [STAC_D965_3ST] = d965_3st_pin_configs,
658 [STAC_D965_5ST] = d965_5st_pin_configs,
661 static const char *stac927x_models[STAC_927X_MODELS] = {
662 [STAC_D965_REF] = "ref",
663 [STAC_D965_3ST] = "3stack",
664 [STAC_D965_5ST] = "5stack",
667 static struct snd_pci_quirk stac927x_cfg_tbl[] = {
668 /* SigmaTel reference board */
669 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
670 "DFI LanParty", STAC_D965_REF),
671 /* Intel 946 based systems */
672 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
673 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
674 /* 965 based 3 stack systems */
675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
678 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
681 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
682 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
683 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
684 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
685 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
686 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
687 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
688 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
689 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
691 /* 965 based 5 stack systems */
692 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
693 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
695 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
697 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
698 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
700 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
704 static unsigned int ref9205_pin_configs[12] = {
705 0x40000100, 0x40000100, 0x01016011, 0x01014010,
706 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
707 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
710 static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
714 static const char *stac9205_models[STAC_9205_MODELS] = {
715 [STAC_9205_REF] = "ref",
718 static struct snd_pci_quirk stac9205_cfg_tbl[] = {
719 /* SigmaTel reference board */
720 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
721 "DFI LanParty", STAC_9205_REF),
725 static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
728 struct sigmatel_spec *spec = codec->spec;
730 if (! spec->bios_pin_configs) {
731 spec->bios_pin_configs = kcalloc(spec->num_pins,
732 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
733 if (! spec->bios_pin_configs)
737 for (i = 0; i < spec->num_pins; i++) {
738 hda_nid_t nid = spec->pin_nids[i];
739 unsigned int pin_cfg;
741 pin_cfg = snd_hda_codec_read(codec, nid, 0,
742 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
743 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
745 spec->bios_pin_configs[i] = pin_cfg;
751 static void stac92xx_set_config_regs(struct hda_codec *codec)
754 struct sigmatel_spec *spec = codec->spec;
755 unsigned int pin_cfg;
757 if (! spec->pin_nids || ! spec->pin_configs)
760 for (i = 0; i < spec->num_pins; i++) {
761 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
762 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
763 spec->pin_configs[i] & 0x000000ff);
764 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
765 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
766 (spec->pin_configs[i] & 0x0000ff00) >> 8);
767 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
768 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
769 (spec->pin_configs[i] & 0x00ff0000) >> 16);
770 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
771 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
772 spec->pin_configs[i] >> 24);
773 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
774 AC_VERB_GET_CONFIG_DEFAULT,
776 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
781 * Analog playback callbacks
783 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
784 struct hda_codec *codec,
785 struct snd_pcm_substream *substream)
787 struct sigmatel_spec *spec = codec->spec;
788 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
791 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
792 struct hda_codec *codec,
793 unsigned int stream_tag,
795 struct snd_pcm_substream *substream)
797 struct sigmatel_spec *spec = codec->spec;
798 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
801 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
802 struct hda_codec *codec,
803 struct snd_pcm_substream *substream)
805 struct sigmatel_spec *spec = codec->spec;
806 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
810 * Digital playback callbacks
812 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
813 struct hda_codec *codec,
814 struct snd_pcm_substream *substream)
816 struct sigmatel_spec *spec = codec->spec;
817 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
820 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
821 struct hda_codec *codec,
822 struct snd_pcm_substream *substream)
824 struct sigmatel_spec *spec = codec->spec;
825 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
828 static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
829 struct hda_codec *codec,
830 unsigned int stream_tag,
832 struct snd_pcm_substream *substream)
834 struct sigmatel_spec *spec = codec->spec;
835 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
836 stream_tag, format, substream);
841 * Analog capture callbacks
843 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
844 struct hda_codec *codec,
845 unsigned int stream_tag,
847 struct snd_pcm_substream *substream)
849 struct sigmatel_spec *spec = codec->spec;
851 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
852 stream_tag, 0, format);
856 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
857 struct hda_codec *codec,
858 struct snd_pcm_substream *substream)
860 struct sigmatel_spec *spec = codec->spec;
862 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
866 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
870 /* NID is set in stac92xx_build_pcms */
872 .open = stac92xx_dig_playback_pcm_open,
873 .close = stac92xx_dig_playback_pcm_close,
874 .prepare = stac92xx_dig_playback_pcm_prepare
878 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
882 /* NID is set in stac92xx_build_pcms */
885 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
889 .nid = 0x02, /* NID to query formats and rates */
891 .open = stac92xx_playback_pcm_open,
892 .prepare = stac92xx_playback_pcm_prepare,
893 .cleanup = stac92xx_playback_pcm_cleanup
897 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
901 .nid = 0x06, /* NID to query formats and rates */
903 .open = stac92xx_playback_pcm_open,
904 .prepare = stac92xx_playback_pcm_prepare,
905 .cleanup = stac92xx_playback_pcm_cleanup
909 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
913 /* NID is set in stac92xx_build_pcms */
915 .prepare = stac92xx_capture_pcm_prepare,
916 .cleanup = stac92xx_capture_pcm_cleanup
920 static int stac92xx_build_pcms(struct hda_codec *codec)
922 struct sigmatel_spec *spec = codec->spec;
923 struct hda_pcm *info = spec->pcm_rec;
926 codec->pcm_info = info;
928 info->name = "STAC92xx Analog";
929 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
930 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
931 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
933 if (spec->alt_switch) {
936 info->name = "STAC92xx Analog Alt";
937 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
940 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
943 info->name = "STAC92xx Digital";
944 if (spec->multiout.dig_out_nid) {
945 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
946 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
948 if (spec->dig_in_nid) {
949 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
950 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
957 static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
959 unsigned int pincap = snd_hda_param_read(codec, nid,
961 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
962 if (pincap & AC_PINCAP_VREF_100)
963 return AC_PINCTL_VREF_100;
964 if (pincap & AC_PINCAP_VREF_80)
965 return AC_PINCTL_VREF_80;
966 if (pincap & AC_PINCAP_VREF_50)
967 return AC_PINCTL_VREF_50;
968 if (pincap & AC_PINCAP_VREF_GRD)
969 return AC_PINCTL_VREF_GRD;
973 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
976 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
979 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
981 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
983 uinfo->value.integer.min = 0;
984 uinfo->value.integer.max = 1;
988 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
990 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
991 struct sigmatel_spec *spec = codec->spec;
992 int io_idx = kcontrol-> private_value & 0xff;
994 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
998 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1000 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1001 struct sigmatel_spec *spec = codec->spec;
1002 hda_nid_t nid = kcontrol->private_value >> 8;
1003 int io_idx = kcontrol-> private_value & 0xff;
1004 unsigned short val = ucontrol->value.integer.value[0];
1006 spec->io_switch[io_idx] = val;
1009 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1011 unsigned int pinctl = AC_PINCTL_IN_EN;
1012 if (io_idx) /* set VREF for mic */
1013 pinctl |= stac92xx_get_vref(codec, nid);
1014 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1019 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
1020 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1023 .info = stac92xx_io_switch_info, \
1024 .get = stac92xx_io_switch_get, \
1025 .put = stac92xx_io_switch_put, \
1026 .private_value = xpval, \
1031 STAC_CTL_WIDGET_VOL,
1032 STAC_CTL_WIDGET_MUTE,
1033 STAC_CTL_WIDGET_IO_SWITCH,
1036 static struct snd_kcontrol_new stac92xx_control_templates[] = {
1037 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1038 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1039 STAC_CODEC_IO_SWITCH(NULL, 0),
1042 /* add dynamic controls */
1043 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1045 struct snd_kcontrol_new *knew;
1047 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1048 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1050 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1053 if (spec->kctl_alloc) {
1054 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1055 kfree(spec->kctl_alloc);
1057 spec->kctl_alloc = knew;
1058 spec->num_kctl_alloc = num;
1061 knew = &spec->kctl_alloc[spec->num_kctl_used];
1062 *knew = stac92xx_control_templates[type];
1063 knew->name = kstrdup(name, GFP_KERNEL);
1066 knew->private_value = val;
1067 spec->num_kctl_used++;
1071 /* flag inputs as additional dynamic lineouts */
1072 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1074 struct sigmatel_spec *spec = codec->spec;
1075 unsigned int wcaps, wtype;
1076 int i, num_dacs = 0;
1078 /* use the wcaps cache to count all DACs available for line-outs */
1079 for (i = 0; i < codec->num_nodes; i++) {
1080 wcaps = codec->wcaps[i];
1081 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1082 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1086 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1088 switch (cfg->line_outs) {
1090 /* add line-in as side */
1091 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
1092 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
1093 spec->line_switch = 1;
1098 /* add line-in as clfe and mic as side */
1099 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
1100 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
1101 spec->line_switch = 1;
1104 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
1105 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
1106 spec->mic_switch = 1;
1111 /* add line-in as surr and mic as clfe */
1112 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
1113 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
1114 spec->line_switch = 1;
1117 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
1118 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
1119 spec->mic_switch = 1;
1129 static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1133 for (i = 0; i < spec->multiout.num_dacs; i++) {
1134 if (spec->multiout.dac_nids[i] == nid)
1142 * Fill in the dac_nids table from the parsed pin configuration
1143 * This function only works when every pin in line_out_pins[]
1144 * contains atleast one DAC in its connection list. Some 92xx
1145 * codecs are not connected directly to a DAC, such as the 9200
1146 * and 9202/925x. For those, dac_nids[] must be hard-coded.
1148 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
1149 const struct auto_pin_cfg *cfg)
1151 struct sigmatel_spec *spec = codec->spec;
1152 int i, j, conn_len = 0;
1153 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1154 unsigned int wcaps, wtype;
1156 for (i = 0; i < cfg->line_outs; i++) {
1157 nid = cfg->line_out_pins[i];
1158 conn_len = snd_hda_get_connections(codec, nid, conn,
1159 HDA_MAX_CONNECTIONS);
1160 for (j = 0; j < conn_len; j++) {
1161 wcaps = snd_hda_param_read(codec, conn[j],
1162 AC_PAR_AUDIO_WIDGET_CAP);
1163 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1165 if (wtype != AC_WID_AUD_OUT ||
1166 (wcaps & AC_WCAP_DIGITAL))
1168 /* conn[j] is a DAC routed to this line-out */
1169 if (!is_in_dac_nids(spec, conn[j]))
1173 if (j == conn_len) {
1174 /* error out, no available DAC found */
1176 "%s: No available DAC for pin 0x%x\n",
1181 spec->multiout.dac_nids[i] = conn[j];
1182 spec->multiout.num_dacs++;
1184 /* select this DAC in the pin's input mux */
1185 snd_hda_codec_write(codec, nid, 0,
1186 AC_VERB_SET_CONNECT_SEL, j);
1191 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1192 spec->multiout.num_dacs,
1193 spec->multiout.dac_nids[0],
1194 spec->multiout.dac_nids[1],
1195 spec->multiout.dac_nids[2],
1196 spec->multiout.dac_nids[3],
1197 spec->multiout.dac_nids[4]);
1201 /* create volume control/switch for the given prefx type */
1202 static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1207 sprintf(name, "%s Playback Volume", pfx);
1208 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1209 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1212 sprintf(name, "%s Playback Switch", pfx);
1213 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1214 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1220 /* add playback controls from the parsed DAC table */
1221 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
1222 const struct auto_pin_cfg *cfg)
1224 static const char *chname[4] = {
1225 "Front", "Surround", NULL /*CLFE*/, "Side"
1230 for (i = 0; i < cfg->line_outs; i++) {
1231 if (!spec->multiout.dac_nids[i])
1234 nid = spec->multiout.dac_nids[i];
1238 err = create_controls(spec, "Center", nid, 1);
1241 err = create_controls(spec, "LFE", nid, 2);
1245 err = create_controls(spec, chname[i], nid, 3);
1251 if (spec->line_switch)
1252 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1255 if (spec->mic_switch)
1256 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1262 static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1264 if (is_in_dac_nids(spec, nid))
1266 if (spec->multiout.hp_nid == nid)
1271 static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1273 if (!spec->multiout.hp_nid)
1274 spec->multiout.hp_nid = nid;
1275 else if (spec->multiout.num_dacs > 4) {
1276 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1279 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1280 spec->multiout.num_dacs++;
1285 /* add playback controls for Speaker and HP outputs */
1286 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1287 struct auto_pin_cfg *cfg)
1289 struct sigmatel_spec *spec = codec->spec;
1291 int i, old_num_dacs, err;
1293 old_num_dacs = spec->multiout.num_dacs;
1294 for (i = 0; i < cfg->hp_outs; i++) {
1295 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1296 if (wid_caps & AC_WCAP_UNSOL_CAP)
1297 spec->hp_detect = 1;
1298 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1299 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1300 if (check_in_dac_nids(spec, nid))
1304 add_spec_dacs(spec, nid);
1306 for (i = 0; i < cfg->speaker_outs; i++) {
1307 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
1308 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1309 if (check_in_dac_nids(spec, nid))
1313 add_spec_dacs(spec, nid);
1316 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1317 static const char *pfxs[] = {
1318 "Speaker", "External Speaker", "Speaker2",
1320 err = create_controls(spec, pfxs[i - old_num_dacs],
1321 spec->multiout.dac_nids[i], 3);
1325 if (spec->multiout.hp_nid) {
1327 if (old_num_dacs == spec->multiout.num_dacs)
1331 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
1339 /* labels for dmic mux inputs */
1340 static const char *stac92xx_dmic_labels[5] = {
1341 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
1342 "Digital Mic 3", "Digital Mic 4"
1345 /* create playback/capture controls for input pins on dmic capable codecs */
1346 static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
1347 const struct auto_pin_cfg *cfg)
1349 struct sigmatel_spec *spec = codec->spec;
1350 struct hda_input_mux *dimux = &spec->private_dimux;
1351 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1354 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
1355 dimux->items[dimux->num_items].index = 0;
1358 for (i = 0; i < spec->num_dmics; i++) {
1361 unsigned int def_conf;
1363 def_conf = snd_hda_codec_read(codec,
1366 AC_VERB_GET_CONFIG_DEFAULT,
1368 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
1371 num_cons = snd_hda_get_connections(codec,
1374 HDA_MAX_NUM_INPUTS);
1375 for (j = 0; j < num_cons; j++)
1376 if (con_lst[j] == spec->dmic_nids[i]) {
1382 dimux->items[dimux->num_items].label =
1383 stac92xx_dmic_labels[dimux->num_items];
1384 dimux->items[dimux->num_items].index = index;
1391 /* create playback/capture controls for input pins */
1392 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
1394 struct sigmatel_spec *spec = codec->spec;
1395 struct hda_input_mux *imux = &spec->private_imux;
1396 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
1399 for (i = 0; i < AUTO_PIN_LAST; i++) {
1402 if (!cfg->input_pins[i])
1405 for (j = 0; j < spec->num_muxes; j++) {
1407 num_cons = snd_hda_get_connections(codec,
1410 HDA_MAX_NUM_INPUTS);
1411 for (k = 0; k < num_cons; k++)
1412 if (con_lst[k] == cfg->input_pins[i]) {
1419 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
1420 imux->items[imux->num_items].index = index;
1424 if (imux->num_items) {
1426 * Set the current input for the muxes.
1427 * The STAC9221 has two input muxes with identical source
1428 * NID lists. Hopefully this won't get confused.
1430 for (i = 0; i < spec->num_muxes; i++) {
1431 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
1432 AC_VERB_SET_CONNECT_SEL,
1433 imux->items[0].index);
1440 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
1442 struct sigmatel_spec *spec = codec->spec;
1445 for (i = 0; i < spec->autocfg.line_outs; i++) {
1446 hda_nid_t nid = spec->autocfg.line_out_pins[i];
1447 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
1451 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
1453 struct sigmatel_spec *spec = codec->spec;
1456 for (i = 0; i < spec->autocfg.hp_outs; i++) {
1458 pin = spec->autocfg.hp_pins[i];
1459 if (pin) /* connect to front */
1460 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
1462 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
1464 pin = spec->autocfg.speaker_pins[i];
1465 if (pin) /* connect to front */
1466 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
1470 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
1472 struct sigmatel_spec *spec = codec->spec;
1475 if ((err = snd_hda_parse_pin_def_config(codec,
1477 spec->dmic_nids)) < 0)
1479 if (! spec->autocfg.line_outs)
1480 return 0; /* can't find valid pin config */
1482 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
1484 if (spec->multiout.num_dacs == 0)
1485 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
1488 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
1489 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
1490 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1493 if (spec->num_dmics > 0)
1494 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
1495 &spec->autocfg)) < 0)
1498 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1499 if (spec->multiout.max_channels > 2)
1500 spec->surr_switch = 1;
1502 if (spec->autocfg.dig_out_pin)
1503 spec->multiout.dig_out_nid = dig_out;
1504 if (spec->autocfg.dig_in_pin)
1505 spec->dig_in_nid = dig_in;
1507 if (spec->kctl_alloc)
1508 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1510 spec->input_mux = &spec->private_imux;
1511 spec->dinput_mux = &spec->private_dimux;
1516 /* add playback controls for HP output */
1517 static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
1518 struct auto_pin_cfg *cfg)
1520 struct sigmatel_spec *spec = codec->spec;
1521 hda_nid_t pin = cfg->hp_pins[0];
1522 unsigned int wid_caps;
1527 wid_caps = get_wcaps(codec, pin);
1528 if (wid_caps & AC_WCAP_UNSOL_CAP)
1529 spec->hp_detect = 1;
1534 /* add playback controls for LFE output */
1535 static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
1536 struct auto_pin_cfg *cfg)
1538 struct sigmatel_spec *spec = codec->spec;
1540 hda_nid_t lfe_pin = 0x0;
1544 * search speaker outs and line outs for a mono speaker pin
1545 * with an amp. If one is found, add LFE controls
1548 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
1549 hda_nid_t pin = spec->autocfg.speaker_pins[i];
1550 unsigned long wcaps = get_wcaps(codec, pin);
1551 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1552 if (wcaps == AC_WCAP_OUT_AMP)
1553 /* found a mono speaker with an amp, must be lfe */
1557 /* if speaker_outs is 0, then speakers may be in line_outs */
1558 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
1559 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
1560 hda_nid_t pin = spec->autocfg.line_out_pins[i];
1562 cfg = snd_hda_codec_read(codec, pin, 0,
1563 AC_VERB_GET_CONFIG_DEFAULT,
1565 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
1566 unsigned long wcaps = get_wcaps(codec, pin);
1567 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
1568 if (wcaps == AC_WCAP_OUT_AMP)
1569 /* found a mono speaker with an amp,
1577 err = create_controls(spec, "LFE", lfe_pin, 1);
1585 static int stac9200_parse_auto_config(struct hda_codec *codec)
1587 struct sigmatel_spec *spec = codec->spec;
1590 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
1593 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
1596 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
1599 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
1602 if (spec->autocfg.dig_out_pin)
1603 spec->multiout.dig_out_nid = 0x05;
1604 if (spec->autocfg.dig_in_pin)
1605 spec->dig_in_nid = 0x04;
1607 if (spec->kctl_alloc)
1608 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1610 spec->input_mux = &spec->private_imux;
1611 spec->dinput_mux = &spec->private_dimux;
1617 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
1618 * funky external mute control using GPIO pins.
1621 static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
1623 unsigned int gpiostate, gpiomask, gpiodir;
1625 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
1626 AC_VERB_GET_GPIO_DATA, 0);
1629 gpiostate |= (1 << pin);
1631 gpiostate &= ~(1 << pin);
1633 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
1634 AC_VERB_GET_GPIO_MASK, 0);
1635 gpiomask |= (1 << pin);
1637 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
1638 AC_VERB_GET_GPIO_DIRECTION, 0);
1639 gpiodir |= (1 << pin);
1641 /* AppleHDA seems to do this -- WTF is this verb?? */
1642 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
1644 snd_hda_codec_write(codec, codec->afg, 0,
1645 AC_VERB_SET_GPIO_MASK, gpiomask);
1646 snd_hda_codec_write(codec, codec->afg, 0,
1647 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
1651 snd_hda_codec_write(codec, codec->afg, 0,
1652 AC_VERB_SET_GPIO_DATA, gpiostate);
1655 static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
1658 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
1659 snd_hda_codec_write(codec, nid, 0,
1660 AC_VERB_SET_UNSOLICITED_ENABLE,
1661 (AC_USRSP_EN | event));
1664 static int stac92xx_init(struct hda_codec *codec)
1666 struct sigmatel_spec *spec = codec->spec;
1667 struct auto_pin_cfg *cfg = &spec->autocfg;
1670 snd_hda_sequence_write(codec, spec->init);
1673 if (spec->hp_detect) {
1674 /* Enable unsolicited responses on the HP widget */
1675 for (i = 0; i < cfg->hp_outs; i++)
1676 enable_pin_detect(codec, cfg->hp_pins[i],
1678 /* force to enable the first line-out; the others are set up
1681 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
1683 stac92xx_auto_init_hp_out(codec);
1684 /* fake event to set up pins */
1685 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1687 stac92xx_auto_init_multi_out(codec);
1688 stac92xx_auto_init_hp_out(codec);
1690 for (i = 0; i < AUTO_PIN_LAST; i++) {
1691 hda_nid_t nid = cfg->input_pins[i];
1693 unsigned int pinctl = AC_PINCTL_IN_EN;
1694 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
1695 pinctl |= stac92xx_get_vref(codec, nid);
1696 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1699 if (spec->num_dmics > 0)
1700 for (i = 0; i < spec->num_dmics; i++)
1701 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
1704 if (cfg->dig_out_pin)
1705 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
1707 if (cfg->dig_in_pin)
1708 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
1711 if (spec->gpio_mute) {
1712 stac922x_gpio_mute(codec, 0, 0);
1713 stac922x_gpio_mute(codec, 1, 0);
1719 static void stac92xx_free(struct hda_codec *codec)
1721 struct sigmatel_spec *spec = codec->spec;
1727 if (spec->kctl_alloc) {
1728 for (i = 0; i < spec->num_kctl_used; i++)
1729 kfree(spec->kctl_alloc[i].name);
1730 kfree(spec->kctl_alloc);
1733 if (spec->bios_pin_configs)
1734 kfree(spec->bios_pin_configs);
1739 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
1742 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1743 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1745 /* if setting pin direction bits, clear the current
1746 direction bits first */
1747 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
1748 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1750 snd_hda_codec_write(codec, nid, 0,
1751 AC_VERB_SET_PIN_WIDGET_CONTROL,
1755 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
1758 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
1759 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
1760 snd_hda_codec_write(codec, nid, 0,
1761 AC_VERB_SET_PIN_WIDGET_CONTROL,
1765 static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
1769 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
1775 static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
1777 struct sigmatel_spec *spec = codec->spec;
1778 struct auto_pin_cfg *cfg = &spec->autocfg;
1782 for (i = 0; i < cfg->hp_outs; i++) {
1783 presence = get_pin_presence(codec, cfg->hp_pins[i]);
1789 /* disable lineouts, enable hp */
1790 for (i = 0; i < cfg->line_outs; i++)
1791 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
1793 for (i = 0; i < cfg->speaker_outs; i++)
1794 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
1797 /* enable lineouts, disable hp */
1798 for (i = 0; i < cfg->line_outs; i++)
1799 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
1801 for (i = 0; i < cfg->speaker_outs; i++)
1802 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
1807 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
1809 switch (res >> 26) {
1811 stac92xx_hp_detect(codec, res);
1817 static int stac92xx_resume(struct hda_codec *codec)
1819 struct sigmatel_spec *spec = codec->spec;
1822 stac92xx_init(codec);
1823 stac92xx_set_config_regs(codec);
1824 snd_hda_resume_ctls(codec, spec->mixer);
1825 for (i = 0; i < spec->num_mixers; i++)
1826 snd_hda_resume_ctls(codec, spec->mixers[i]);
1827 if (spec->multiout.dig_out_nid)
1828 snd_hda_resume_spdif_out(codec);
1829 if (spec->dig_in_nid)
1830 snd_hda_resume_spdif_in(codec);
1836 static struct hda_codec_ops stac92xx_patch_ops = {
1837 .build_controls = stac92xx_build_controls,
1838 .build_pcms = stac92xx_build_pcms,
1839 .init = stac92xx_init,
1840 .free = stac92xx_free,
1841 .unsol_event = stac92xx_unsol_event,
1843 .resume = stac92xx_resume,
1847 static int patch_stac9200(struct hda_codec *codec)
1849 struct sigmatel_spec *spec;
1852 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1858 spec->pin_nids = stac9200_pin_nids;
1859 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
1862 if (spec->board_config < 0) {
1863 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1864 err = stac92xx_save_bios_config_regs(codec);
1866 stac92xx_free(codec);
1869 spec->pin_configs = spec->bios_pin_configs;
1871 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1872 stac92xx_set_config_regs(codec);
1875 spec->multiout.max_channels = 2;
1876 spec->multiout.num_dacs = 1;
1877 spec->multiout.dac_nids = stac9200_dac_nids;
1878 spec->adc_nids = stac9200_adc_nids;
1879 spec->mux_nids = stac9200_mux_nids;
1880 spec->num_muxes = 1;
1881 spec->num_dmics = 0;
1883 spec->init = stac9200_core_init;
1884 spec->mixer = stac9200_mixer;
1886 err = stac9200_parse_auto_config(codec);
1888 stac92xx_free(codec);
1892 codec->patch_ops = stac92xx_patch_ops;
1897 static int patch_stac925x(struct hda_codec *codec)
1899 struct sigmatel_spec *spec;
1902 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1908 spec->pin_nids = stac925x_pin_nids;
1909 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
1913 if (spec->board_config < 0) {
1914 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x, using BIOS defaults\n");
1915 err = stac92xx_save_bios_config_regs(codec);
1917 stac92xx_free(codec);
1920 spec->pin_configs = spec->bios_pin_configs;
1921 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
1922 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
1923 stac92xx_set_config_regs(codec);
1926 spec->multiout.max_channels = 2;
1927 spec->multiout.num_dacs = 1;
1928 spec->multiout.dac_nids = stac925x_dac_nids;
1929 spec->adc_nids = stac925x_adc_nids;
1930 spec->mux_nids = stac925x_mux_nids;
1931 spec->num_muxes = 1;
1932 spec->num_dmics = 0;
1934 spec->init = stac925x_core_init;
1935 spec->mixer = stac925x_mixer;
1937 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
1939 if (spec->board_config < 0) {
1940 printk(KERN_WARNING "hda_codec: No auto-config is "
1941 "available, default to model=ref\n");
1942 spec->board_config = STAC_925x_REF;
1948 stac92xx_free(codec);
1952 codec->patch_ops = stac92xx_patch_ops;
1957 static int patch_stac922x(struct hda_codec *codec)
1959 struct sigmatel_spec *spec;
1962 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1967 spec->num_pins = 10;
1968 spec->pin_nids = stac922x_pin_nids;
1969 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
1972 if (spec->board_config == STAC_MACMINI) {
1973 spec->gpio_mute = 1;
1974 /* Intel Macs have all same PCI SSID, so we need to check
1975 * codec SSID to distinguish the exact models
1977 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
1978 switch (codec->subsystem_id) {
1979 case 0x106b0a00: /* MacBook First generatoin */
1980 spec->board_config = STAC_MACBOOK;
1982 case 0x106b0200: /* MacBook Pro first generation */
1983 spec->board_config = STAC_MACBOOK_PRO_V1;
1985 case 0x106b1e00: /* MacBook Pro second generation */
1986 spec->board_config = STAC_MACBOOK_PRO_V2;
1988 case 0x106b0700: /* Intel-based iMac */
1989 spec->board_config = STAC_IMAC_INTEL;
1995 if (spec->board_config < 0) {
1996 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
1997 "using BIOS defaults\n");
1998 err = stac92xx_save_bios_config_regs(codec);
2000 stac92xx_free(codec);
2003 spec->pin_configs = spec->bios_pin_configs;
2004 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
2005 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2006 stac92xx_set_config_regs(codec);
2009 spec->adc_nids = stac922x_adc_nids;
2010 spec->mux_nids = stac922x_mux_nids;
2011 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
2012 spec->num_dmics = 0;
2014 spec->init = stac922x_core_init;
2015 spec->mixer = stac922x_mixer;
2017 spec->multiout.dac_nids = spec->dac_nids;
2019 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
2021 if (spec->board_config < 0) {
2022 printk(KERN_WARNING "hda_codec: No auto-config is "
2023 "available, default to model=ref\n");
2024 spec->board_config = STAC_D945_REF;
2030 stac92xx_free(codec);
2034 codec->patch_ops = stac92xx_patch_ops;
2039 static int patch_stac927x(struct hda_codec *codec)
2041 struct sigmatel_spec *spec;
2044 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2049 spec->num_pins = 14;
2050 spec->pin_nids = stac927x_pin_nids;
2051 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2055 if (spec->board_config < 0) {
2056 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
2057 err = stac92xx_save_bios_config_regs(codec);
2059 stac92xx_free(codec);
2062 spec->pin_configs = spec->bios_pin_configs;
2063 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
2064 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2065 stac92xx_set_config_regs(codec);
2068 switch (spec->board_config) {
2070 spec->adc_nids = stac927x_adc_nids;
2071 spec->mux_nids = stac927x_mux_nids;
2072 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2073 spec->num_dmics = 0;
2074 spec->init = d965_core_init;
2075 spec->mixer = stac9227_mixer;
2078 spec->adc_nids = stac927x_adc_nids;
2079 spec->mux_nids = stac927x_mux_nids;
2080 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2081 spec->num_dmics = 0;
2082 spec->init = d965_core_init;
2083 spec->mixer = stac9227_mixer;
2086 spec->adc_nids = stac927x_adc_nids;
2087 spec->mux_nids = stac927x_mux_nids;
2088 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
2089 spec->num_dmics = 0;
2090 spec->init = stac927x_core_init;
2091 spec->mixer = stac927x_mixer;
2094 spec->multiout.dac_nids = spec->dac_nids;
2096 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
2098 if (spec->board_config < 0) {
2099 printk(KERN_WARNING "hda_codec: No auto-config is "
2100 "available, default to model=ref\n");
2101 spec->board_config = STAC_D965_REF;
2107 stac92xx_free(codec);
2111 codec->patch_ops = stac92xx_patch_ops;
2116 static int patch_stac9205(struct hda_codec *codec)
2118 struct sigmatel_spec *spec;
2121 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2126 spec->num_pins = 14;
2127 spec->pin_nids = stac9205_pin_nids;
2128 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2132 if (spec->board_config < 0) {
2133 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
2134 err = stac92xx_save_bios_config_regs(codec);
2136 stac92xx_free(codec);
2139 spec->pin_configs = spec->bios_pin_configs;
2141 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
2142 stac92xx_set_config_regs(codec);
2145 spec->adc_nids = stac9205_adc_nids;
2146 spec->mux_nids = stac9205_mux_nids;
2147 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
2148 spec->dmic_nids = stac9205_dmic_nids;
2149 spec->num_dmics = ARRAY_SIZE(stac9205_dmic_nids);
2150 spec->dmux_nid = 0x1d;
2152 spec->init = stac9205_core_init;
2153 spec->mixer = stac9205_mixer;
2155 spec->multiout.dac_nids = spec->dac_nids;
2157 /* Configure GPIO0 as EAPD output */
2158 snd_hda_codec_write(codec, codec->afg, 0,
2159 AC_VERB_SET_GPIO_DIRECTION, 0x00000001);
2160 /* Configure GPIO0 as CMOS */
2161 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0x00000000);
2162 /* Assert GPIO0 high */
2163 snd_hda_codec_write(codec, codec->afg, 0,
2164 AC_VERB_SET_GPIO_DATA, 0x00000001);
2166 snd_hda_codec_write(codec, codec->afg, 0,
2167 AC_VERB_SET_GPIO_MASK, 0x00000001);
2169 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
2171 if (spec->board_config < 0) {
2172 printk(KERN_WARNING "hda_codec: No auto-config is "
2173 "available, default to model=ref\n");
2174 spec->board_config = STAC_9205_REF;
2180 stac92xx_free(codec);
2184 codec->patch_ops = stac92xx_patch_ops;
2193 /* static config for Sony VAIO FE550G and Sony VAIO AR */
2194 static hda_nid_t vaio_dacs[] = { 0x2 };
2195 #define VAIO_HP_DAC 0x5
2196 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
2197 static hda_nid_t vaio_mux_nids[] = { 0x15 };
2199 static struct hda_input_mux vaio_mux = {
2202 /* { "HP", 0x0 }, */
2209 static struct hda_verb vaio_init[] = {
2210 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2211 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2212 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2213 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2214 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2215 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2216 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2217 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2218 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2219 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2220 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2224 static struct hda_verb vaio_ar_init[] = {
2225 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
2226 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
2227 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
2228 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
2229 /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
2230 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
2231 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
2232 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
2233 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
2234 /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
2235 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
2236 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
2237 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
2241 /* bind volumes of both NID 0x02 and 0x05 */
2242 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
2243 struct snd_ctl_elem_value *ucontrol)
2245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2246 long *valp = ucontrol->value.integer.value;
2249 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2250 0x7f, valp[0] & 0x7f);
2251 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2252 0x7f, valp[1] & 0x7f);
2253 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2254 0x7f, valp[0] & 0x7f);
2255 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2256 0x7f, valp[1] & 0x7f);
2260 /* bind volumes of both NID 0x02 and 0x05 */
2261 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
2262 struct snd_ctl_elem_value *ucontrol)
2264 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2265 long *valp = ucontrol->value.integer.value;
2268 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
2269 0x80, (valp[0] ? 0 : 0x80));
2270 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
2271 0x80, (valp[1] ? 0 : 0x80));
2272 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
2273 0x80, (valp[0] ? 0 : 0x80));
2274 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
2275 0x80, (valp[1] ? 0 : 0x80));
2279 static struct snd_kcontrol_new vaio_mixer[] = {
2281 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2282 .name = "Master Playback Volume",
2283 .info = snd_hda_mixer_amp_volume_info,
2284 .get = snd_hda_mixer_amp_volume_get,
2285 .put = vaio_master_vol_put,
2286 .tlv = { .c = snd_hda_mixer_amp_tlv },
2287 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2290 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2291 .name = "Master Playback Switch",
2292 .info = snd_hda_mixer_amp_switch_info,
2293 .get = snd_hda_mixer_amp_switch_get,
2294 .put = vaio_master_sw_put,
2295 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2297 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2298 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2299 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2302 .name = "Capture Source",
2304 .info = stac92xx_mux_enum_info,
2305 .get = stac92xx_mux_enum_get,
2306 .put = stac92xx_mux_enum_put,
2311 static struct snd_kcontrol_new vaio_ar_mixer[] = {
2313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2314 .name = "Master Playback Volume",
2315 .info = snd_hda_mixer_amp_volume_info,
2316 .get = snd_hda_mixer_amp_volume_get,
2317 .put = vaio_master_vol_put,
2318 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2322 .name = "Master Playback Switch",
2323 .info = snd_hda_mixer_amp_switch_info,
2324 .get = snd_hda_mixer_amp_switch_get,
2325 .put = vaio_master_sw_put,
2326 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
2328 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
2329 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
2330 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
2331 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
2332 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
2334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2335 .name = "Capture Source",
2337 .info = stac92xx_mux_enum_info,
2338 .get = stac92xx_mux_enum_get,
2339 .put = stac92xx_mux_enum_put,
2344 static struct hda_codec_ops stac9872_patch_ops = {
2345 .build_controls = stac92xx_build_controls,
2346 .build_pcms = stac92xx_build_pcms,
2347 .init = stac92xx_init,
2348 .free = stac92xx_free,
2350 .resume = stac92xx_resume,
2354 enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
2356 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
2358 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
2360 /* AR Series. id=0x83847664 and subsys=104D1300 */
2365 static const char *stac9872_models[STAC_9872_MODELS] = {
2366 [CXD9872RD_VAIO] = "vaio",
2367 [CXD9872AKD_VAIO] = "vaio-ar",
2370 static struct snd_pci_quirk stac9872_cfg_tbl[] = {
2371 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
2372 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
2373 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
2374 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
2378 static int patch_stac9872(struct hda_codec *codec)
2380 struct sigmatel_spec *spec;
2383 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
2386 if (board_config < 0)
2387 /* unknown config, let generic-parser do its job... */
2388 return snd_hda_parse_generic_codec(codec);
2390 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2395 switch (board_config) {
2396 case CXD9872RD_VAIO:
2397 case STAC9872AK_VAIO:
2398 case STAC9872K_VAIO:
2399 spec->mixer = vaio_mixer;
2400 spec->init = vaio_init;
2401 spec->multiout.max_channels = 2;
2402 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2403 spec->multiout.dac_nids = vaio_dacs;
2404 spec->multiout.hp_nid = VAIO_HP_DAC;
2405 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2406 spec->adc_nids = vaio_adcs;
2407 spec->input_mux = &vaio_mux;
2408 spec->mux_nids = vaio_mux_nids;
2411 case CXD9872AKD_VAIO:
2412 spec->mixer = vaio_ar_mixer;
2413 spec->init = vaio_ar_init;
2414 spec->multiout.max_channels = 2;
2415 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
2416 spec->multiout.dac_nids = vaio_dacs;
2417 spec->multiout.hp_nid = VAIO_HP_DAC;
2418 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
2419 spec->adc_nids = vaio_adcs;
2420 spec->input_mux = &vaio_mux;
2421 spec->mux_nids = vaio_mux_nids;
2425 codec->patch_ops = stac9872_patch_ops;
2433 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
2434 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
2435 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
2436 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
2437 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
2438 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
2439 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
2440 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
2441 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
2442 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
2443 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
2444 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
2445 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
2446 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
2447 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
2448 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
2449 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
2450 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
2451 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
2452 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
2453 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
2454 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
2455 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
2456 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
2457 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
2458 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
2459 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
2460 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
2461 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
2462 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
2463 /* The following does not take into account .id=0x83847661 when subsys =
2464 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
2465 * currently not fully supported.
2467 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
2468 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
2469 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
2470 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
2471 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
2472 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
2473 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
2474 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
2475 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
2476 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
2477 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },