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
39 #define STAC_UNSOL_ENABLE (AC_USRSP_EN | STAC_HP_EVENT)
42 #define STAC_D945GTP3 1
43 #define STAC_D945GTP5 2
45 struct sigmatel_spec {
46 struct snd_kcontrol_new *mixers[4];
47 unsigned int num_mixers;
50 unsigned int surr_switch: 1;
51 unsigned int line_switch: 1;
52 unsigned int mic_switch: 1;
53 unsigned int alt_switch: 1;
56 struct hda_multi_out multiout;
57 hda_nid_t dac_nids[5];
61 unsigned int num_adcs;
63 unsigned int num_muxes;
68 unsigned int num_pins;
69 unsigned int *pin_configs;
71 /* codec specific stuff */
72 struct hda_verb *init;
73 struct snd_kcontrol_new *mixer;
76 struct hda_input_mux *input_mux;
77 unsigned int cur_mux[3];
80 unsigned int io_switch[2];
82 struct hda_pcm pcm_rec[2]; /* PCM information */
84 /* dynamic controls and input_mux */
85 struct auto_pin_cfg autocfg;
86 unsigned int num_kctl_alloc, num_kctl_used;
87 struct snd_kcontrol_new *kctl_alloc;
88 struct hda_input_mux private_imux;
91 static hda_nid_t stac9200_adc_nids[1] = {
95 static hda_nid_t stac9200_mux_nids[1] = {
99 static hda_nid_t stac9200_dac_nids[1] = {
103 static hda_nid_t stac922x_adc_nids[2] = {
107 static hda_nid_t stac922x_mux_nids[2] = {
111 static hda_nid_t stac927x_adc_nids[3] = {
115 static hda_nid_t stac927x_mux_nids[3] = {
119 static hda_nid_t stac9200_pin_nids[8] = {
120 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
123 static hda_nid_t stac922x_pin_nids[10] = {
124 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
125 0x0f, 0x10, 0x11, 0x15, 0x1b,
128 static hda_nid_t stac927x_pin_nids[14] = {
129 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
130 0x0f, 0x10, 0x11, 0x12, 0x13,
131 0x14, 0x21, 0x22, 0x23,
134 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
136 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
137 struct sigmatel_spec *spec = codec->spec;
138 return snd_hda_input_mux_info(spec->input_mux, uinfo);
141 static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
143 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
144 struct sigmatel_spec *spec = codec->spec;
145 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
147 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
151 static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
154 struct sigmatel_spec *spec = codec->spec;
155 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
157 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
158 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
161 static struct hda_verb stac9200_core_init[] = {
162 /* set dac0mux for dac converter */
163 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
167 static struct hda_verb stac922x_core_init[] = {
168 /* set master volume and direct control */
169 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
173 static struct hda_verb stac927x_core_init[] = {
174 /* set master volume and direct control */
175 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
179 static struct snd_kcontrol_new stac9200_mixer[] = {
180 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
181 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
184 .name = "Input Source",
186 .info = stac92xx_mux_enum_info,
187 .get = stac92xx_mux_enum_get,
188 .put = stac92xx_mux_enum_put,
190 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
191 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
192 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
196 /* This needs to be generated dynamically based on sequence */
197 static struct snd_kcontrol_new stac922x_mixer[] = {
199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
200 .name = "Input Source",
202 .info = stac92xx_mux_enum_info,
203 .get = stac92xx_mux_enum_get,
204 .put = stac92xx_mux_enum_put,
206 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
207 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
208 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
212 static snd_kcontrol_new_t stac927x_mixer[] = {
214 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
215 .name = "Input Source",
217 .info = stac92xx_mux_enum_info,
218 .get = stac92xx_mux_enum_get,
219 .put = stac92xx_mux_enum_put,
221 HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
222 HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
223 HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
227 static int stac92xx_build_controls(struct hda_codec *codec)
229 struct sigmatel_spec *spec = codec->spec;
233 err = snd_hda_add_new_ctls(codec, spec->mixer);
237 for (i = 0; i < spec->num_mixers; i++) {
238 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
243 if (spec->multiout.dig_out_nid) {
244 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
248 if (spec->dig_in_nid) {
249 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
256 static unsigned int ref9200_pin_configs[8] = {
257 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
258 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
261 static unsigned int *stac9200_brd_tbl[] = {
265 static struct hda_board_config stac9200_cfg_tbl[] = {
266 { .modelname = "ref",
267 .pci_subvendor = PCI_VENDOR_ID_INTEL,
268 .pci_subdevice = 0x2668, /* DFI LanParty */
269 .config = STAC_REF },
273 static unsigned int ref922x_pin_configs[10] = {
274 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
275 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
276 0x40000100, 0x40000100,
279 static unsigned int d945gtp3_pin_configs[10] = {
280 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
281 0x40000100, 0x40000100, 0x40000100, 0x40000100,
282 0x02a19120, 0x40000100,
285 static unsigned int d945gtp5_pin_configs[10] = {
286 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
287 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
288 0x02a19320, 0x40000100,
291 static unsigned int *stac922x_brd_tbl[] = {
293 d945gtp3_pin_configs,
294 d945gtp5_pin_configs,
297 static struct hda_board_config stac922x_cfg_tbl[] = {
298 { .modelname = "ref",
299 .pci_subvendor = PCI_VENDOR_ID_INTEL,
300 .pci_subdevice = 0x2668, /* DFI LanParty */
301 .config = STAC_REF }, /* SigmaTel reference board */
302 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
303 .pci_subdevice = 0x0101,
304 .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
305 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
306 .pci_subdevice = 0x0404,
307 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
308 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309 .pci_subdevice = 0x0303,
310 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
311 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
312 .pci_subdevice = 0x0013,
313 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
314 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315 .pci_subdevice = 0x0417,
316 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
320 static unsigned int ref927x_pin_configs[14] = {
321 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
322 0x01012012, 0x01011014, 0x40000100, 0x40000100,
323 0x40000100, 0x40000100, 0x40000100, 0x01441030,
324 0x01c41030, 0x40000100,
327 static unsigned int *stac927x_brd_tbl[] = {
331 static struct hda_board_config stac927x_cfg_tbl[] = {
332 { .modelname = "ref",
333 .pci_subvendor = PCI_VENDOR_ID_INTEL,
334 .pci_subdevice = 0x2668, /* DFI LanParty */
335 .config = STAC_REF }, /* SigmaTel reference board */
339 static void stac92xx_set_config_regs(struct hda_codec *codec)
342 struct sigmatel_spec *spec = codec->spec;
343 unsigned int pin_cfg;
345 for (i=0; i < spec->num_pins; i++) {
346 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
347 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
348 spec->pin_configs[i] & 0x000000ff);
349 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
350 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
351 (spec->pin_configs[i] & 0x0000ff00) >> 8);
352 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
354 (spec->pin_configs[i] & 0x00ff0000) >> 16);
355 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
357 spec->pin_configs[i] >> 24);
358 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
359 AC_VERB_GET_CONFIG_DEFAULT,
361 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
366 * Analog playback callbacks
368 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
369 struct hda_codec *codec,
370 struct snd_pcm_substream *substream)
372 struct sigmatel_spec *spec = codec->spec;
373 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
376 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
377 struct hda_codec *codec,
378 unsigned int stream_tag,
380 struct snd_pcm_substream *substream)
382 struct sigmatel_spec *spec = codec->spec;
383 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
386 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
387 struct hda_codec *codec,
388 struct snd_pcm_substream *substream)
390 struct sigmatel_spec *spec = codec->spec;
391 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
395 * Digital playback callbacks
397 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
398 struct hda_codec *codec,
399 struct snd_pcm_substream *substream)
401 struct sigmatel_spec *spec = codec->spec;
402 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
405 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
406 struct hda_codec *codec,
407 struct snd_pcm_substream *substream)
409 struct sigmatel_spec *spec = codec->spec;
410 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
415 * Analog capture callbacks
417 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
418 struct hda_codec *codec,
419 unsigned int stream_tag,
421 struct snd_pcm_substream *substream)
423 struct sigmatel_spec *spec = codec->spec;
425 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
426 stream_tag, 0, format);
430 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
431 struct hda_codec *codec,
432 struct snd_pcm_substream *substream)
434 struct sigmatel_spec *spec = codec->spec;
436 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
440 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
444 /* NID is set in stac92xx_build_pcms */
446 .open = stac92xx_dig_playback_pcm_open,
447 .close = stac92xx_dig_playback_pcm_close
451 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
455 /* NID is set in stac92xx_build_pcms */
458 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
462 .nid = 0x02, /* NID to query formats and rates */
464 .open = stac92xx_playback_pcm_open,
465 .prepare = stac92xx_playback_pcm_prepare,
466 .cleanup = stac92xx_playback_pcm_cleanup
470 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
474 .nid = 0x06, /* NID to query formats and rates */
476 .open = stac92xx_playback_pcm_open,
477 .prepare = stac92xx_playback_pcm_prepare,
478 .cleanup = stac92xx_playback_pcm_cleanup
482 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
486 /* NID is set in stac92xx_build_pcms */
488 .prepare = stac92xx_capture_pcm_prepare,
489 .cleanup = stac92xx_capture_pcm_cleanup
493 static int stac92xx_build_pcms(struct hda_codec *codec)
495 struct sigmatel_spec *spec = codec->spec;
496 struct hda_pcm *info = spec->pcm_rec;
499 codec->pcm_info = info;
501 info->name = "STAC92xx Analog";
502 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
503 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
504 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
506 if (spec->alt_switch) {
509 info->name = "STAC92xx Analog Alt";
510 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
513 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
516 info->name = "STAC92xx Digital";
517 if (spec->multiout.dig_out_nid) {
518 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
519 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
521 if (spec->dig_in_nid) {
522 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
523 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
530 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
533 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
536 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
538 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
540 uinfo->value.integer.min = 0;
541 uinfo->value.integer.max = 1;
545 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
548 struct sigmatel_spec *spec = codec->spec;
549 int io_idx = kcontrol-> private_value & 0xff;
551 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
555 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
558 struct sigmatel_spec *spec = codec->spec;
559 hda_nid_t nid = kcontrol->private_value >> 8;
560 int io_idx = kcontrol-> private_value & 0xff;
561 unsigned short val = ucontrol->value.integer.value[0];
563 spec->io_switch[io_idx] = val;
566 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
568 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
573 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
574 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
577 .info = stac92xx_io_switch_info, \
578 .get = stac92xx_io_switch_get, \
579 .put = stac92xx_io_switch_put, \
580 .private_value = xpval, \
586 STAC_CTL_WIDGET_MUTE,
587 STAC_CTL_WIDGET_IO_SWITCH,
590 static struct snd_kcontrol_new stac92xx_control_templates[] = {
591 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
592 HDA_CODEC_MUTE(NULL, 0, 0, 0),
593 STAC_CODEC_IO_SWITCH(NULL, 0),
596 /* add dynamic controls */
597 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
599 struct snd_kcontrol_new *knew;
601 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
602 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
604 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
607 if (spec->kctl_alloc) {
608 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
609 kfree(spec->kctl_alloc);
611 spec->kctl_alloc = knew;
612 spec->num_kctl_alloc = num;
615 knew = &spec->kctl_alloc[spec->num_kctl_used];
616 *knew = stac92xx_control_templates[type];
617 knew->name = kstrdup(name, GFP_KERNEL);
620 knew->private_value = val;
621 spec->num_kctl_used++;
625 /* flag inputs as additional dynamic lineouts */
626 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
628 struct sigmatel_spec *spec = codec->spec;
630 switch (cfg->line_outs) {
632 /* add line-in as side */
633 if (cfg->input_pins[AUTO_PIN_LINE]) {
634 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
635 spec->line_switch = 1;
640 /* add line-in as clfe and mic as side */
641 if (cfg->input_pins[AUTO_PIN_LINE]) {
642 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
643 spec->line_switch = 1;
646 if (cfg->input_pins[AUTO_PIN_MIC]) {
647 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
648 spec->mic_switch = 1;
653 /* add line-in as surr and mic as clfe */
654 if (cfg->input_pins[AUTO_PIN_LINE]) {
655 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
656 spec->line_switch = 1;
659 if (cfg->input_pins[AUTO_PIN_MIC]) {
660 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
661 spec->mic_switch = 1;
671 * XXX The line_out pin widget connection list may not be set to the
672 * desired DAC nid. This is the case on 927x where ports A and B can
673 * be routed to several DACs.
675 * This requires an analysis of the line-out/hp pin configuration
676 * to provide a best fit for pin/DAC configurations that are routable.
677 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
678 * A and B is not supported.
680 /* fill in the dac_nids table from the parsed pin configuration */
681 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
683 struct sigmatel_spec *spec = codec->spec;
687 /* check the pins hardwired to audio widget */
688 for (i = 0; i < cfg->line_outs; i++) {
689 nid = cfg->line_out_pins[i];
690 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
691 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
695 spec->multiout.num_dacs = cfg->line_outs;
696 else if (cfg->hp_pin) {
697 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
698 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
699 spec->multiout.num_dacs = 1;
705 /* add playback controls from the parsed DAC table */
706 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
709 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
713 for (i = 0; i < cfg->line_outs; i++) {
714 if (!spec->multiout.dac_nids[i])
717 nid = spec->multiout.dac_nids[i];
721 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
722 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
724 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
725 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
727 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
728 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
730 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
731 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
734 sprintf(name, "%s Playback Volume", chname[i]);
735 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
736 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
738 sprintf(name, "%s Playback Switch", chname[i]);
739 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
740 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
745 if (spec->line_switch)
746 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
749 if (spec->mic_switch)
750 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
756 /* add playback controls for HP output */
757 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
759 struct sigmatel_spec *spec = codec->spec;
760 hda_nid_t pin = cfg->hp_pin;
763 unsigned int wid_caps;
768 wid_caps = get_wcaps(codec, pin);
769 if (wid_caps & AC_WCAP_UNSOL_CAP)
770 /* Enable unsolicited responses on the HP widget */
771 snd_hda_codec_write(codec, pin, 0,
772 AC_VERB_SET_UNSOLICITED_ENABLE,
775 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
776 for (i = 0; i < cfg->line_outs; i++) {
777 if (! spec->multiout.dac_nids[i])
779 if (spec->multiout.dac_nids[i] == nid)
783 spec->multiout.hp_nid = nid;
785 /* control HP volume/switch on the output mixer amp */
786 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
787 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
789 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
790 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
796 /* create playback/capture controls for input pins */
797 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
799 struct sigmatel_spec *spec = codec->spec;
800 struct hda_input_mux *imux = &spec->private_imux;
801 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
804 for (i = 0; i < AUTO_PIN_LAST; i++) {
806 if (cfg->input_pins[i]) {
807 /* Enable active pin widget as an input */
808 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
810 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
812 for (j=0; j<spec->num_muxes; j++) {
813 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
814 for (k=0; k<num_cons; k++)
815 if (con_lst[k] == cfg->input_pins[i]) {
822 imux->items[imux->num_items].index = index;
830 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
832 struct sigmatel_spec *spec = codec->spec;
835 for (i = 0; i < spec->autocfg.line_outs; i++) {
836 hda_nid_t nid = spec->autocfg.line_out_pins[i];
837 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
841 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
843 struct sigmatel_spec *spec = codec->spec;
846 pin = spec->autocfg.hp_pin;
847 if (pin) /* connect to front */
848 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
851 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
853 struct sigmatel_spec *spec = codec->spec;
856 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
858 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
859 return 0; /* can't find valid pin config */
860 stac92xx_auto_init_multi_out(codec);
861 stac92xx_auto_init_hp_out(codec);
862 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
864 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
867 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
868 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
869 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
872 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
873 if (spec->multiout.max_channels > 2)
874 spec->surr_switch = 1;
876 if (spec->autocfg.dig_out_pin) {
877 spec->multiout.dig_out_nid = dig_out;
878 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
880 if (spec->autocfg.dig_in_pin) {
881 spec->dig_in_nid = dig_in;
882 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
885 if (spec->kctl_alloc)
886 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
888 spec->input_mux = &spec->private_imux;
893 static int stac9200_parse_auto_config(struct hda_codec *codec)
895 struct sigmatel_spec *spec = codec->spec;
898 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
901 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
904 if (spec->autocfg.dig_out_pin) {
905 spec->multiout.dig_out_nid = 0x05;
906 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
908 if (spec->autocfg.dig_in_pin) {
909 spec->dig_in_nid = 0x04;
910 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
913 if (spec->kctl_alloc)
914 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
916 spec->input_mux = &spec->private_imux;
921 static int stac92xx_init(struct hda_codec *codec)
923 struct sigmatel_spec *spec = codec->spec;
925 snd_hda_sequence_write(codec, spec->init);
930 static void stac92xx_free(struct hda_codec *codec)
932 struct sigmatel_spec *spec = codec->spec;
938 if (spec->kctl_alloc) {
939 for (i = 0; i < spec->num_kctl_used; i++)
940 kfree(spec->kctl_alloc[i].name);
941 kfree(spec->kctl_alloc);
947 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
950 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
951 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
952 snd_hda_codec_write(codec, nid, 0,
953 AC_VERB_SET_PIN_WIDGET_CONTROL,
957 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
960 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
961 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
962 snd_hda_codec_write(codec, nid, 0,
963 AC_VERB_SET_PIN_WIDGET_CONTROL,
967 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
969 struct sigmatel_spec *spec = codec->spec;
970 struct auto_pin_cfg *cfg = &spec->autocfg;
973 if ((res >> 26) != STAC_HP_EVENT)
976 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
977 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
980 /* disable lineouts, enable hp */
981 for (i = 0; i < cfg->line_outs; i++)
982 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
984 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
986 /* enable lineouts, disable hp */
987 for (i = 0; i < cfg->line_outs; i++)
988 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
990 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
995 static int stac92xx_resume(struct hda_codec *codec)
997 struct sigmatel_spec *spec = codec->spec;
1000 stac92xx_init(codec);
1001 for (i = 0; i < spec->num_mixers; i++)
1002 snd_hda_resume_ctls(codec, spec->mixers[i]);
1003 if (spec->multiout.dig_out_nid)
1004 snd_hda_resume_spdif_out(codec);
1005 if (spec->dig_in_nid)
1006 snd_hda_resume_spdif_in(codec);
1012 static struct hda_codec_ops stac92xx_patch_ops = {
1013 .build_controls = stac92xx_build_controls,
1014 .build_pcms = stac92xx_build_pcms,
1015 .init = stac92xx_init,
1016 .free = stac92xx_free,
1017 .unsol_event = stac92xx_unsol_event,
1019 .resume = stac92xx_resume,
1023 static int patch_stac9200(struct hda_codec *codec)
1025 struct sigmatel_spec *spec;
1028 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1033 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1034 if (spec->board_config < 0)
1035 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1038 spec->pin_nids = stac9200_pin_nids;
1039 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1040 stac92xx_set_config_regs(codec);
1043 spec->multiout.max_channels = 2;
1044 spec->multiout.num_dacs = 1;
1045 spec->multiout.dac_nids = stac9200_dac_nids;
1046 spec->adc_nids = stac9200_adc_nids;
1047 spec->mux_nids = stac9200_mux_nids;
1048 spec->num_muxes = 1;
1050 spec->init = stac9200_core_init;
1051 spec->mixer = stac9200_mixer;
1053 err = stac9200_parse_auto_config(codec);
1055 stac92xx_free(codec);
1059 codec->patch_ops = stac92xx_patch_ops;
1064 static int patch_stac922x(struct hda_codec *codec)
1066 struct sigmatel_spec *spec;
1069 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1074 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1075 if (spec->board_config < 0)
1076 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1078 spec->num_pins = 10;
1079 spec->pin_nids = stac922x_pin_nids;
1080 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1081 stac92xx_set_config_regs(codec);
1084 spec->adc_nids = stac922x_adc_nids;
1085 spec->mux_nids = stac922x_mux_nids;
1086 spec->num_muxes = 2;
1088 spec->init = stac922x_core_init;
1089 spec->mixer = stac922x_mixer;
1091 spec->multiout.dac_nids = spec->dac_nids;
1093 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1095 stac92xx_free(codec);
1099 codec->patch_ops = stac92xx_patch_ops;
1104 static int patch_stac927x(struct hda_codec *codec)
1106 struct sigmatel_spec *spec;
1109 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1114 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1115 if (spec->board_config < 0)
1116 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1118 spec->num_pins = 14;
1119 spec->pin_nids = stac927x_pin_nids;
1120 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1121 stac92xx_set_config_regs(codec);
1124 spec->adc_nids = stac927x_adc_nids;
1125 spec->mux_nids = stac927x_mux_nids;
1126 spec->num_muxes = 3;
1128 spec->init = stac927x_core_init;
1129 spec->mixer = stac927x_mixer;
1131 spec->multiout.dac_nids = spec->dac_nids;
1133 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1135 stac92xx_free(codec);
1139 codec->patch_ops = stac92xx_patch_ops;
1147 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1148 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1149 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1150 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1151 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1152 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1153 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1154 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
1155 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1156 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1157 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1158 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1159 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1160 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1161 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1162 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1163 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1164 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },