2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for C-Media CMI9880
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
35 /* board config type */
37 CMI_MINIMAL, /* back 3-jack */
38 CMI_MIN_FP, /* back 3-jack + front-panel 2-jack */
39 CMI_FULL, /* back 6-jack + front-panel 2-jack */
40 CMI_FULL_DIG, /* back 6-jack + front-panel 2-jack + digital I/O */
41 CMI_ALLOUT, /* back 5-jack + front-panel 2-jack + digital out */
42 CMI_AUTO, /* let driver guess it */
47 unsigned int surr_switch: 1; /* switchable line,mic */
48 unsigned int no_line_in: 1; /* no line-in (5-jack) */
49 unsigned int front_panel: 1; /* has front-panel 2-jack */
52 struct hda_multi_out multiout;
53 hda_nid_t dac_nids[4]; /* NID for each DAC */
61 const struct hda_input_mux *input_mux;
62 unsigned int cur_mux[2];
65 unsigned int num_ch_modes;
66 unsigned int cur_ch_mode;
67 const struct cmi_channel_mode *channel_modes;
69 struct hda_pcm pcm_rec[2]; /* PCM information */
71 /* pin deafault configuration */
72 hda_nid_t pin_nid[NUM_PINS];
73 unsigned int def_conf[NUM_PINS];
74 unsigned int pin_def_confs;
76 /* multichannel pins */
77 hda_nid_t multich_pin[4]; /* max 8-channel */
78 struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */
82 #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
83 #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
84 #define AMP_OUT_MUTE 0xb080
85 #define AMP_OUT_UNMUTE 0xb000
86 #define AMP_OUT_ZERO 0xb000
89 #define PIN_VREF80 0x24
90 #define PIN_VREF50 0x21
97 static int cmi_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
99 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
100 struct cmi_spec *spec = codec->spec;
101 return snd_hda_input_mux_info(spec->input_mux, uinfo);
104 static int cmi_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
106 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
107 struct cmi_spec *spec = codec->spec;
108 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
110 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
114 static int cmi_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
116 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
117 struct cmi_spec *spec = codec->spec;
118 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
120 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
121 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
125 * shared line-in, mic for surrounds
128 /* 3-stack / 2 channel */
129 static struct hda_verb cmi9880_ch2_init[] = {
130 /* set line-in PIN for input */
131 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
132 /* set mic PIN for input, also enable vref */
133 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
134 /* route front PCM (DAC1) to HP */
135 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
139 /* 3-stack / 6 channel */
140 static struct hda_verb cmi9880_ch6_init[] = {
141 /* set line-in PIN for output */
142 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
143 /* set mic PIN for output */
144 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
145 /* route front PCM (DAC1) to HP */
146 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
150 /* 3-stack+front / 8 channel */
151 static struct hda_verb cmi9880_ch8_init[] = {
152 /* set line-in PIN for output */
153 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
154 /* set mic PIN for output */
155 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
156 /* route rear-surround PCM (DAC4) to HP */
157 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x03 },
161 struct cmi_channel_mode {
162 unsigned int channels;
163 const struct hda_verb *sequence;
166 static struct cmi_channel_mode cmi9880_channel_modes[3] = {
167 { 2, cmi9880_ch2_init },
168 { 6, cmi9880_ch6_init },
169 { 8, cmi9880_ch8_init },
172 static int cmi_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
175 struct cmi_spec *spec = codec->spec;
177 snd_assert(spec->channel_modes, return -EINVAL);
178 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
180 uinfo->value.enumerated.items = spec->num_ch_modes;
181 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
182 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
183 sprintf(uinfo->value.enumerated.name, "%dch",
184 spec->channel_modes[uinfo->value.enumerated.item].channels);
188 static int cmi_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
190 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
191 struct cmi_spec *spec = codec->spec;
193 ucontrol->value.enumerated.item[0] = spec->cur_ch_mode;
197 static int cmi_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
199 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
200 struct cmi_spec *spec = codec->spec;
202 snd_assert(spec->channel_modes, return -EINVAL);
203 if (ucontrol->value.enumerated.item[0] >= spec->num_ch_modes)
204 ucontrol->value.enumerated.item[0] = spec->num_ch_modes;
205 if (ucontrol->value.enumerated.item[0] == spec->cur_ch_mode &&
209 spec->cur_ch_mode = ucontrol->value.enumerated.item[0];
210 snd_hda_sequence_write(codec, spec->channel_modes[spec->cur_ch_mode].sequence);
211 spec->multiout.max_channels = spec->channel_modes[spec->cur_ch_mode].channels;
217 static snd_kcontrol_new_t cmi9880_basic_mixer[] = {
218 /* CMI9880 has no playback volumes! */
219 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), /* front */
220 HDA_CODEC_MUTE("Surround Playback Switch", 0x04, 0x0, HDA_OUTPUT),
221 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
222 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
223 HDA_CODEC_MUTE("Side Playback Switch", 0x06, 0x0, HDA_OUTPUT),
225 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
226 /* The multiple "Capture Source" controls confuse alsamixer
227 * So call somewhat different..
228 * FIXME: the controls appear in the "playback" view!
230 /* .name = "Capture Source", */
231 .name = "Input Source",
233 .info = cmi_mux_enum_info,
234 .get = cmi_mux_enum_get,
235 .put = cmi_mux_enum_put,
237 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0, HDA_INPUT),
238 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
239 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
240 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
241 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT),
242 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT),
249 static snd_kcontrol_new_t cmi9880_ch_mode_mixer[] = {
251 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
252 .name = "Channel Mode",
253 .info = cmi_ch_mode_info,
254 .get = cmi_ch_mode_get,
255 .put = cmi_ch_mode_put,
260 /* AUD-in selections:
261 * 0x0b 0x0c 0x0d 0x0e 0x0f 0x10 0x11 0x1f 0x20
263 static struct hda_input_mux cmi9880_basic_mux = {
266 { "Front Mic", 0x5 },
273 static struct hda_input_mux cmi9880_no_line_mux = {
276 { "Front Mic", 0x5 },
282 /* front, rear, clfe, rear_surr */
283 static hda_nid_t cmi9880_dac_nids[4] = {
284 0x03, 0x04, 0x05, 0x06
287 static hda_nid_t cmi9880_adc_nids[2] = {
291 #define CMI_DIG_OUT_NID 0x07
292 #define CMI_DIG_IN_NID 0x0a
296 static struct hda_verb cmi9880_basic_init[] = {
297 /* port-D for line out (rear panel) */
298 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
299 /* port-E for HP out (front panel) */
300 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
301 /* route front PCM to HP */
302 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
303 /* port-A for surround (rear panel) */
304 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
305 /* port-G for CLFE (rear panel) */
306 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
307 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
308 /* port-H for side (rear panel) */
309 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
310 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
311 /* port-C for line-in (rear panel) */
312 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
313 /* port-B for mic-in (rear panel) with vref */
314 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
315 /* port-F for mic-in (front panel) with vref */
316 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
318 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
319 /* route front mic to ADC1/2 */
320 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
321 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
325 static struct hda_verb cmi9880_allout_init[] = {
326 /* port-D for line out (rear panel) */
327 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
328 /* port-E for HP out (front panel) */
329 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
330 /* route front PCM to HP */
331 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
332 /* port-A for side (rear panel) */
333 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
334 /* port-G for CLFE (rear panel) */
335 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
336 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x02 },
337 /* port-H for side (rear panel) */
338 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
339 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x01 },
340 /* port-C for surround (rear panel) */
341 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
342 /* port-B for mic-in (rear panel) with vref */
343 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
344 /* port-F for mic-in (front panel) with vref */
345 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
347 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
348 /* route front mic to ADC1/2 */
349 { 0x08, AC_VERB_SET_CONNECT_SEL, 0x05 },
350 { 0x09, AC_VERB_SET_CONNECT_SEL, 0x05 },
356 static int cmi9880_build_controls(struct hda_codec *codec)
358 struct cmi_spec *spec = codec->spec;
361 err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
364 if (spec->surr_switch) {
365 err = snd_hda_add_new_ctls(codec, cmi9880_ch_mode_mixer);
369 if (spec->multiout.dig_out_nid) {
370 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
374 if (spec->dig_in_nid) {
375 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
382 /* fill in the multi_dac_nids table, which will decide
383 which audio widget to use for each channel */
384 static int cmi9880_fill_multi_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
386 struct cmi_spec *spec = codec->spec;
391 /* clear the table, only one c-media dac assumed here */
392 memset(spec->dac_nids, 0, sizeof(spec->dac_nids));
393 memset(assigned, 0, sizeof(assigned));
394 /* check the pins we found */
395 for (i = 0; i < cfg->line_outs; i++) {
396 nid = cfg->line_out_pins[i];
397 /* nid 0x0b~0x0e is hardwired to audio widget 0x3~0x6 */
398 if (nid >= 0x0b && nid <= 0x0e) {
399 spec->dac_nids[i] = (nid - 0x0b) + 0x03;
400 assigned[nid - 0x0b] = 1;
403 /* left pin can be connect to any audio widget */
404 for (i = 0; i < cfg->line_outs; i++) {
405 nid = cfg->line_out_pins[i];
408 /* search for an empty channel */
409 for (j = 0; j < cfg->line_outs; j++) {
411 spec->dac_nids[i] = j + 0x03;
417 spec->num_dacs = cfg->line_outs;
421 /* create multi_init table, which is used for multichannel initialization */
422 static int cmi9880_fill_multi_init(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
424 struct cmi_spec *spec = codec->spec;
428 /* clear the table, only one c-media dac assumed here */
429 memset(spec->multi_init, 0, sizeof(spec->multi_init));
430 for (j = 0, i = 0; i < cfg->line_outs; i++) {
432 nid = cfg->line_out_pins[i];
434 spec->multi_init[j].nid = nid;
435 spec->multi_init[j].verb = AC_VERB_SET_PIN_WIDGET_CONTROL;
436 spec->multi_init[j].param = PIN_OUT;
440 spec->multi_init[j].nid = nid;
441 spec->multi_init[j].verb = AC_VERB_SET_CONNECT_SEL;
442 spec->multi_init[j].param = 0;
443 /* find the index in connect list */
444 len = snd_hda_get_connections(codec, nid, conn, 4);
445 for (k = 0; k < len; k++)
446 if (conn[k] == spec->dac_nids[i]) {
447 spec->multi_init[j].param = k;
456 static int cmi9880_init(struct hda_codec *codec)
458 struct cmi_spec *spec = codec->spec;
459 if (spec->board_config == CMI_ALLOUT)
460 snd_hda_sequence_write(codec, cmi9880_allout_init);
462 snd_hda_sequence_write(codec, cmi9880_basic_init);
463 if (spec->board_config == CMI_AUTO)
464 snd_hda_sequence_write(codec, spec->multi_init);
472 static int cmi9880_resume(struct hda_codec *codec)
474 struct cmi_spec *spec = codec->spec;
477 snd_hda_resume_ctls(codec, cmi9880_basic_mixer);
478 if (spec->surr_switch)
479 snd_hda_resume_ctls(codec, cmi9880_ch_mode_mixer);
480 if (spec->multiout.dig_out_nid)
481 snd_hda_resume_spdif_out(codec);
482 if (spec->dig_in_nid)
483 snd_hda_resume_spdif_in(codec);
490 * Analog playback callbacks
492 static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
493 struct hda_codec *codec,
494 snd_pcm_substream_t *substream)
496 struct cmi_spec *spec = codec->spec;
497 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
500 static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
501 struct hda_codec *codec,
502 unsigned int stream_tag,
504 snd_pcm_substream_t *substream)
506 struct cmi_spec *spec = codec->spec;
507 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
511 static int cmi9880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
512 struct hda_codec *codec,
513 snd_pcm_substream_t *substream)
515 struct cmi_spec *spec = codec->spec;
516 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
522 static int cmi9880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
523 struct hda_codec *codec,
524 snd_pcm_substream_t *substream)
526 struct cmi_spec *spec = codec->spec;
527 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
530 static int cmi9880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
531 struct hda_codec *codec,
532 snd_pcm_substream_t *substream)
534 struct cmi_spec *spec = codec->spec;
535 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
541 static int cmi9880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
542 struct hda_codec *codec,
543 unsigned int stream_tag,
545 snd_pcm_substream_t *substream)
547 struct cmi_spec *spec = codec->spec;
549 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
550 stream_tag, 0, format);
554 static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
555 struct hda_codec *codec,
556 snd_pcm_substream_t *substream)
558 struct cmi_spec *spec = codec->spec;
560 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
567 static struct hda_pcm_stream cmi9880_pcm_analog_playback = {
571 .nid = 0x03, /* NID to query formats and rates */
573 .open = cmi9880_playback_pcm_open,
574 .prepare = cmi9880_playback_pcm_prepare,
575 .cleanup = cmi9880_playback_pcm_cleanup
579 static struct hda_pcm_stream cmi9880_pcm_analog_capture = {
583 .nid = 0x08, /* NID to query formats and rates */
585 .prepare = cmi9880_capture_pcm_prepare,
586 .cleanup = cmi9880_capture_pcm_cleanup
590 static struct hda_pcm_stream cmi9880_pcm_digital_playback = {
594 /* NID is set in cmi9880_build_pcms */
596 .open = cmi9880_dig_playback_pcm_open,
597 .close = cmi9880_dig_playback_pcm_close
601 static struct hda_pcm_stream cmi9880_pcm_digital_capture = {
605 /* NID is set in cmi9880_build_pcms */
608 static int cmi9880_build_pcms(struct hda_codec *codec)
610 struct cmi_spec *spec = codec->spec;
611 struct hda_pcm *info = spec->pcm_rec;
614 codec->pcm_info = info;
616 info->name = "CMI9880";
617 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_analog_playback;
618 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_analog_capture;
620 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
623 info->name = "CMI9880 Digital";
624 if (spec->multiout.dig_out_nid) {
625 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
626 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
628 if (spec->dig_in_nid) {
629 info->stream[SNDRV_PCM_STREAM_CAPTURE] = cmi9880_pcm_digital_capture;
630 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
637 static void cmi9880_free(struct hda_codec *codec)
645 static struct hda_board_config cmi9880_cfg_tbl[] = {
646 { .modelname = "minimal", .config = CMI_MINIMAL },
647 { .modelname = "min_fp", .config = CMI_MIN_FP },
648 { .modelname = "full", .config = CMI_FULL },
649 { .modelname = "full_dig", .config = CMI_FULL_DIG },
650 { .modelname = "allout", .config = CMI_ALLOUT },
651 { .modelname = "auto", .config = CMI_AUTO },
655 static struct hda_codec_ops cmi9880_patch_ops = {
656 .build_controls = cmi9880_build_controls,
657 .build_pcms = cmi9880_build_pcms,
658 .init = cmi9880_init,
659 .free = cmi9880_free,
661 .resume = cmi9880_resume,
665 static int patch_cmi9880(struct hda_codec *codec)
667 struct cmi_spec *spec;
669 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
674 spec->board_config = snd_hda_check_board_config(codec, cmi9880_cfg_tbl);
675 if (spec->board_config < 0) {
676 snd_printdd(KERN_INFO "hda_codec: Unknown model for CMI9880\n");
677 spec->board_config = CMI_AUTO; /* try everything */
680 /* copy default DAC NIDs */
681 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
684 switch (spec->board_config) {
687 spec->surr_switch = 1;
688 if (spec->board_config == CMI_MINIMAL)
689 spec->num_ch_modes = 2;
691 spec->front_panel = 1;
692 spec->num_ch_modes = 3;
694 spec->channel_modes = cmi9880_channel_modes;
695 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
696 spec->input_mux = &cmi9880_basic_mux;
700 spec->front_panel = 1;
701 spec->multiout.max_channels = 8;
702 spec->input_mux = &cmi9880_basic_mux;
703 if (spec->board_config == CMI_FULL_DIG) {
704 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
705 spec->dig_in_nid = CMI_DIG_IN_NID;
709 spec->front_panel = 1;
710 spec->multiout.max_channels = 8;
711 spec->no_line_in = 1;
712 spec->input_mux = &cmi9880_no_line_mux;
713 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
717 unsigned int port_e, port_f, port_g, port_h;
718 unsigned int port_spdifi, port_spdifo;
719 struct auto_pin_cfg cfg;
721 /* collect pin default configuration */
722 port_e = snd_hda_codec_read(codec, 0x0f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
723 port_f = snd_hda_codec_read(codec, 0x10, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
724 spec->front_panel = 1;
725 if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE ||
726 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
727 port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
728 port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
729 spec->surr_switch = 1;
731 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
732 get_defcfg_connect(port_h) == AC_JACK_PORT_NONE) {
733 /* no optional rear panel */
734 spec->board_config = CMI_MINIMAL;
735 spec->front_panel = 0;
736 spec->num_ch_modes = 2;
738 spec->board_config = CMI_MIN_FP;
739 spec->num_ch_modes = 3;
741 spec->channel_modes = cmi9880_channel_modes;
742 spec->input_mux = &cmi9880_basic_mux;
743 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
745 spec->input_mux = &cmi9880_basic_mux;
746 port_spdifi = snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
747 port_spdifo = snd_hda_codec_read(codec, 0x12, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
748 if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE)
749 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
750 if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE)
751 spec->dig_in_nid = CMI_DIG_IN_NID;
752 spec->multiout.max_channels = 8;
754 snd_hda_parse_pin_def_config(codec, &cfg);
756 spec->multiout.max_channels = cfg.line_outs * 2;
757 cmi9880_fill_multi_dac_nids(codec, &cfg);
758 cmi9880_fill_multi_init(codec, &cfg);
760 snd_printd("patch_cmedia: cannot detect association in defcfg\n");
765 spec->multiout.num_dacs = spec->num_dacs;
766 spec->multiout.dac_nids = spec->dac_nids;
768 spec->adc_nids = cmi9880_adc_nids;
770 codec->patch_ops = cmi9880_patch_ops;
778 struct hda_codec_preset snd_hda_preset_cmedia[] = {
779 { .id = 0x13f69880, .name = "CMI9880", .patch = patch_cmi9880 },
780 { .id = 0x434d4980, .name = "CMI9880", .patch = patch_cmi9880 },