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@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"
39 struct sigmatel_spec {
40 snd_kcontrol_new_t *mixers[4];
41 unsigned int num_mixers;
43 unsigned int surr_switch: 1;
46 struct hda_multi_out multiout;
47 hda_nid_t dac_nids[4];
51 unsigned int num_adcs;
53 unsigned int num_muxes;
59 unsigned int num_pins;
60 unsigned int *pin_configs;
63 /* codec specific stuff */
64 struct hda_verb *init;
65 snd_kcontrol_new_t *mixer;
68 struct hda_input_mux *input_mux;
69 unsigned int cur_mux[2];
72 unsigned int num_ch_modes;
73 unsigned int cur_ch_mode;
75 struct hda_pcm pcm_rec[2]; /* PCM information */
77 /* dynamic controls and input_mux */
78 struct auto_pin_cfg autocfg;
79 unsigned int num_kctl_alloc, num_kctl_used;
80 snd_kcontrol_new_t *kctl_alloc;
81 struct hda_input_mux private_imux;
84 static hda_nid_t stac9200_adc_nids[1] = {
88 static hda_nid_t stac9200_mux_nids[1] = {
92 static hda_nid_t stac9200_dac_nids[1] = {
96 static hda_nid_t stac922x_adc_nids[2] = {
100 static hda_nid_t stac922x_mux_nids[2] = {
105 static hda_nid_t stac9200_pin_nids[8] = {
106 0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
109 static hda_nid_t stac922x_pin_nids[10] = {
110 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
111 0x0f, 0x10, 0x11, 0x15, 0x1b,
115 static int stac92xx_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
117 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
118 struct sigmatel_spec *spec = codec->spec;
119 return snd_hda_input_mux_info(spec->input_mux, uinfo);
122 static int stac92xx_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
125 struct sigmatel_spec *spec = codec->spec;
126 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
128 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
132 static int stac92xx_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
134 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
135 struct sigmatel_spec *spec = codec->spec;
136 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
138 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
139 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
142 static struct hda_verb stac9200_core_init[] = {
143 /* set dac0mux for dac converter */
144 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
148 static struct hda_verb stac922x_core_init[] = {
149 /* set master volume and direct control */
150 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
154 static int stac922x_channel_modes[3] = {2, 6, 8};
156 static int stac922x_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
158 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
159 struct sigmatel_spec *spec = codec->spec;
161 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
163 uinfo->value.enumerated.items = spec->num_ch_modes;
164 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
165 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
166 sprintf(uinfo->value.enumerated.name, "%dch",
167 stac922x_channel_modes[uinfo->value.enumerated.item]);
171 static int stac922x_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
173 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
174 struct sigmatel_spec *spec = codec->spec;
176 ucontrol->value.enumerated.item[0] = spec->cur_ch_mode;
180 static int stac922x_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
182 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
183 struct sigmatel_spec *spec = codec->spec;
185 if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
186 ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
187 if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
191 spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
192 spec->multiout.max_channels = stac922x_channel_modes[spec->cur_ch_mode];
197 static snd_kcontrol_new_t stac9200_mixer[] = {
198 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
199 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
201 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
202 .name = "Input Source",
204 .info = stac92xx_mux_enum_info,
205 .get = stac92xx_mux_enum_get,
206 .put = stac92xx_mux_enum_put,
208 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
209 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
210 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
214 /* This needs to be generated dynamically based on sequence */
215 static snd_kcontrol_new_t stac922x_mixer[] = {
217 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
218 .name = "Input Source",
220 .info = stac92xx_mux_enum_info,
221 .get = stac92xx_mux_enum_get,
222 .put = stac92xx_mux_enum_put,
224 HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
225 HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
226 HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
230 static snd_kcontrol_new_t stac922x_ch_mode_mixer[] = {
232 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
233 .name = "Channel Mode",
234 .info = stac922x_ch_mode_info,
235 .get = stac922x_ch_mode_get,
236 .put = stac922x_ch_mode_put,
241 static int stac92xx_build_controls(struct hda_codec *codec)
243 struct sigmatel_spec *spec = codec->spec;
247 err = snd_hda_add_new_ctls(codec, spec->mixer);
251 for (i = 0; i < spec->num_mixers; i++) {
252 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
257 if (spec->surr_switch) {
258 err = snd_hda_add_new_ctls(codec, stac922x_ch_mode_mixer);
262 if (spec->multiout.dig_out_nid) {
263 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
267 if (spec->dig_in_nid) {
268 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
276 static unsigned int stac9200_pin_configs[8] = {
277 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
278 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
281 static unsigned int stac922x_pin_configs[10] = {
282 0x01014010, 0x01014011, 0x01014012, 0x0221401f,
283 0x01813122, 0x01014014, 0x01441030, 0x01c41030,
284 0x40000100, 0x40000100,
287 static void stac92xx_set_config_regs(struct hda_codec *codec)
290 struct sigmatel_spec *spec = codec->spec;
291 unsigned int pin_cfg;
293 for (i=0; i < spec->num_pins; i++) {
294 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
295 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
296 spec->pin_configs[i] & 0x000000ff);
297 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
298 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
299 (spec->pin_configs[i] & 0x0000ff00) >> 8);
300 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
301 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
302 (spec->pin_configs[i] & 0x00ff0000) >> 16);
303 snd_hda_codec_write(codec, spec->pin_nids[i], 0,
304 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
305 spec->pin_configs[i] >> 24);
306 pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
307 AC_VERB_GET_CONFIG_DEFAULT,
309 printk("pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
315 * Analog playback callbacks
317 static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
318 struct hda_codec *codec,
319 snd_pcm_substream_t *substream)
321 struct sigmatel_spec *spec = codec->spec;
322 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
326 * set up the i/o for analog out
327 * when the digital out is available, copy the front out to digital out, too.
329 static int stac92xx_multi_out_analog_prepare(struct hda_codec *codec, struct hda_multi_out *mout,
330 unsigned int stream_tag,
332 snd_pcm_substream_t *substream)
334 hda_nid_t *nids = mout->dac_nids;
335 int chs = substream->runtime->channels;
338 down(&codec->spdif_mutex);
339 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
341 snd_hda_is_supported_format(codec, mout->dig_out_nid, format) &&
342 ! (codec->spdif_status & IEC958_AES0_NONAUDIO)) {
343 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
344 /* setup digital receiver */
345 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
346 stream_tag, 0, format);
348 mout->dig_out_used = 0;
349 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0);
352 up(&codec->spdif_mutex);
355 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 0, format);
357 /* headphone out will just decode front left/right (stereo) */
358 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format);
360 if (mout->max_channels > 2)
361 for (i = 1; i < mout->num_dacs; i++) {
362 if ((mout->max_channels == 6) && (i == 3))
364 if (chs >= (i + 1) * 2) /* independent out */
365 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, i * 2,
367 else /* copy front */
368 snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 0,
375 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
376 struct hda_codec *codec,
377 unsigned int stream_tag,
379 snd_pcm_substream_t *substream)
381 struct sigmatel_spec *spec = codec->spec;
382 return stac92xx_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
386 static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
387 struct hda_codec *codec,
388 snd_pcm_substream_t *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 snd_pcm_substream_t *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 snd_pcm_substream_t *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 snd_pcm_substream_t *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 snd_pcm_substream_t *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_capture = {
474 .nid = 0x06, /* NID to query formats and rates */
476 .prepare = stac92xx_capture_pcm_prepare,
477 .cleanup = stac92xx_capture_pcm_cleanup
481 static int stac92xx_build_pcms(struct hda_codec *codec)
483 struct sigmatel_spec *spec = codec->spec;
484 struct hda_pcm *info = spec->pcm_rec;
487 codec->pcm_info = info;
489 info->name = "STAC92xx Analog";
490 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
491 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
493 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
496 info->name = "STAC92xx Digital";
497 if (spec->multiout.dig_out_nid) {
498 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
499 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
501 if (spec->dig_in_nid) {
502 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
503 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
510 #define NUM_CONTROL_ALLOC 32
514 STAC_CTL_WIDGET_MUTE,
517 static snd_kcontrol_new_t stac92xx_control_templates[] = {
518 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
519 HDA_CODEC_MUTE(NULL, 0, 0, 0),
522 /* add dynamic controls */
523 static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
525 snd_kcontrol_new_t *knew;
527 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
528 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
530 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
533 if (spec->kctl_alloc) {
534 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
535 kfree(spec->kctl_alloc);
537 spec->kctl_alloc = knew;
538 spec->num_kctl_alloc = num;
541 knew = &spec->kctl_alloc[spec->num_kctl_used];
542 *knew = stac92xx_control_templates[type];
543 knew->name = snd_kmalloc_strdup(name, GFP_KERNEL);
546 knew->private_value = val;
547 spec->num_kctl_used++;
551 /* fill in the dac_nids table from the parsed pin configuration */
552 static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
554 struct sigmatel_spec *spec = codec->spec;
558 /* check the pins hardwired to audio widget */
559 for (i = 0; i < cfg->line_outs; i++) {
560 nid = cfg->line_out_pins[i];
561 spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
562 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
565 spec->multiout.num_dacs = cfg->line_outs;
570 /* add playback controls from the parsed DAC table */
571 static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
574 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
578 for (i = 0; i < cfg->line_outs; i++) {
579 if (! spec->multiout.dac_nids[i])
582 nid = spec->multiout.dac_nids[i];
586 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Center Playback Volume",
587 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
589 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "LFE Playback Volume",
590 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
592 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Center Playback Switch",
593 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
595 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "LFE Playback Switch",
596 HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
599 sprintf(name, "%s Playback Volume", chname[i]);
600 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
601 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
603 sprintf(name, "%s Playback Switch", chname[i]);
604 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
605 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
613 /* add playback controls for HP output */
614 static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin_cfg *cfg)
616 struct sigmatel_spec *spec = codec->spec;
617 hda_nid_t pin = cfg->hp_pin;
624 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
625 for (i = 0; i < cfg->line_outs; i++) {
626 if (! spec->multiout.dac_nids[i])
628 if (spec->multiout.dac_nids[i] == nid)
632 spec->multiout.hp_nid = nid;
634 /* control HP volume/switch on the output mixer amp */
635 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, "Headphone Playback Volume",
636 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
638 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
639 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
645 /* create playback/capture controls for input pins */
646 static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
648 struct sigmatel_spec *spec = codec->spec;
649 static char *labels[AUTO_PIN_LAST] = {
650 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
652 struct hda_input_mux *imux = &spec->private_imux;
653 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
656 for (i = 0; i < AUTO_PIN_LAST; i++) {
658 if (cfg->input_pins[i]) {
659 imux->items[imux->num_items].label = labels[i];
661 for (j=0; j<spec->num_muxes; j++) {
662 int num_cons = snd_hda_get_connections(codec, spec->mux_nids[j], con_lst, HDA_MAX_NUM_INPUTS);
663 for (k=0; k<num_cons; k++)
664 if (con_lst[k] == cfg->input_pins[i]) {
671 imux->items[imux->num_items].index = index;
679 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
682 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
685 static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
687 struct sigmatel_spec *spec = codec->spec;
690 for (i = 0; i < spec->autocfg.line_outs; i++) {
691 hda_nid_t nid = spec->autocfg.line_out_pins[i];
692 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
696 static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
698 struct sigmatel_spec *spec = codec->spec;
701 pin = spec->autocfg.hp_pin;
702 if (pin) /* connect to front */
703 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
706 static int stac922x_parse_auto_config(struct hda_codec *codec)
708 struct sigmatel_spec *spec = codec->spec;
711 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg)) < 0)
713 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
715 if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
716 return 0; /* can't find valid pin config */
718 if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
719 (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
720 (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
723 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
724 if (spec->multiout.max_channels > 2) {
725 spec->surr_switch = 1;
726 spec->cur_ch_mode = 1;
727 spec->num_ch_modes = 2;
728 if (spec->multiout.max_channels == 8) {
730 spec->num_ch_modes++;
734 if (spec->autocfg.dig_out_pin) {
735 spec->multiout.dig_out_nid = 0x08;
736 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
738 if (spec->autocfg.dig_in_pin) {
739 spec->dig_in_nid = 0x09;
740 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
743 if (spec->kctl_alloc)
744 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
746 spec->input_mux = &spec->private_imux;
751 static int stac9200_parse_auto_config(struct hda_codec *codec)
753 struct sigmatel_spec *spec = codec->spec;
756 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg)) < 0)
759 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
762 if (spec->autocfg.dig_out_pin) {
763 spec->multiout.dig_out_nid = 0x05;
764 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
766 if (spec->autocfg.dig_in_pin) {
767 spec->dig_in_nid = 0x04;
768 stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
771 if (spec->kctl_alloc)
772 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
774 spec->input_mux = &spec->private_imux;
779 static int stac92xx_init_pstate(struct hda_codec *codec)
781 hda_nid_t nid, nid_start;
784 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_POWER_STATE, 0x00);
786 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start);
787 for (nid = nid_start; nid < nodes + nid_start; nid++) {
788 unsigned int wid_caps = snd_hda_param_read(codec, nid,
789 AC_PAR_AUDIO_WIDGET_CAP);
790 if (wid_caps & AC_WCAP_POWER)
791 snd_hda_codec_write(codec, nid, 0,
792 AC_VERB_SET_POWER_STATE, 0x00);
800 static int stac92xx_init(struct hda_codec *codec)
802 struct sigmatel_spec *spec = codec->spec;
804 stac92xx_init_pstate(codec);
806 snd_hda_sequence_write(codec, spec->init);
808 stac92xx_auto_init_multi_out(codec);
809 stac92xx_auto_init_hp_out(codec);
814 static void stac92xx_free(struct hda_codec *codec)
816 struct sigmatel_spec *spec = codec->spec;
822 if (spec->kctl_alloc) {
823 for (i = 0; i < spec->num_kctl_used; i++)
824 kfree(spec->kctl_alloc[i].name);
825 kfree(spec->kctl_alloc);
832 static int stac92xx_resume(struct hda_codec *codec)
834 struct sigmatel_spec *spec = codec->spec;
837 stac92xx_init(codec);
838 for (i = 0; i < spec->num_mixers; i++)
839 snd_hda_resume_ctls(codec, spec->mixers[i]);
840 if (spec->multiout.dig_out_nid)
841 snd_hda_resume_spdif_out(codec);
842 if (spec->dig_in_nid)
843 snd_hda_resume_spdif_in(codec);
849 static struct hda_codec_ops stac92xx_patch_ops = {
850 .build_controls = stac92xx_build_controls,
851 .build_pcms = stac92xx_build_pcms,
852 .init = stac92xx_init,
853 .free = stac92xx_free,
855 .resume = stac92xx_resume,
859 static int patch_stac9200(struct hda_codec *codec)
861 struct sigmatel_spec *spec;
864 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
871 spec->pin_nids = stac9200_pin_nids;
873 spec->pin_configs = stac9200_pin_configs;
874 stac92xx_set_config_regs(codec);
876 spec->multiout.max_channels = 2;
877 spec->multiout.num_dacs = 1;
878 spec->multiout.dac_nids = stac9200_dac_nids;
879 spec->adc_nids = stac9200_adc_nids;
880 spec->mux_nids = stac9200_mux_nids;
883 spec->init = stac9200_core_init;
884 spec->mixer = stac9200_mixer;
886 err = stac9200_parse_auto_config(codec);
888 stac92xx_free(codec);
892 codec->patch_ops = stac92xx_patch_ops;
897 static int patch_stac922x(struct hda_codec *codec)
899 struct sigmatel_spec *spec;
902 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
910 spec->pin_nids = stac922x_pin_nids;
911 spec->pin_configs = stac922x_pin_configs;
912 stac92xx_set_config_regs(codec);
914 spec->adc_nids = stac922x_adc_nids;
915 spec->mux_nids = stac922x_mux_nids;
918 spec->init = stac922x_core_init;
919 spec->mixer = stac922x_mixer;
921 spec->multiout.dac_nids = spec->dac_nids;
923 err = stac922x_parse_auto_config(codec);
925 stac92xx_free(codec);
929 codec->patch_ops = stac92xx_patch_ops;
937 struct hda_codec_preset snd_hda_preset_sigmatel[] = {
938 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
939 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
940 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
941 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
942 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
943 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
944 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },