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 = 0x0202,
307 .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack, 9221 A1 */
308 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
309 .pci_subdevice = 0x0b0b,
310 .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack, 9221 A1 */
311 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
312 .pci_subdevice = 0x0404,
313 .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
314 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
315 .pci_subdevice = 0x0303,
316 .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
317 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
318 .pci_subdevice = 0x0013,
319 .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
320 { .pci_subvendor = PCI_VENDOR_ID_INTEL,
321 .pci_subdevice = 0x0417,
322 .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
326 static unsigned int ref927x_pin_configs[14] = {
327 0x01813122, 0x01a19021, 0x01014010, 0x01016011,
328 0x01012012, 0x01011014, 0x40000100, 0x40000100,
329 0x40000100, 0x40000100, 0x40000100, 0x01441030,
330 0x01c41030, 0x40000100,
333 static unsigned int *stac927x_brd_tbl[] = {
337 static struct hda_board_config stac927x_cfg_tbl[] = {
338 { .modelname = "ref",
339 .pci_subvendor = PCI_VENDOR_ID_INTEL,
340 .pci_subdevice = 0x2668, /* DFI LanParty */
341 .config = STAC_REF }, /* SigmaTel reference board */
345 static void stac92xx_set_config_regs(struct hda_codec *codec)
348 struct sigmatel_spec *spec = codec->spec;
349 unsigned int pin_cfg;
351 for (i=0; i < spec->num_pins; i++) {
352 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
353 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
354 spec->pin_configs[i] & 0x000000ff);
355 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
356 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
357 (spec->pin_configs[i] & 0x0000ff00) >> 8);
358 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
359 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
360 (spec->pin_configs[i] & 0x00ff0000) >> 16);
361 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
362 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
363 spec->pin_configs[i] >> 24);
364 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
365 AC_VERB_GET_CONFIG_DEFAULT,
367 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
372 * Analog playback callbacks
374 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
375 struct hda_codec *codec,
376 struct snd_pcm_substream *substream)
378 struct sigmatel_spec *spec = codec->spec;
379 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
382 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
383 struct hda_codec *codec,
384 unsigned int stream_tag,
386 struct snd_pcm_substream *substream)
388 struct sigmatel_spec *spec = codec->spec;
389 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
392 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
393 struct hda_codec *codec,
394 struct snd_pcm_substream *substream)
396 struct sigmatel_spec *spec = codec->spec;
397 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
401 * Digital playback callbacks
403 static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
404 struct hda_codec *codec,
405 struct snd_pcm_substream *substream)
407 struct sigmatel_spec *spec = codec->spec;
408 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
411 static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
412 struct hda_codec *codec,
413 struct snd_pcm_substream *substream)
415 struct sigmatel_spec *spec = codec->spec;
416 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
421 * Analog capture callbacks
423 static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
424 struct hda_codec *codec,
425 unsigned int stream_tag,
427 struct snd_pcm_substream *substream)
429 struct sigmatel_spec *spec = codec->spec;
431 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
432 stream_tag, 0, format);
436 static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
437 struct hda_codec *codec,
438 struct snd_pcm_substream *substream)
440 struct sigmatel_spec *spec = codec->spec;
442 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
446 static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
450 /* NID is set in stac92xx_build_pcms */
452 .open = stac92xx_dig_playback_pcm_open,
453 .close = stac92xx_dig_playback_pcm_close
457 static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
461 /* NID is set in stac92xx_build_pcms */
464 static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
468 .nid = 0x02, /* NID to query formats and rates */
470 .open = stac92xx_playback_pcm_open,
471 .prepare = stac92xx_playback_pcm_prepare,
472 .cleanup = stac92xx_playback_pcm_cleanup
476 static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
480 .nid = 0x06, /* NID to query formats and rates */
482 .open = stac92xx_playback_pcm_open,
483 .prepare = stac92xx_playback_pcm_prepare,
484 .cleanup = stac92xx_playback_pcm_cleanup
488 static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
492 /* NID is set in stac92xx_build_pcms */
494 .prepare = stac92xx_capture_pcm_prepare,
495 .cleanup = stac92xx_capture_pcm_cleanup
499 static int stac92xx_build_pcms(struct hda_codec *codec)
501 struct sigmatel_spec *spec = codec->spec;
502 struct hda_pcm *info = spec->pcm_rec;
505 codec->pcm_info = info;
507 info->name = "STAC92xx Analog";
508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
509 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
510 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
512 if (spec->alt_switch) {
515 info->name = "STAC92xx Analog Alt";
516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
519 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
522 info->name = "STAC92xx Digital";
523 if (spec->multiout.dig_out_nid) {
524 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
525 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
527 if (spec->dig_in_nid) {
528 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
529 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
536 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
539 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
542 static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
546 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 1;
551 static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct sigmatel_spec *spec = codec->spec;
555 int io_idx = kcontrol-> private_value & 0xff;
557 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
561 static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 hda_nid_t nid = kcontrol->private_value >> 8;
566 int io_idx = kcontrol-> private_value & 0xff;
567 unsigned short val = ucontrol->value.integer.value[0];
569 spec->io_switch[io_idx] = val;
572 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
574 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
579 #define STAC_CODEC_IO_SWITCH(xname, xpval) \
580 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
583 .info = stac92xx_io_switch_info, \
584 .get = stac92xx_io_switch_get, \
585 .put = stac92xx_io_switch_put, \
586 .private_value = xpval, \
592 STAC_CTL_WIDGET_MUTE,
593 STAC_CTL_WIDGET_IO_SWITCH,
596 static struct snd_kcontrol_new stac92xx_control_templates[] = {
597 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
598 HDA_CODEC_MUTE(NULL, 0, 0, 0),
599 STAC_CODEC_IO_SWITCH(NULL, 0),
602 /* add dynamic controls */
603 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
605 struct snd_kcontrol_new *knew;
607 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
608 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
610 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
613 if (spec->kctl_alloc) {
614 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
615 kfree(spec->kctl_alloc);
617 spec->kctl_alloc = knew;
618 spec->num_kctl_alloc = num;
621 knew = &spec->kctl_alloc[spec->num_kctl_used];
622 *knew = stac92xx_control_templates[type];
623 knew->name = kstrdup(name, GFP_KERNEL);
626 knew->private_value = val;
627 spec->num_kctl_used++;
631 /* flag inputs as additional dynamic lineouts */
632 static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
634 struct sigmatel_spec *spec = codec->spec;
636 switch (cfg->line_outs) {
638 /* add line-in as side */
639 if (cfg->input_pins[AUTO_PIN_LINE]) {
640 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
641 spec->line_switch = 1;
646 /* add line-in as clfe and mic as side */
647 if (cfg->input_pins[AUTO_PIN_LINE]) {
648 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
649 spec->line_switch = 1;
652 if (cfg->input_pins[AUTO_PIN_MIC]) {
653 cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
654 spec->mic_switch = 1;
659 /* add line-in as surr and mic as clfe */
660 if (cfg->input_pins[AUTO_PIN_LINE]) {
661 cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
662 spec->line_switch = 1;
665 if (cfg->input_pins[AUTO_PIN_MIC]) {
666 cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
667 spec->mic_switch = 1;
677 * XXX The line_out pin widget connection list may not be set to the
678 * desired DAC nid. This is the case on 927x where ports A and B can
679 * be routed to several DACs.
681 * This requires an analysis of the line-out/hp pin configuration
682 * to provide a best fit for pin/DAC configurations that are routable.
683 * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
684 * A and B is not supported.
686 /* fill in the dac_nids table from the parsed pin configuration */
687 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
689 struct sigmatel_spec *spec = codec->spec;
693 /* check the pins hardwired to audio widget */
694 for (i = 0; i < cfg->line_outs; i++) {
695 nid = cfg->line_out_pins[i];
696 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
697 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
701 spec->multiout.num_dacs = cfg->line_outs;
702 else if (cfg->hp_pin) {
703 spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
704 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
705 spec->multiout.num_dacs = 1;
711 /* add playback controls from the parsed DAC table */
712 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
715 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
719 for (i = 0; i < cfg->line_outs; i++) {
720 if (!spec->multiout.dac_nids[i])
723 nid = spec->multiout.dac_nids[i];
727 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
728 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
730 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
731 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
733 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
734 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
736 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
737 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
740 sprintf(name, "%s Playback Volume", chname[i]);
741 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
742 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
744 sprintf(name, "%s Playback Switch", chname[i]);
745 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
746 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
751 if (spec->line_switch)
752 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
755 if (spec->mic_switch)
756 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
762 /* add playback controls for HP output */
763 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
765 struct sigmatel_spec *spec = codec->spec;
766 hda_nid_t pin = cfg->hp_pin;
769 unsigned int wid_caps;
774 wid_caps = get_wcaps(codec, pin);
775 if (wid_caps & AC_WCAP_UNSOL_CAP)
776 /* Enable unsolicited responses on the HP widget */
777 snd_hda_codec_write(codec, pin, 0,
778 AC_VERB_SET_UNSOLICITED_ENABLE,
781 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
782 for (i = 0; i < cfg->line_outs; i++) {
783 if (! spec->multiout.dac_nids[i])
785 if (spec->multiout.dac_nids[i] == nid)
789 spec->multiout.hp_nid = nid;
791 /* control HP volume/switch on the output mixer amp */
792 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
793 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
795 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
796 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
802 /* create playback/capture controls for input pins */
803 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
805 struct sigmatel_spec *spec = codec->spec;
806 struct hda_input_mux *imux = &spec->private_imux;
807 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
810 for (i = 0; i < AUTO_PIN_LAST; i++) {
812 if (cfg->input_pins[i]) {
813 /* Enable active pin widget as an input */
814 stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
816 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
818 for (j=0; j<spec->num_muxes; j++) {
819 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
820 for (k=0; k<num_cons; k++)
821 if (con_lst[k] == cfg->input_pins[i]) {
828 imux->items[imux->num_items].index = index;
836 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
838 struct sigmatel_spec *spec = codec->spec;
841 for (i = 0; i < spec->autocfg.line_outs; i++) {
842 hda_nid_t nid = spec->autocfg.line_out_pins[i];
843 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
847 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
849 struct sigmatel_spec *spec = codec->spec;
852 pin = spec->autocfg.hp_pin;
853 if (pin) /* connect to front */
854 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
857 static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
859 struct sigmatel_spec *spec = codec->spec;
862 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
864 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
865 return 0; /* can't find valid pin config */
866 stac92xx_auto_init_multi_out(codec);
867 stac92xx_auto_init_hp_out(codec);
868 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
870 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
873 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
874 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
875 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
879 if (spec->multiout.max_channels > 2)
880 spec->surr_switch = 1;
882 if (spec->autocfg.dig_out_pin) {
883 spec->multiout.dig_out_nid = dig_out;
884 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
886 if (spec->autocfg.dig_in_pin) {
887 spec->dig_in_nid = dig_in;
888 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
891 if (spec->kctl_alloc)
892 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
894 spec->input_mux = &spec->private_imux;
899 static int stac9200_parse_auto_config(struct hda_codec *codec)
901 struct sigmatel_spec *spec = codec->spec;
904 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
907 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
910 if (spec->autocfg.dig_out_pin) {
911 spec->multiout.dig_out_nid = 0x05;
912 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
914 if (spec->autocfg.dig_in_pin) {
915 spec->dig_in_nid = 0x04;
916 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
919 if (spec->kctl_alloc)
920 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
922 spec->input_mux = &spec->private_imux;
927 static int stac92xx_init(struct hda_codec *codec)
929 struct sigmatel_spec *spec = codec->spec;
931 snd_hda_sequence_write(codec, spec->init);
936 static void stac92xx_free(struct hda_codec *codec)
938 struct sigmatel_spec *spec = codec->spec;
944 if (spec->kctl_alloc) {
945 for (i = 0; i < spec->num_kctl_used; i++)
946 kfree(spec->kctl_alloc[i].name);
947 kfree(spec->kctl_alloc);
953 static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
956 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
957 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
958 snd_hda_codec_write(codec, nid, 0,
959 AC_VERB_SET_PIN_WIDGET_CONTROL,
963 static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
966 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
967 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
968 snd_hda_codec_write(codec, nid, 0,
969 AC_VERB_SET_PIN_WIDGET_CONTROL,
973 static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
975 struct sigmatel_spec *spec = codec->spec;
976 struct auto_pin_cfg *cfg = &spec->autocfg;
979 if ((res >> 26) != STAC_HP_EVENT)
982 presence = snd_hda_codec_read(codec, cfg->hp_pin, 0,
983 AC_VERB_GET_PIN_SENSE, 0x00) >> 31;
986 /* disable lineouts, enable hp */
987 for (i = 0; i < cfg->line_outs; i++)
988 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
990 stac92xx_set_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
992 /* enable lineouts, disable hp */
993 for (i = 0; i < cfg->line_outs; i++)
994 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
996 stac92xx_reset_pinctl(codec, cfg->hp_pin, AC_PINCTL_OUT_EN);
1001 static int stac92xx_resume(struct hda_codec *codec)
1003 struct sigmatel_spec *spec = codec->spec;
1006 stac92xx_init(codec);
1007 for (i = 0; i < spec->num_mixers; i++)
1008 snd_hda_resume_ctls(codec, spec->mixers[i]);
1009 if (spec->multiout.dig_out_nid)
1010 snd_hda_resume_spdif_out(codec);
1011 if (spec->dig_in_nid)
1012 snd_hda_resume_spdif_in(codec);
1018 static struct hda_codec_ops stac92xx_patch_ops = {
1019 .build_controls = stac92xx_build_controls,
1020 .build_pcms = stac92xx_build_pcms,
1021 .init = stac92xx_init,
1022 .free = stac92xx_free,
1023 .unsol_event = stac92xx_unsol_event,
1025 .resume = stac92xx_resume,
1029 static int patch_stac9200(struct hda_codec *codec)
1031 struct sigmatel_spec *spec;
1034 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1039 spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
1040 if (spec->board_config < 0)
1041 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
1044 spec->pin_nids = stac9200_pin_nids;
1045 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
1046 stac92xx_set_config_regs(codec);
1049 spec->multiout.max_channels = 2;
1050 spec->multiout.num_dacs = 1;
1051 spec->multiout.dac_nids = stac9200_dac_nids;
1052 spec->adc_nids = stac9200_adc_nids;
1053 spec->mux_nids = stac9200_mux_nids;
1054 spec->num_muxes = 1;
1056 spec->init = stac9200_core_init;
1057 spec->mixer = stac9200_mixer;
1059 err = stac9200_parse_auto_config(codec);
1061 stac92xx_free(codec);
1065 codec->patch_ops = stac92xx_patch_ops;
1070 static int patch_stac922x(struct hda_codec *codec)
1072 struct sigmatel_spec *spec;
1075 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1080 spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
1081 if (spec->board_config < 0)
1082 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
1084 spec->num_pins = 10;
1085 spec->pin_nids = stac922x_pin_nids;
1086 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
1087 stac92xx_set_config_regs(codec);
1090 spec->adc_nids = stac922x_adc_nids;
1091 spec->mux_nids = stac922x_mux_nids;
1092 spec->num_muxes = 2;
1094 spec->init = stac922x_core_init;
1095 spec->mixer = stac922x_mixer;
1097 spec->multiout.dac_nids = spec->dac_nids;
1099 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
1101 stac92xx_free(codec);
1105 codec->patch_ops = stac92xx_patch_ops;
1110 static int patch_stac927x(struct hda_codec *codec)
1112 struct sigmatel_spec *spec;
1115 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1120 spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
1121 if (spec->board_config < 0)
1122 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
1124 spec->num_pins = 14;
1125 spec->pin_nids = stac927x_pin_nids;
1126 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
1127 stac92xx_set_config_regs(codec);
1130 spec->adc_nids = stac927x_adc_nids;
1131 spec->mux_nids = stac927x_mux_nids;
1132 spec->num_muxes = 3;
1134 spec->init = stac927x_core_init;
1135 spec->mixer = stac927x_mixer;
1137 spec->multiout.dac_nids = spec->dac_nids;
1139 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
1141 stac92xx_free(codec);
1145 codec->patch_ops = stac92xx_patch_ops;
1154 /* static config for Sony VAIO FE550G */
1155 static hda_nid_t vaio_dacs[] = { 0x2 };
1156 #define VAIO_HP_DAC 0x5
1157 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
1158 static hda_nid_t vaio_mux_nids[] = { 0x15 };
1160 static struct hda_input_mux vaio_mux = {
1164 { "Unknown", 0x1 }, */
1170 static struct hda_verb vaio_init[] = {
1171 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
1172 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
1173 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
1174 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
1175 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
1176 {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
1177 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
1178 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
1179 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
1180 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
1181 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
1185 /* bind volumes of both NID 0x02 and 0x05 */
1186 static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
1187 struct snd_ctl_elem_value *ucontrol)
1189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1190 long *valp = ucontrol->value.integer.value;
1193 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1194 0x7f, valp[0] & 0x7f);
1195 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1196 0x7f, valp[1] & 0x7f);
1197 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1198 0x7f, valp[0] & 0x7f);
1199 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1200 0x7f, valp[1] & 0x7f);
1204 /* bind volumes of both NID 0x02 and 0x05 */
1205 static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
1206 struct snd_ctl_elem_value *ucontrol)
1208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1209 long *valp = ucontrol->value.integer.value;
1212 change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
1213 0x80, valp[0] & 0x80);
1214 change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
1215 0x80, valp[1] & 0x80);
1216 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1217 0x80, valp[0] & 0x80);
1218 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1219 0x80, valp[1] & 0x80);
1223 static struct snd_kcontrol_new vaio_mixer[] = {
1225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1226 .name = "Master Playback Volume",
1227 .info = snd_hda_mixer_amp_volume_info,
1228 .get = snd_hda_mixer_amp_volume_get,
1229 .put = vaio_master_vol_put,
1230 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1234 .name = "Master Playback Switch",
1235 .info = snd_hda_mixer_amp_switch_info,
1236 .get = snd_hda_mixer_amp_switch_get,
1237 .put = vaio_master_sw_put,
1238 .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
1240 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
1241 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
1242 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
1244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1245 .name = "Capture Source",
1247 .info = stac92xx_mux_enum_info,
1248 .get = stac92xx_mux_enum_get,
1249 .put = stac92xx_mux_enum_put,
1254 static struct hda_codec_ops stac7661_patch_ops = {
1255 .build_controls = stac92xx_build_controls,
1256 .build_pcms = stac92xx_build_pcms,
1257 .init = stac92xx_init,
1258 .free = stac92xx_free,
1260 .resume = stac92xx_resume,
1264 enum { STAC7661_VAIO };
1266 static struct hda_board_config stac7661_cfg_tbl[] = {
1267 { .modelname = "vaio", .config = STAC7661_VAIO },
1268 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
1269 .config = STAC7661_VAIO },
1270 { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
1271 .config = STAC7661_VAIO },
1275 static int patch_stac7661(struct hda_codec *codec)
1277 struct sigmatel_spec *spec;
1280 board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
1281 if (board_config < 0)
1282 /* unknown config, let generic-parser do its job... */
1283 return snd_hda_parse_generic_codec(codec);
1285 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1290 switch (board_config) {
1292 spec->mixer = vaio_mixer;
1293 spec->init = vaio_init;
1294 spec->multiout.max_channels = 2;
1295 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
1296 spec->multiout.dac_nids = vaio_dacs;
1297 spec->multiout.hp_nid = VAIO_HP_DAC;
1298 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
1299 spec->adc_nids = vaio_adcs;
1300 spec->input_mux = &vaio_mux;
1301 spec->mux_nids = vaio_mux_nids;
1305 codec->patch_ops = stac7661_patch_ops;
1313 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
1314 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
1315 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
1316 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
1317 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
1318 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
1319 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
1320 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
1321 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
1322 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
1323 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
1324 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
1325 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
1326 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
1327 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
1328 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
1329 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
1330 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
1331 { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },